From c4a121cbd2793cc2637a38bac002732c9cb7c13c Mon Sep 17 00:00:00 2001 From: dLedda Date: Sat, 14 Nov 2020 12:08:27 +0000 Subject: [PATCH] Almost there --- climate-pinger.py | 13 +++++++------ server.go | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/climate-pinger.py b/climate-pinger.py index d1e611f..c6e61a7 100755 --- a/climate-pinger.py +++ b/climate-pinger.py @@ -2,7 +2,7 @@ import adafruit_dht import mh_z19 -from sys import stderr +import sys from board import D4 from datetime import datetime @@ -17,12 +17,13 @@ try: raise RuntimeError() print( 'Time:', str(datetime.now()), - 'Temp:', temp, - 'Humidity:', humidity, - 'CO2:', co2, - sep='\n', + '\nTemp:', temp, + '\nHumidity:', humidity, + '\nCO2:', co2, + sep='\t', ) except Exception as error: print('err:', error, file=sys.stderr) -dhtDevice.exit() \ No newline at end of file +sys.stdout = None +dhtDevice.exit() diff --git a/server.go b/server.go index 9c7c8b2..dbe59ba 100644 --- a/server.go +++ b/server.go @@ -111,14 +111,14 @@ func getSnapshotFromPythonScript() (*SnapshotSubmission, error) { ) } tokens := strings.Split(string(output), "\n") - if len(tokens) != 4 { + if len(tokens) != 5 { return nil, errors.New(fmt.Sprintf("Strange python output: %s", output)) } snapshot := SnapshotSubmission{ - Timestamp: tokens[0], - Temp: tokens[1], - Humidity: tokens[2], - Co2: tokens[3], + Timestamp: strings.Split(tokens[0], "\t")[1], + Temp: strings.Split(tokens[1], "\t")[1], + Humidity: strings.Split(tokens[2], "\t")[1], + Co2: strings.Split(tokens[3], "\t")[1], } return &snapshot, nil } @@ -142,4 +142,4 @@ func internalErrorOnErr(err error, w http.ResponseWriter, r *http.Request) bool func logError(errorMessage string) { fmt.Println(errorMessage) mainLogger.Println(errorMessage) -} \ No newline at end of file +}