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