parent
33b9d87bc6
commit
cf5224c8a3
49
main.py
49
main.py
|
@ -67,29 +67,6 @@ def mqtt_on_connect(client, userdata, flags, rc):
|
||||||
client.subscribe("server-rack-led-1/g")
|
client.subscribe("server-rack-led-1/g")
|
||||||
client.subscribe("server-rack-led-1/b")
|
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__':
|
if __name__ == '__main__':
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -185,13 +162,35 @@ if __name__ == '__main__':
|
||||||
power = "False"
|
power = "False"
|
||||||
return 'Power: OFF'
|
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 = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
|
||||||
strip.begin()
|
strip.begin()
|
||||||
|
|
||||||
mode = 0
|
mode = 0
|
||||||
power = "True"
|
power = "True"
|
||||||
|
|
||||||
|
|
||||||
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"
|
||||||
|
@ -205,8 +204,6 @@ if __name__ == '__main__':
|
||||||
client.publish("server-rack-led-1/power","True")
|
client.publish("server-rack-led-1/power","True")
|
||||||
client.publish("server-rack-led-1/mode","0")
|
client.publish("server-rack-led-1/mode","0")
|
||||||
|
|
||||||
# threading.Thread(target=lambda: client.loop_start())
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Reference in New Issue