Skip to content

Instantly share code, notes, and snippets.

@starbuck93
Last active March 22, 2016 07:02
Show Gist options
  • Save starbuck93/f6c8d3deae5e84373f24 to your computer and use it in GitHub Desktop.
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
<?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