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