parent
71e5662e4f
commit
a43c5a36fc
29
main.py
29
main.py
|
@ -60,12 +60,9 @@ def setColor(strip, color, wait_ms=10):
|
|||
time.sleep(wait_ms/1000.0)
|
||||
|
||||
def mqtt_on_connect(client, userdata, flags, rc):
|
||||
#sub to status
|
||||
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")
|
||||
client.subscribe("server-rack-led/power")
|
||||
client.subscribe("server-rack-led/mode")
|
||||
client.subscribe("server-rack-led/rgb")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -167,23 +164,15 @@ if __name__ == '__main__':
|
|||
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":
|
||||
if topic == "server-rack-led/power":
|
||||
global power
|
||||
power = payload
|
||||
|
||||
elif topic == "server-rack-led-1/r":
|
||||
elif topic == "server-rack-led/rgb":
|
||||
global r
|
||||
r = payload
|
||||
|
||||
elif topic == "server-rack-led-1/g":
|
||||
global g
|
||||
g = payload
|
||||
|
||||
elif topic == "server-rack-led-1/b":
|
||||
global b
|
||||
b = payload
|
||||
|
||||
elif topic == "server-rack-led-1/mode":
|
||||
elif topic == "server-rack-led/mode":
|
||||
if payload == "0":
|
||||
global mode
|
||||
mode = 0
|
||||
|
@ -199,15 +188,15 @@ if __name__ == '__main__':
|
|||
threading.Thread(target=lambda: app.run(host='0.0.0.0', port=80)).start()
|
||||
|
||||
mqttBroker ="homeassistant.ping-mee.local"
|
||||
client = mqtt.Client("server_rack_led_1")
|
||||
client = mqtt.Client("server_rack_led")
|
||||
client.username_pw_set("mqtt", "pmMQTT_11!")
|
||||
debug_print("Connecting to MQTT Broker "+str(mqttBroker))
|
||||
client.connect(mqttBroker)
|
||||
client.on_connect = mqtt_on_connect
|
||||
client.on_message = mqtt_on_message
|
||||
|
||||
client.publish("server-rack-led-1/power","True")
|
||||
client.publish("server-rack-led-1/mode","0")
|
||||
client.publish("server-rack-led/power","True")
|
||||
client.publish("server-rack-led/mode","0")
|
||||
|
||||
try:
|
||||
client.loop_start()
|
||||
|
|
Loading…
Reference in New Issue