Send data as single "packet" instead of multiple
This commit is contained in:
parent
01dd30d2cf
commit
b7205f397f
@ -80,18 +80,16 @@ with serial.Serial(uart_name, uart_baud_rate, timeout=2) as uart:
|
|||||||
|
|
||||||
# Formatting data for sending to MQTT broker (one source at a time)
|
# Formatting data for sending to MQTT broker (one source at a time)
|
||||||
for s in data.items():
|
for s in data.items():
|
||||||
mqtt_data = []
|
|
||||||
for d in s[1].items():
|
for d in s[1].items():
|
||||||
payload = json.dumps({"date": reception_date,
|
payload = json.dumps({"date": reception_date,
|
||||||
"value": d[1],
|
"value": d[1],
|
||||||
"unit": data_unit[d[0]],
|
"unit": data_unit[d[0]],
|
||||||
"type": data_type[d[0]]})
|
"type": data_type[d[0]]})
|
||||||
mqtt_data.append({'topic': "{}/{}".format(mqtt_topic, s[0]),
|
print(payload)
|
||||||
'payload': payload,
|
mqtt.single("{}/{}".format(mqtt_topic, s[0]),
|
||||||
'qos': 2,
|
payload= payload ,
|
||||||
'retain': True})
|
qos= 2 ,
|
||||||
pprint.pprint(mqtt_data)
|
retain= True ,
|
||||||
mqtt.multiple(mqtt_data,
|
|
||||||
hostname= mqtt_host ,
|
hostname= mqtt_host ,
|
||||||
port= mqtt_port ,
|
port= mqtt_port ,
|
||||||
client_id= mqtt_client_id ,
|
client_id= mqtt_client_id ,
|
||||||
|
Loading…
Reference in New Issue
Block a user