added status and set option for mqtt topics
Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>master
parent
bc1c162ae9
commit
c66498d48f
26
main.py
26
main.py
|
@ -60,11 +60,12 @@ 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):
|
||||||
client.subscribe("server-rack-led-1/power")
|
#sub to status
|
||||||
client.subscribe("server-rack-led-1/mode")
|
client.subscribe("server-rack-led-1/power/status")
|
||||||
client.subscribe("server-rack-led-1/r")
|
client.subscribe("server-rack-led-1/mode/status")
|
||||||
client.subscribe("server-rack-led-1/g")
|
client.subscribe("server-rack-led-1/r/status")
|
||||||
client.subscribe("server-rack-led-1/b")
|
client.subscribe("server-rack-led-1/g/status")
|
||||||
|
client.subscribe("server-rack-led-1/b/status")
|
||||||
|
|
||||||
def mqtt_on_message(client, userdata, msg):
|
def mqtt_on_message(client, userdata, msg):
|
||||||
print(f"Message received [{msg.topic}]: {msg.payload}")
|
print(f"Message received [{msg.topic}]: {msg.payload}")
|
||||||
|
@ -184,19 +185,20 @@ if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
if power == "True":
|
if power == "True":
|
||||||
client.publish("server-rack-led-1/power","True")
|
client.publish("server-rack-led-1/power/status","True")
|
||||||
|
|
||||||
if mode == 0:
|
if mode == 0:
|
||||||
client.publish("server-rack-led-1/mode","0")
|
client.publish("server-rack-led-1/mode/status","0")
|
||||||
rainbowCycle(strip)
|
rainbowCycle(strip)
|
||||||
elif mode == 1:
|
elif mode == 1:
|
||||||
client.publish("server-rack-led-1/mode","1")
|
client.publish("server-rack-led-1/mode/status","1")
|
||||||
client.publish("server-rack-led-1/r",str(r))
|
client.publish("server-rack-led-1/r/status",str(r))
|
||||||
client.publish("server-rack-led-1/g",str(g))
|
client.publish("server-rack-led-1/g/status",str(g))
|
||||||
client.publish("server-rack-led-1/b",str(b))
|
client.publish("server-rack-led-1/b/status",str(b))
|
||||||
setColor(strip, Color(int(r), int(g), int(b)))
|
setColor(strip, Color(int(r), int(g), int(b)))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
client.publish("server-rack-led-1/power","False")
|
client.publish("server-rack-led-1/power/status","False")
|
||||||
setColor(strip, Color(0,0,0))
|
setColor(strip, Color(0,0,0))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
Loading…
Reference in New Issue