From c66498d48fc6bb40c2683ef37c93fa7a22988157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Fri, 1 Jul 2022 21:52:00 +0200 Subject: [PATCH] added status and set option for mqtt topics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 925e4cc..f6b6bd0 100644 --- a/main.py +++ b/main.py @@ -60,11 +60,12 @@ def setColor(strip, color, wait_ms=10): time.sleep(wait_ms/1000.0) def mqtt_on_connect(client, userdata, flags, rc): - client.subscribe("server-rack-led-1/power") - client.subscribe("server-rack-led-1/mode") - client.subscribe("server-rack-led-1/r") - client.subscribe("server-rack-led-1/g") - client.subscribe("server-rack-led-1/b") + #sub to status + client.subscribe("server-rack-led-1/power/status") + client.subscribe("server-rack-led-1/mode/status") + client.subscribe("server-rack-led-1/r/status") + client.subscribe("server-rack-led-1/g/status") + client.subscribe("server-rack-led-1/b/status") def mqtt_on_message(client, userdata, msg): print(f"Message received [{msg.topic}]: {msg.payload}") @@ -184,19 +185,20 @@ if __name__ == '__main__': try: while True: if power == "True": - client.publish("server-rack-led-1/power","True") + client.publish("server-rack-led-1/power/status","True") + if mode == 0: - client.publish("server-rack-led-1/mode","0") + client.publish("server-rack-led-1/mode/status","0") rainbowCycle(strip) elif mode == 1: - client.publish("server-rack-led-1/mode","1") - client.publish("server-rack-led-1/r",str(r)) - client.publish("server-rack-led-1/g",str(g)) - client.publish("server-rack-led-1/b",str(b)) + client.publish("server-rack-led-1/mode/status","1") + client.publish("server-rack-led-1/r/status",str(r)) + client.publish("server-rack-led-1/g/status",str(g)) + client.publish("server-rack-led-1/b/status",str(b)) setColor(strip, Color(int(r), int(g), int(b))) time.sleep(1) else: - client.publish("server-rack-led-1/power","False") + client.publish("server-rack-led-1/power/status","False") setColor(strip, Color(0,0,0)) time.sleep(1) except KeyboardInterrupt: