moved mqtt_on_message

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-07-01 22:49:15 +02:00
parent 33b9d87bc6
commit cf5224c8a3
1 changed files with 23 additions and 26 deletions

49
main.py
View File

@ -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: