From 3a5ad1e6af9562971f0a37d4709d47dcc13a61ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Sun, 18 Feb 2024 00:08:39 +0100 Subject: [PATCH] revert changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- server/app.py | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/server/app.py b/server/app.py index 221184c..4a2d4e6 100644 --- a/server/app.py +++ b/server/app.py @@ -94,10 +94,6 @@ def get_eth0_ip(): except (KeyError, IndexError, OSError) as e: print(f"Error getting eth0 IP: {e}") exit - -def on_message(mqttc, obj, msg): - global TUBE_INDEX - TUBE_INDEX = list(msg.payload.decode()) def on_connect(client, userdata, flags, reason_code, properties): if reason_code == 0: @@ -113,11 +109,19 @@ def connect_mqtt(): client.connect("localhost", 1883) return client -def mqtt_publisher(): +if __name__ == "__main__": + flask_thread = Process(target=flask_api) + flask_thread.start() + # Create and start a thread for each universe + mqtt_client = connect_mqtt() artnetBindIp = get_eth0_ip() artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454) while True: + 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() @@ -140,26 +144,4 @@ def mqtt_publisher(): mqtt_client.publish(p1_topic, str([str([p1_r, p1_g, p1_b]), str([p2_r, p2_g, p2_b]), str([p3_r, p3_g, p3_b]), str([p4_r, p4_g, p4_b]), str([p5_r, p5_g, p5_b]), str([p6_r, p6_g, p6_b])])) except KeyboardInterrupt: artNet.close() - sys.exit() - -def tube_index_updater(): - while True: - mqtt_client = connect_mqtt() - cur = db.cursor() - cur.execute("SELECT mac_address, universe, dmx_address FROM tubes") - TUBE_INDEX = cur.fetchall() - cur.close() - mqtt_client.publish("pxm/tube_index", str(TUBE_INDEX)) - print("Updated tube index") - time.sleep(5) - - -if __name__ == "__main__": - update_tube_index_thread = Process(target=tube_index_updater) - update_tube_index_thread.start() - flask_thread = Process(target=flask_api) - flask_thread.start() - mqtt_client = connect_mqtt() - mqtt_client.subscribe("pxm/tube_index") - mqtt_client.loop_start() - mqtt_publisher() \ No newline at end of file + sys.exit() \ No newline at end of file