Version 1.0, cleaned out debugging

This commit is contained in:
2022-11-29 15:28:41 -05:00
parent a25b50120c
commit f1b0113c8d

View File

@@ -54,13 +54,14 @@ def connect_mqtt():
def getValues(sensor): def getValues(sensor):
try: try:
print(sensor)
temp = sensor.temperature temp = sensor.temperature
humidity = sensor.humidity humidity = sensor.humidity
#convert to Farenheit #convert to Farenheit
temp = (temp * 1.8) + 32 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: except RuntimeError as error:
print(error.args[0]) print(error.args[0])
time.sleep(2.0) time.sleep(2.0)
@@ -73,11 +74,13 @@ def getValues(sensor):
def publish(client, temp, humidity): def publish(client, temp, humidity):
#Publish Temp Results #Publish Temp Results
tempMsg = '{{ "temperature": "{}" }}'.format(temp) tempMsg = '{{ "temperature": "{}" }}'.format(temp)
#tempMsg = temp
result = client.publish(tempTopic, tempMsg) result = client.publish(tempTopic, tempMsg)
# result: [0, 1] # result: [0, 1]
status = result[0] status = result[0]
if status == 0: if status == 0:
print(f"Send `{tempMsg}` to topic `{tempTopic}`") #print(f"Send `{tempMsg}` to topic `{tempTopic}`")
pass
else: else:
print(f"Failed to send message to topic {tempTopic}") print(f"Failed to send message to topic {tempTopic}")
@@ -87,14 +90,14 @@ def publish(client, temp, humidity):
# result: [0, 1] # result: [0, 1]
status = result[0] status = result[0]
if status == 0: if status == 0:
print(f"Send `{humidMsg}` to topic `{humidTopic}`") #print(f"Send `{humidMsg}` to topic `{humidTopic}`")
pass
else: else:
print(f"Failed to send message to topic {humidTopic}") print(f"Failed to send message to topic {humidTopic}")
time.sleep(5.0) time.sleep(5.0)
print (sensor)
while True: while True:
client = connect_mqtt() client = connect_mqtt()
client.loop_start() client.loop_start()