Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 °C / $fahrenheit °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 °C / $fahrenheit °F"; | ||
fclose($handle); | ||
} else { | ||
print "No motherfucking sensors found!"; | ||
} | ||
?> |