diff --git a/mqtt/tempSensor.py b/mqtt/tempSensor.py index 0b48b50..46873b0 100644 --- a/mqtt/tempSensor.py +++ b/mqtt/tempSensor.py @@ -54,13 +54,14 @@ def connect_mqtt(): def getValues(sensor): try: - print(sensor) temp = sensor.temperature humidity = sensor.humidity #convert to Farenheit temp = (temp * 1.8) + 32 - print("Temperature: {}*F Humidity: {}% ".format(temp, humidity)) + #Round the decimals + temp = round(temp, 2) + #print("Temperature: {}*F Humidity: {}% ".format(temp, humidity)) except RuntimeError as error: print(error.args[0]) time.sleep(2.0) @@ -73,11 +74,13 @@ def getValues(sensor): def publish(client, temp, humidity): #Publish Temp Results tempMsg = '{{ "temperature": "{}" }}'.format(temp) + #tempMsg = temp result = client.publish(tempTopic, tempMsg) # result: [0, 1] status = result[0] if status == 0: - print(f"Send `{tempMsg}` to topic `{tempTopic}`") + #print(f"Send `{tempMsg}` to topic `{tempTopic}`") + pass else: print(f"Failed to send message to topic {tempTopic}") @@ -87,14 +90,14 @@ def publish(client, temp, humidity): # result: [0, 1] status = result[0] if status == 0: - print(f"Send `{humidMsg}` to topic `{humidTopic}`") + #print(f"Send `{humidMsg}` to topic `{humidTopic}`") + pass else: print(f"Failed to send message to topic {humidTopic}") time.sleep(5.0) -print (sensor) while True: client = connect_mqtt() client.loop_start()