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