From d6c0cec4637d83b9df27b7a1229066e4baf980ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Tue, 12 Jul 2022 11:54:25 +0200 Subject: [PATCH] added rounded distance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index e5ba5c0..b845500 100644 --- a/main.py +++ b/main.py @@ -58,8 +58,8 @@ def get_water_level(): TimeElapsed = StopTime - startTime distance = (TimeElapsed * 34300) / 2 - - return int(distance) + rounded_distance = int(distance) + return str(rounded_distance) #temperature def get_temperature(): @@ -71,13 +71,13 @@ def get_temperature(): print(get_water_level()) print(get_temperature()) -def mqtt_on_connect(client): +def mqtt_on_connect(client, userdata, flags, rc): client.subscribe("strawberry-pi-greenhouse/relay/channel/1") client.subscribe("strawberry-pi-greenhouse/relay/channel/2") client.subscribe("strawberry-pi-greenhouse/relay/channel/3") client.subscribe("strawberry-pi-greenhouse/relay/channel/4") -def mqtt_on_message(msg): +def mqtt_on_message(client, userdata, msg): print("topic: " ,str(msg.topic)) print("payload: " ,str(msg.payload.decode("utf-8"))) topic = str(msg.topic)