added TUBE_INDEX to mqtt publisher and removed it at script start

Signed-off-by: Ebbe Baß <ebbe.bass>
main
Ebbe Baß 2024-02-17 16:38:46 +01:00
parent 7affda9c98
commit 31eb06a2ab
1 changed files with 5 additions and 15 deletions

View File

@ -43,11 +43,6 @@ db.autocommit(True)
mqtt_client_id = "PiXelTubeMaster-"+wlan_mac_address
cur = db.cursor()
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
TUBE_INDEX = cur.fetchall()
cur.close()
# Function to register a tube in the database
def register_tube(mac_address):
cur = db.cursor()
@ -120,7 +115,10 @@ def mqtt_publisher():
artnetBindIp = get_eth0_ip()
artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454)
while True:
print(TUBE_INDEX)
cur = db.cursor()
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
TUBE_INDEX = cur.fetchall()
cur.close()
try:
# Gets whatever the last Art-Net packet we received is
artNetPacket = artNet.readPacket()
@ -149,12 +147,4 @@ if __name__ == "__main__":
flask_thread = Process(target=flask_api)
flask_thread.start()
publisher_thread = Process(target=mqtt_publisher)
publisher_thread.start()
# Tube index updater
while True:
cur = db.cursor()
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
TUBE_INDEX = cur.fetchall()
cur.close()
print("Updated index: "+str(TUBE_INDEX))
time.sleep(1)
publisher_thread.start()