change mechanism to run

removed the loop, needs to be executed by cron
This commit is contained in:
robert 2021-02-18 09:46:13 +01:00
parent 3a4d974a89
commit 3a2d1ec06f

View File

@ -36,9 +36,6 @@ time_topic = 'weathersensors/' + client_id + '/time'
#client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials #client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials
client.connect(mqtt_broker) # MQTT server address client.connect(mqtt_broker) # MQTT server address
client.loop_start()
while True:
# DATETIME # DATETIME
now = datetime.now() now = datetime.now()
#print("now =", now) #print("now =", now)
@ -49,30 +46,16 @@ 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: " + str(temperature)) temperature = round(float(temperature),2)
# 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]
print("temperature after cut: " + temperature) print("temperature after round: " + 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: " + str(humidity)) humidity = round(float(humidity),2)
# 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]
print("humidity after cut: " + humidity) print("humidity after round: " + 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)
client.publish(time_topic, dt_string) client.publish(time_topic, dt_string)
time.sleep(30)