diff --git a/updateSensor.php b/updateSensor.php index f32d6bb308c9f9b7f14076cd47b6bad02dcecd51..51bd5b718b4a329b74c413284a49afe690c4886b 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); +}