Update radar/update.php

This commit is contained in:
2026-01-03 17:03:28 +01:00
parent 8bb849c370
commit 47e991f017

View File

@@ -1,12 +1,43 @@
<?php
// Log alles wat binnenkomt
file_put_contents('log.txt', print_r($_POST, true), FILE_APPEND);
if(isset($_POST['afstand'])) {
$afstand = intval($_POST['afstand']);
file_put_contents('afstand.txt', $afstand);
echo "OK";
} else {
echo "No data";
// Alleen POST toestaan
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
exit("Only POST allowed");
}
?>
// Check of data bestaat
if (!isset($_POST['hoek']) || !isset($_POST['afstand'])) {
http_response_code(400);
exit("Missing data");
}
$hoek = intval($_POST['hoek']);
$afstand = intval($_POST['afstand']);
// Basis validatie
if ($hoek < 0 || $hoek > 180) {
http_response_code(400);
exit("Invalid angle");
}
// Bestand met radar data
$file = __DIR__ . "/radar.json";
// Bestaande data laden
$data = [];
if (file_exists($file)) {
$json = file_get_contents($file);
$data = json_decode($json, true);
if (!is_array($data)) $data = [];
}
// Opslaan per hoek
$data[$hoek] = [
"afstand" => $afstand,
"tijd" => time()
];
// Terugschrijven
file_put_contents($file, json_encode($data));
echo "OK";