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

Initial commit.

parent f5103e00
No related branches found
No related tags found
No related merge requests found
<?php
$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) {
while (($sensors = fgets($handle)) !== false) {
$sensor = "/sys/bus/w1/devices/".trim($sensors)."/w1_slave";
$sensorhandle = fopen($sensor, "r");
if ($sensorhandle) {
$thermometerReading = fread($sensorhandle, filesize($sensor));
fclose($sensorhandle);
// We want the value after the t= on the 2nd line
preg_match("/t=(.+)/", preg_split("/\n/", $thermometerReading)[1], $matches);
$celsius = round($matches[1] / 1000);
fclose($handle);
return $celsius;
} else {
return null;
}
}
fclose($handle);
} else {
return null;
}
return null;
}
while(true) {
$temperature = getTemperature();
}
\ No newline at end of file
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