Skip to content

Commit

Permalink
Update temp.php
Browse files Browse the repository at this point in the history
  • Loading branch information
xillwillx committed May 17, 2015
1 parent 131a9a8 commit 54ed95c
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions temp.php
@@ -1,25 +1,25 @@
<?php
$THERMOMETER_COUNT = "/sys/bus/w1/devices/w1_bus_master1/w1_master_slave_count";
$thermo = fopen($THERMOMETER_COUNT, "r");
$thermometer_cnt = fread($thermo, filesize($THERMOMETER_COUNT));
fclose($thermo);
print "Found: $thermometer_cnt thermometer<P>";
$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); //round the results
$fahrenheit = round($celsius*9/5+32);
print "Sensor ID#: $sensors = $celsius &deg;C / $fahrenheit &deg;F<br>";
$sensors++;
} else {
print "No motherfucking temperature read!";
}
}

$THERMOMETERS = "/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves";
$thermo = fopen($THERMOMETERS, "r");
$thermometername = fread($thermo, filesize($THERMOMETERS));
$thermometername = trim($thermometername); ///trim the white space after the name
fclose($thermo);
print "Name: $thermometername<P>";

$THERMOMETER_SENSOR_PATH = "/sys/bus/w1/devices/".$thermometername."/w1_slave";
$thermometer = fopen($THERMOMETER_SENSOR_PATH, "r");
$thermometerReadings = fread($thermometer, filesize($THERMOMETER_SENSOR_PATH));
fclose($thermometer);
// We're only interested in the 2nd line, and the value after the t= on the 2nd line
preg_match("/t=(.+)/", preg_split("/\n/", $thermometerReadings)[1], $matches);
$celsius = round($matches[1] / 1000);
$fahrenheit = round($celsius*9/5+32);
// Output the temperature
print "The current temp is: $celsius &deg;C / $fahrenheit &deg;F";
fclose($handle);
} else {
print "No motherfucking sensors found!";
}
?>

0 comments on commit 54ed95c

Please sign in to comment.