From cfd69b682d9151e0833d4e2cea4464df9e416ba2 Mon Sep 17 00:00:00 2001 From: jerick Date: Mon, 28 Nov 2022 14:03:58 -0500 Subject: [PATCH] Set values to string for payload --- mqtt/tempSensor.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mqtt/tempSensor.py b/mqtt/tempSensor.py index b77ff50..a116778 100644 --- a/mqtt/tempSensor.py +++ b/mqtt/tempSensor.py @@ -53,7 +53,10 @@ while True: client.connect(broker, port) #Publish Temp Results - tempMsg = '{ "temperature": {} }'.format(temp) + #Convert to string so it can be sent to the broker. + temp = str(temp) + tempClean = f'{ "temperature": {temp} }' + tempMsg = tempClean result = client.publish(tempTopic, tempMsg) # result: [0, 1] status = result[0] @@ -63,8 +66,10 @@ while True: print(f"Failed to send message to topic {tempTopic}") #Publish Humid Results - - humidMsg = '{ "humidity": {} }'.format(humidity) + #Convert to string so it can be sent to the broker. + humidity = str(humidity) + humidClean = f'{ "humidity": {humidity} }' + humidMsg = humidClean result = client.publish(humidTopic, humidMsg) # result: [0, 1] status = result[0]