Created
March 22, 2016 07:03
-
-
Save starbuck93/371c43454639c57aaab5 to your computer and use it in GitHub Desktop.
raspberry pi two ds18b20 temperature sensors
This file contains hidden or 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
<?php | |
$paths = array(); | |
$command = "find /sys/bus/w1/devices -name '28-*'"; | |
exec($command,$paths); | |
$fullpath1 = $paths[0] . "/w1_slave"; | |
$fullpath2 = $paths[1] . "/w1_slave"; | |
$filename1 = $fullpath1; | |
$filename2 = $fullpath2; | |
//----- get first one -----// | |
$handle1 = fopen($filename1, "r") or die("Unable to open file!"); | |
$myString1 = fread($handle1,filesize($filename1)); | |
fclose($handle1); | |
$tempC1 = ((float) substr($myString1, strpos($myString1,"t=")+2))/1000; | |
$tempF1 = ($tempC1*(9.0 / 5.0)) + 32.0; | |
//----- get second one ----// | |
$handle2 = fopen($filename2, "r") or die("Unable to open file!"); | |
$myString2 = fread($handle2,filesize($filename2)); | |
fclose($handle2); | |
$tempC2 = ((float) substr($myString2, strpos($myString2,"t=")+2))/1000; | |
$tempF2 = ($tempC2*(9.0 / 5.0)) + 32.0; | |
//----- echo the whole string -----// | |
$str = '{"temperature":'.number_format($tempF1,2).',"temperature2":'.number_format($tempF2,2).'}'; | |
echo $str; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment