From 3c8c048c4527b4e84619dd84281ba2d4acf27c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Sat, 17 Feb 2024 23:43:51 +0100 Subject: [PATCH] mqtt_publisher as normal function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- server/app.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/app.py b/server/app.py index 98bce5b..7be23a3 100644 --- a/server/app.py +++ b/server/app.py @@ -94,6 +94,10 @@ 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: @@ -110,10 +114,6 @@ def connect_mqtt(): return client def mqtt_publisher(): - def on_message(mqttc, obj, msg): - global TUBE_INDEX - TUBE_INDEX = list(msg.payload.decode()) - # Set Connecting Client ID mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) # client.username_pw_set(username, password) @@ -166,5 +166,4 @@ if __name__ == "__main__": update_tube_index_thread.start() flask_thread = Process(target=flask_api) flask_thread.start() - publisher_thread = Process(target=mqtt_publisher) - publisher_thread.start() \ No newline at end of file + mqtt_publisher() \ No newline at end of file