added tube index updater

Signed-off-by: Ebbe Baß <ebbe.bass>
main
Ebbe Baß 2024-02-17 03:09:16 +01:00
parent 9acd2e9d78
commit 13d35d6664
1 changed files with 45 additions and 40 deletions

View File

@ -115,6 +115,9 @@ def start_mqtt_publishers():
mqtt_client = connect_mqtt()
artnetBindIp = get_eth0_ip()
artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454)
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
global result
result = cur.fetchall()
while True:
try:
# Gets whatever the last Art-Net packet we received is
@ -124,10 +127,7 @@ def start_mqtt_publishers():
#Checks to see if the current packet is for the specified DMX Universe
dmxPacket = artNetPacket.data
# Create MQTT topic based on the universe and channel
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
result = cur.fetchall()
for row in result:
try:
dmx_address = int(row[2])
if artNetPacket.universe == int(row[1]):
#Define RGB values per pixel
@ -170,15 +170,20 @@ def start_mqtt_publishers():
mqtt_client.publish(p4_topic, str([p4_r, p4_g, p4_b]))
mqtt_client.publish(p5_topic, str([p5_r, p5_g, p5_b]))
mqtt_client.publish(p6_topic, str([p6_r, p6_g, p6_b]))
except Exception as e:
print(e)
except KeyboardInterrupt:
artNet.close()
sys.exit()
def update_tube_index():
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
global result
result = cur.fetchall()
if __name__ == "__main__":
flask_thread = Process(target=flask_api)
flask_thread.start()
publisher_thread = Process(target=start_mqtt_publishers)
publisher_thread.start()
tube_index_updater_thread = Process(target=update_tube_index)
tube_index_updater_thread.start()