From e60f097884fdc215ed426092e5ecb12efa3ab110 Mon Sep 17 00:00:00 2001
From: Zandor Smith <info@zsinfo.nl>
Date: Sat, 6 Jan 2018 14:19:57 +0100
Subject: [PATCH] Report errors and the recorded temperature.

---
 updateSensor.php | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/updateSensor.php b/updateSensor.php
index 814337e..8ee03b5 100644
--- a/updateSensor.php
+++ b/updateSensor.php
@@ -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);
 	}
 
-- 
GitLab