From 0a062438f9508b93e02f27bb82af3118bbb5e9b4 Mon Sep 17 00:00:00 2001 From: su530201 <olivier.kaufmann@umons.ac.be> Date: Fri, 18 Feb 2022 18:58:38 +0100 Subject: [PATCH] Updates scripts and notebooks; fixes missing mqtt_setup.py --- mqtt_setup.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 mqtt_setup.py diff --git a/mqtt_setup.py b/mqtt_setup.py new file mode 100644 index 00000000..22a9e68e --- /dev/null +++ b/mqtt_setup.py @@ -0,0 +1,18 @@ +from settings import MQTT_CONFIG +import paho.mqtt.client as mqtt + + +def on_message(client, userdata, message): + m = str(message.payload.decode("utf-8")) + print(f'message received {m}') + print(f'topic: {message.topic}') + print(f'qos: {message.qos}') + print(f'retain flag: {message.retain}') + client.publish(MQTT_CONFIG['measurements_topic'], f'{m} 45 ohm.m') + + +def mqtt_client_setup(): + client = mqtt.Client(MQTT_CONFIG['client_id'], protocol=4) # create new client instance + client.connect(MQTT_CONFIG['mqtt_broker']) + client.on_message = on_message + return client, MQTT_CONFIG['measurements_topic'] -- GitLab