Send data as single "packet" instead of multiple
This commit is contained in:
parent
01dd30d2cf
commit
b7205f397f
@ -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 )
|
||||
|
Loading…
Reference in New Issue
Block a user