Skip to content
Snippets Groups Projects
Commit e60f0978 authored by Zandor Smith's avatar Zandor Smith :computer:
Browse files

Report errors and the recorded temperature.

parent 5f40f38a
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ function getTemperature() {
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);
$celsius = $matches[1] / 1000;
fclose($handle);
return $celsius;
} else {
......@@ -36,6 +36,8 @@ function getTemperature() {
while(true) {
$temperature = getTemperature();
echo "Recorded temperature: " . $temperature . PHP_EOL;
if($temperature !== null) {
$ch = curl_init('https://api.chmonitor.com/v2/updateSensorTemperature.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
......@@ -43,6 +45,11 @@ while(true) {
$response = curl_exec($ch);
$json = json_decode($response, true);
if(isset($json['error'])) {
echo $json['error'] . PHP_EOL;
}
curl_close($ch);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment