This commit is contained in:
2022-12-06 08:31:13 -05:00

View File

@@ -39,22 +39,23 @@ def connect_mqtt():
def getValues(sensor): def getValues(sensor):
try: #While loop to try sensor again if it fails, seems to happen occasionally
temp = sensor.temperature result = None
humidity = sensor.humidity while result is None:
try:
#convert to Farenheit temp = sensor.temperature
temp = (temp * 1.8) + 32 humidity = sensor.humidity
#Round the decimals
temp = round(temp, 2) #convert to Farenheit
#print("Temperature: {}*F Humidity: {}% ".format(temp, humidity)) temp = (temp * 1.8) + 32
except RuntimeError as error: #Round the decimals
print(error.args[0]) temp = round(temp, 2)
time.sleep(2.0) #print("Temperature: {}*F Humidity: {}% ".format(temp, humidity))
except Exception as error: result = 1
sensor.exit() except RuntimeError as error:
raise error print(error.args[0])
return temp, humidity time.sleep(2.0)
return temp, humidity
def publish(client, temp, humidity): def publish(client, temp, humidity):