Last active
March 22, 2016 07:02
-
-
Save starbuck93/f6c8d3deae5e84373f24 to your computer and use it in GitHub Desktop.
echos the single DS18B20 on your linux system as a REST string. if you have two, see my other gists
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
<?php | |
$command = "find /sys/bus/w1/devices -name '28-*'"; | |
$path = exec($command); | |
$fullpath = $path . "/w1_slave"; | |
$filename1 = $fullpath; | |
$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; | |
$str = '{"temperature":'.number_format($tempF1,2).'}'; | |
echo $str; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment