From f7b36659415d3d7952135f4c7eed74775c05c283 Mon Sep 17 00:00:00 2001 From: Zandor Smith <info@zsinfo.nl> Date: Tue, 2 Jan 2018 23:26:38 +0100 Subject: [PATCH] Main script finished. --- updateSensor.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/updateSensor.php b/updateSensor.php index f32d6bb..51bd5b7 100644 --- a/updateSensor.php +++ b/updateSensor.php @@ -3,6 +3,8 @@ $sensorId = 0; // Fill in your sensor id. $apiKey = ""; // Fill in the installation API key. +// ================= + function getTemperature() { $handle = fopen("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves", "r"); if ($handle) { @@ -18,20 +20,31 @@ function getTemperature() { fclose($handle); return $celsius; } else { + echo "Unable to read temperature!\n"; + fclose($handle); return null; } } fclose($handle); - } else { - return null; } + echo "No temperature sensor found!\n"; return null; } -while(true) { +// ================= +while(true) { $temperature = getTemperature(); + if($temperature !== null) { + $ch = curl_init('https://api.chmonitor.com/v2/updateSensorTemperature.php'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, ["apiKey" => $apiKey, "sensor" => $sensorId, "temperature" => $temperature]); + $response = curl_exec($ch); -} \ No newline at end of file + curl_close($ch); + } + + sleep(10); +} -- GitLab