change mechanism to run
removed the loop, needs to be executed by cron
This commit is contained in:
parent
3a4d974a89
commit
3a2d1ec06f
@ -36,9 +36,6 @@ time_topic = 'weathersensors/' + client_id + '/time'
|
||||
#client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials
|
||||
client.connect(mqtt_broker) # MQTT server address
|
||||
|
||||
client.loop_start()
|
||||
|
||||
while True:
|
||||
# DATETIME
|
||||
now = datetime.now()
|
||||
#print("now =", now)
|
||||
@ -49,30 +46,16 @@ while True:
|
||||
# Get Temperature from DHT
|
||||
_, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
|
||||
|
||||
print("temperature before cut: " + str(temperature))
|
||||
# cut temperature to xx.xx if more then tow digits after "."
|
||||
t_split = str(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]
|
||||
temperature = round(float(temperature),2)
|
||||
|
||||
print("temperature after cut: " + temperature)
|
||||
print("temperature after round: " + temperature)
|
||||
# Get Humidity from DHT
|
||||
humidity, _ = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
|
||||
|
||||
print("humidity before cut: " + str(humidity))
|
||||
# cut humidity to xx.xx if more then tow digits after "."
|
||||
h_split = str(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]
|
||||
humidity = round(float(humidity),2)
|
||||
|
||||
print("humidity after cut: " + humidity)
|
||||
print("humidity after round: " + humidity)
|
||||
# Publish our data
|
||||
client.publish(temperature_topic, temperature)
|
||||
client.publish(humidity_topic, humidity)
|
||||
client.publish(time_topic, dt_string)
|
||||
|
||||
time.sleep(30)
|
Loading…
Reference in New Issue
Block a user