diff --git a/main.py b/main.py index 8b91925..5b93909 100644 --- a/main.py +++ b/main.py @@ -168,6 +168,7 @@ if __name__ == '__main__': mode = 0 power = "True" + threading.Thread(target=lambda: app.run(host='0.0.0.0', port=80)).start() mqttBroker ="homeassistant.ping-mee.local" @@ -177,6 +178,9 @@ if __name__ == '__main__': client.connect(mqttBroker) client.on_connect = mqtt_on_connect + client.publish("server-rack-led-1/power","True") + client.publish("server-rack-led-1/mode","0") + def mqtt_on_message(client, userdata, msg): print(f"Message received [{msg.topic}]: {msg.payload}") if str(msg.topic) == "server-rack-led-1/power": @@ -203,22 +207,17 @@ if __name__ == '__main__': try: while True: if power == "True": - client.publish("server-rack-led-1/power","True") - if mode == 0: - client.publish("server-rack-led-1/mode","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)) setColor(strip, Color(int(r), int(g), int(b))) time.sleep(1) else: client.publish("server-rack-led-1/power","False") setColor(strip, Color(0,0,0)) time.sleep(1) + except KeyboardInterrupt: client.disconnect() setColor(strip, Color(0,0,0))