diff --git a/main.py b/main.py index 1141a06..a87a88f 100644 --- a/main.py +++ b/main.py @@ -66,29 +66,6 @@ def mqtt_on_connect(client, userdata, flags, rc): client.subscribe("server-rack-led-1/r") client.subscribe("server-rack-led-1/g") client.subscribe("server-rack-led-1/b") - -def mqtt_on_message(client, userdata, msg): - print("topic: " ,str(msg.topic)) - print("payload: " ,str(msg.payload.decode("utf-8"))) - topic = str(msg.topic) - payload = str(msg.payload.decode("utf-8")) - if topic == "server-rack-led-1/power": - power = payload - - elif topic == "server-rack-led-1/r": - r = payload - - elif topic == "server-rack-led-1/g": - g = payload - - elif topic == "server-rack-led-1/b": - b = payload - - elif topic == "server-rack-led-1/mode": - if payload == "0": - mode = 0 - elif payload == "1": - mode = 1 if __name__ == '__main__': @@ -185,13 +162,35 @@ if __name__ == '__main__': power = "False" return 'Power: OFF' + def mqtt_on_message(client, userdata, msg): + print("topic: " ,str(msg.topic)) + print("payload: " ,str(msg.payload.decode("utf-8"))) + topic = str(msg.topic) + payload = str(msg.payload.decode("utf-8")) + if topic == "server-rack-led-1/power": + power = payload + + elif topic == "server-rack-led-1/r": + r = payload + + elif topic == "server-rack-led-1/g": + g = payload + + elif topic == "server-rack-led-1/b": + b = payload + + elif topic == "server-rack-led-1/mode": + if payload == "0": + mode = 0 + elif payload == "1": + mode = 1 + strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) strip.begin() mode = 0 power = "True" - threading.Thread(target=lambda: app.run(host='0.0.0.0', port=80)).start() mqttBroker ="homeassistant.ping-mee.local" @@ -205,8 +204,6 @@ if __name__ == '__main__': client.publish("server-rack-led-1/power","True") client.publish("server-rack-led-1/mode","0") - # threading.Thread(target=lambda: client.loop_start()) - try: client.loop_start() while True: