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 @@ ...@@ -3,6 +3,8 @@
$sensorId = 0; // Fill in your sensor id. $sensorId = 0; // Fill in your sensor id.
$apiKey = ""; // Fill in the installation API key. $apiKey = ""; // Fill in the installation API key.
// =================
function getTemperature() { function getTemperature() {
$handle = fopen("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves", "r"); $handle = fopen("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves", "r");
if ($handle) { if ($handle) {
...@@ -18,20 +20,31 @@ function getTemperature() { ...@@ -18,20 +20,31 @@ function getTemperature() {
fclose($handle); fclose($handle);
return $celsius; return $celsius;
} else { } else {
echo "Unable to read temperature!\n";
fclose($handle);
return null; return null;
} }
} }
fclose($handle); fclose($handle);
} else {
return null;
} }
echo "No temperature sensor found!\n";
return null; return null;
} }
while(true) { // =================
while(true) {
$temperature = getTemperature(); $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);
} curl_close($ch);
\ No newline at end of file }
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