From 3ba023229d411263ed7d286f6cb9db59b05c083e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Sat, 17 Feb 2024 16:30:25 +0100 Subject: [PATCH] db request at script beginning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- server/app.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/app.py b/server/app.py index 1e5bed9..3cfc100 100644 --- a/server/app.py +++ b/server/app.py @@ -43,6 +43,11 @@ 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() @@ -141,10 +146,10 @@ def mqtt_publisher(): sys.exit() def update_tube_index(): + global TUBE_INDEX while True: cur = db.cursor() cur.execute("SELECT mac_address, universe, dmx_address FROM tubes") - global TUBE_INDEX TUBE_INDEX = cur.fetchall() cur.close() print("Updated index: "+str(TUBE_INDEX)) @@ -155,6 +160,5 @@ if __name__ == "__main__": tube_index_updater_thread.start() flask_thread = Process(target=flask_api) flask_thread.start() - print(globals()) publisher_thread = Process(target=mqtt_publisher) publisher_thread.start()