diff --git a/mqtt/tempSensor.py b/mqtt/tempSensor.py index a116778..07d0579 100644 --- a/mqtt/tempSensor.py +++ b/mqtt/tempSensor.py @@ -30,7 +30,7 @@ while True: humidity = sensor.humidity #convert to Farenheit - temp = (temp * 1.8) + 32 + #temp = (temp * 1.8) + 32 print("Temperature: {}*F Humidity: {}% ".format(temp, humidity)) except RuntimeError as error: print(error.args[0]) @@ -53,10 +53,7 @@ while True: client.connect(broker, port) #Publish Temp Results - #Convert to string so it can be sent to the broker. - temp = str(temp) - tempClean = f'{ "temperature": {temp} }' - tempMsg = tempClean + tempMsg = '{ "temperature": {} }'.format(temp) result = client.publish(tempTopic, tempMsg) # result: [0, 1] status = result[0] @@ -66,10 +63,7 @@ while True: print(f"Failed to send message to topic {tempTopic}") #Publish Humid Results - #Convert to string so it can be sent to the broker. - humidity = str(humidity) - humidClean = f'{ "humidity": {humidity} }' - humidMsg = humidClean + humidMsg = '{ "humidity": {} }'.format(humidity) result = client.publish(humidTopic, humidMsg) # result: [0, 1] status = result[0]