From 31eb06a2ab81f3f1b88a217a2d530dfbdd768d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Sat, 17 Feb 2024 16:38:46 +0100 Subject: [PATCH] added TUBE_INDEX to mqtt publisher and removed it at script start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- server/app.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/server/app.py b/server/app.py index a127bd4..b60cc28 100644 --- a/server/app.py +++ b/server/app.py @@ -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) \ No newline at end of file + publisher_thread.start() \ No newline at end of file