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:
temp = sensor.temperature
humidity = sensor.humidity
#convert to Farenheit #convert to Farenheit
temp = (temp * 1.8) + 32 temp = (temp * 1.8) + 32
#Round the decimals #Round the decimals
temp = round(temp, 2) temp = round(temp, 2)
#print("Temperature: {}*F Humidity: {}% ".format(temp, humidity)) #print("Temperature: {}*F Humidity: {}% ".format(temp, humidity))
except RuntimeError as error: result = 1
print(error.args[0]) except RuntimeError as error:
time.sleep(2.0) print(error.args[0])
except Exception as error: time.sleep(2.0)
sensor.exit() return temp, humidity
raise error
return temp, humidity
def publish(client, temp, humidity): def publish(client, temp, humidity):