Update radar/update.php
This commit is contained in:
@@ -1,12 +1,43 @@
|
|||||||
<?php
|
<?php
|
||||||
// Log alles wat binnenkomt
|
// Alleen POST toestaan
|
||||||
file_put_contents('log.txt', print_r($_POST, true), FILE_APPEND);
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
http_response_code(405);
|
||||||
if(isset($_POST['afstand'])) {
|
exit("Only POST allowed");
|
||||||
$afstand = intval($_POST['afstand']);
|
|
||||||
file_put_contents('afstand.txt', $afstand);
|
|
||||||
echo "OK";
|
|
||||||
} else {
|
|
||||||
echo "No data";
|
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
// 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";
|
||||||
|
|||||||
Reference in New Issue
Block a user