Skip to content
Snippets Groups Projects
Commit f7b36659 authored by Zandor Smith's avatar Zandor Smith :computer:
Browse files

Main script finished.

parent 75497fad
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment