add outputs
This commit is contained in:
parent
31ebe981be
commit
2e6f6b3f1a
@ -48,20 +48,27 @@ while True:
|
||||
# Get Temperature from DHT
|
||||
_, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
|
||||
|
||||
print("temperature before cut: " + temperature)
|
||||
# cut temperature to xx.xx if more then tow digits after "."
|
||||
t_split = temperature.split(".")
|
||||
if len(t_split[1]) > 2:
|
||||
t_cut = len(t_split[1]) - 2
|
||||
t_split[1] = t_split[1][:-t_cut]
|
||||
temperature = t_split[0] + "." + t_split[1]
|
||||
|
||||
print("temperature after cut: " + temperature)
|
||||
# Get Humidity from DHT
|
||||
humidity, _ = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
|
||||
|
||||
print("humidity before cut: " + humidity)
|
||||
# cut humidity to xx.xx if more then tow digits after "."
|
||||
h_split = humidity.split(".")
|
||||
if len(h_split[1]) > 2:
|
||||
h_cut = len(h_split[1]) - 2
|
||||
h_split[1] = h_split[1][:-h_cut]
|
||||
humidity = h_split[0] + "." + h_split[1]
|
||||
|
||||
print("humidity after cut: " + humidity)
|
||||
# Publish our data
|
||||
client.publish(temperature_topic, temperature)
|
||||
client.publish(humidity_topic, humidity)
|
||||
|
Loading…
Reference in New Issue
Block a user