parent
27b59d05fa
commit
d12e59cab3
|
@ -62,8 +62,26 @@ def update_led_strip(rgb_values, pixel, strip):
|
||||||
strip[int(pixel)] = rgb_values
|
strip[int(pixel)] = rgb_values
|
||||||
|
|
||||||
def on_message(mqttc, obj, msg):
|
def on_message(mqttc, obj, msg):
|
||||||
|
global rgb_values_list
|
||||||
rgb_values_list = eval(msg.payload.decode())
|
rgb_values_list = eval(msg.payload.decode())
|
||||||
|
|
||||||
|
# strip.show()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Connect to Wi-Fi
|
||||||
|
if is_connected_to_wifi() is not None:
|
||||||
|
# Register/reauthenticate the tube
|
||||||
|
register_tube()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||||
|
mqttc.connect("192.168.0.1", 1883, 60)
|
||||||
|
mqttc.on_message = on_message
|
||||||
|
mqttc.subscribe("tube-"+str(wlan_mac_address)+"/pixel_colors", 0)
|
||||||
|
|
||||||
|
mqttc.loop_forever()
|
||||||
|
|
||||||
|
while True:
|
||||||
for pixel in range(LEDS_PER_PIXEL):
|
for pixel in range(LEDS_PER_PIXEL):
|
||||||
update_led_strip(tuple(eval(rgb_values_list[0])), pixel, strip)
|
update_led_strip(tuple(eval(rgb_values_list[0])), pixel, strip)
|
||||||
|
|
||||||
|
@ -81,19 +99,3 @@ def on_message(mqttc, obj, msg):
|
||||||
|
|
||||||
for pixel in range(LEDS_PER_PIXEL*5, LEDS_PER_PIXEL*6):
|
for pixel in range(LEDS_PER_PIXEL*5, LEDS_PER_PIXEL*6):
|
||||||
update_led_strip(tuple(eval(rgb_values_list[5])), pixel, strip)
|
update_led_strip(tuple(eval(rgb_values_list[5])), pixel, strip)
|
||||||
|
|
||||||
# strip.show()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# Connect to Wi-Fi
|
|
||||||
if is_connected_to_wifi() is not None:
|
|
||||||
# Register/reauthenticate the tube
|
|
||||||
register_tube()
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
|
||||||
mqttc.connect("192.168.0.1", 1883, 60)
|
|
||||||
mqttc.on_message = on_message
|
|
||||||
mqttc.subscribe("tube-"+str(wlan_mac_address)+"/pixel_colors", 0)
|
|
||||||
|
|
||||||
mqttc.loop_forever()
|
|
Loading…
Reference in New Issue