parent
b90817b892
commit
2c6b5c5c6b
|
@ -57,41 +57,34 @@ def is_connected_to_wifi():
|
||||||
output = subprocess.check_output(['iwgetid']).decode()
|
output = subprocess.check_output(['iwgetid']).decode()
|
||||||
return output.split('"')[1]
|
return output.split('"')[1]
|
||||||
|
|
||||||
# def update_led_strip(rgb_values, pixel, strip):
|
def update_led_strip(rgb_values, pixel, strip):
|
||||||
# for i in range(LEDS_PER_PIXEL):
|
strip[int(pixel)] = Color(rgb_values)
|
||||||
# strip[int(pixel)] = Color(rgb_values[i])
|
|
||||||
|
|
||||||
# def mqtt_listner(msg, universe, dmx_address, strip, LEDS_PER_PIXEL):
|
def on_message(mqttc, obj, msg):
|
||||||
# try:
|
if msg.topic == "tube-"+wlan_mac_address+"/p1":
|
||||||
# # Parse the topic to get universe and channel
|
for pixel in range(LEDS_PER_PIXEL):
|
||||||
# _, dmx_universe, channel_number = msg.topic.split("/")
|
update_led_strip(list(msg.payload), pixel)
|
||||||
# channel_number = int(channel_number)
|
|
||||||
|
|
||||||
# # Calculate the pixel index and channel within the pixel
|
elif msg.topic == "tube-"+wlan_mac_address+"/p2":
|
||||||
# pixel_index = (channel_number - dmx_address) // LEDS_PER_PIXEL
|
for pixel in range(LEDS_PER_PIXEL, LEDS_PER_PIXEL*2):
|
||||||
# channel_in_pixel = (channel_number - dmx_address) % LEDS_PER_PIXEL
|
update_led_strip(list(msg.payload), pixel)
|
||||||
|
|
||||||
# # Initialize a new pixel entry if not present
|
elif msg.topic == "tube-"+wlan_mac_address+"/p3":
|
||||||
# if pixel_index not in pixel_data:
|
for pixel in range(LEDS_PER_PIXEL*2, LEDS_PER_PIXEL*3):
|
||||||
# pixel_data[pixel_index] = [0] * LEDS_PER_PIXEL
|
update_led_strip(list(msg.payload), pixel)
|
||||||
|
|
||||||
# # Update the RGB value for the corresponding channel in the pixel
|
elif msg.topic == "tube-"+wlan_mac_address+"/p4":
|
||||||
# pixel_data[pixel_index][channel_in_pixel] = int(msg.payload)
|
for pixel in range(LEDS_PER_PIXEL*3, LEDS_PER_PIXEL*4):
|
||||||
|
update_led_strip(list(msg.payload), pixel)
|
||||||
|
|
||||||
# # Check if all three channels for the pixel are received
|
elif msg.topic == "tube-"+wlan_mac_address+"/p5":
|
||||||
# if len(pixel_data[pixel_index]) == LEDS_PER_PIXEL:
|
for pixel in range(LEDS_PER_PIXEL*4, LEDS_PER_PIXEL*5):
|
||||||
# # Set the RGB values for the pixel in the LED strip
|
update_led_strip(list(msg.payload), pixel)
|
||||||
# update_led_strip(pixel_index, pixel_data[pixel_index], strip)
|
|
||||||
|
|
||||||
# # Remove the pixel entry from the temporary storage
|
elif msg.topic == "tube-"+wlan_mac_address+"/p6":
|
||||||
# del pixel_data[pixel_index]
|
for pixel in range(LEDS_PER_PIXEL*5, LEDS_PER_PIXEL*6):
|
||||||
|
update_led_strip(list(msg.payload), pixel)
|
||||||
|
|
||||||
# except Exception as e:
|
|
||||||
# print(f"Error: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
# def on_message(mqttc, obj, msg):
|
|
||||||
# mqtt_listner(msg)
|
|
||||||
|
|
||||||
def loopCheckSettingUpdates():
|
def loopCheckSettingUpdates():
|
||||||
while True:
|
while True:
|
||||||
|
@ -103,7 +96,6 @@ def loopCheckSettingUpdates():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
exit()
|
exit()
|
||||||
sys.exit()
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -116,13 +108,18 @@ if __name__ == "__main__":
|
||||||
global dmx_address
|
global dmx_address
|
||||||
universe, dmx_address = get_assigned_params()
|
universe, dmx_address = get_assigned_params()
|
||||||
|
|
||||||
# mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||||
# mqttc.connect("192.168.0.1", 1883, 60)
|
mqttc.connect("192.168.0.1", 1883, 60)
|
||||||
# mqttc.on_message = on_message
|
mqttc.on_message = on_message
|
||||||
# mqttc.subscribe("PiXelTubes/"+str(universe), 0)
|
mqttc.subscribe("tube-"+str(wlan_mac_address)+"/p1", 0)
|
||||||
|
mqttc.subscribe("tube-"+str(wlan_mac_address)+"/p2", 0)
|
||||||
|
mqttc.subscribe("tube-"+str(wlan_mac_address)+"/p3", 0)
|
||||||
|
mqttc.subscribe("tube-"+str(wlan_mac_address)+"/p4", 0)
|
||||||
|
mqttc.subscribe("tube-"+str(wlan_mac_address)+"/p5", 0)
|
||||||
|
mqttc.subscribe("tube-"+str(wlan_mac_address)+"/p6", 0)
|
||||||
|
|
||||||
settingsUpdateThread = Thread(target=loopCheckSettingUpdates, args=())
|
settingsUpdateThread = Thread(target=loopCheckSettingUpdates, args=())
|
||||||
# pixelUpdateThread = Thread(target=mqtt_listner, args=(universe, dmx_address, strip, LEDS_PER_PIXEL))
|
pixelUpdateThread = Thread(target=mqtt_listner, args=(universe, dmx_address, strip, LEDS_PER_PIXEL))
|
||||||
|
|
||||||
settingsUpdateThread.start()
|
settingsUpdateThread.start()
|
||||||
# pixelUpdateThread.start()
|
pixelUpdateThread.start()
|
Loading…
Reference in New Issue