diff --git a/radar/update.php b/radar/update.php index 3fba5c0..c86cc3b 100644 --- a/radar/update.php +++ b/radar/update.php @@ -1,12 +1,43 @@ + +// 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";