From b7205f397f84f57c64ddc0dd2ead45a70cadf882 Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Sat, 4 Aug 2018 19:21:08 +0200 Subject: [PATCH] Send data as single "packet" instead of multiple --- raspberry/python/uart2mqtt.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/raspberry/python/uart2mqtt.py b/raspberry/python/uart2mqtt.py index 6600c45..dd7911d 100644 --- a/raspberry/python/uart2mqtt.py +++ b/raspberry/python/uart2mqtt.py @@ -80,19 +80,17 @@ with serial.Serial(uart_name, uart_baud_rate, timeout=2) as uart: # Formatting data for sending to MQTT broker (one source at a time) for s in data.items(): - mqtt_data = [] for d in s[1].items(): payload = json.dumps({"date": reception_date, "value": d[1], "unit": data_unit[d[0]], "type": data_type[d[0]]}) - mqtt_data.append({'topic': "{}/{}".format(mqtt_topic, s[0]), - 'payload': payload, - 'qos': 2, - 'retain': True}) - pprint.pprint(mqtt_data) - mqtt.multiple(mqtt_data, - hostname= mqtt_host , - port= mqtt_port , - client_id= mqtt_client_id , - auth= mqtt_auth ) + print(payload) + mqtt.single("{}/{}".format(mqtt_topic, s[0]), + payload= payload , + qos= 2 , + retain= True , + hostname= mqtt_host , + port= mqtt_port , + client_id= mqtt_client_id , + auth= mqtt_auth )