db request at script beginning

Signed-off-by: Ebbe Baß <ebbe.bass>
main
Ebbe Baß 2024-02-17 16:30:25 +01:00
parent febd453aa7
commit 3ba023229d
1 changed files with 6 additions and 2 deletions

View File

@ -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()