From 225f80587bac8505ccd0fba11512457a93170887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Fri, 1 Jul 2022 22:39:56 +0200 Subject: [PATCH] changed msg.topic/msg.payload into var's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 25b4b1c..f9add58 100644 --- a/main.py +++ b/main.py @@ -68,23 +68,26 @@ def mqtt_on_connect(client, userdata, flags, rc): client.subscribe("server-rack-led-1/b") def mqtt_on_message(client, userdata, msg): - print(f"Message received [{msg.topic}]: {msg.payload}") - if str(msg.topic) == "server-rack-led-1/power": - power = str(msg.payload) + print("topic: " ,str(msg.topic.decode("utf-8"))) + print("payload: " ,str(msg.payload.decode("utf-8"))) + topic = str(msg.topic.decode("utf-8")) + payload = str(msg.payload.decode("utf-8")) + if topic == "server-rack-led-1/power": + power = payload - elif str(msg.topic) == "server-rack-led-1/r": - r = str(msg.payload) + elif topic == "server-rack-led-1/r": + r = payload - elif str(msg.topic) == "server-rack-led-1/g": - g = str(msg.payload) + elif topic == "server-rack-led-1/g": + g = payload - elif str(msg.topic) == "server-rack-led-1/b": - b = str(msg.payload) + elif topic == "server-rack-led-1/b": + b = payload - elif str(msg.topic) == "server-rack-led-1/mode": - if str(msg.payload) == "0": + elif topic == "server-rack-led-1/mode": + if payload == "0": mode = 0 - elif str(msg.payload) == "1": + elif payload == "1": mode = 1