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: