diff --git a/mqtt_setup.py b/mqtt_setup.py new file mode 100644 index 0000000000000000000000000000000000000000..22a9e68e1af739e0e8293d248fb8ff1b3fe54dd5 --- /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']