try and fix reliability issues

This commit is contained in:
Travis Shears 2023-08-15 21:22:13 +02:00
parent b4d6e97b46
commit f5cd4501fe
Signed by: travisshears
GPG key ID: D4C2E4DFAB8BABF8
3 changed files with 19 additions and 31 deletions

View file

@ -1,5 +1,4 @@
import time
import supervisor
from weather_station.pubsub import PubSub
from weather_station.timer import Timer
from weather_station.bme280 import BME280
@ -10,28 +9,19 @@ airlift = AirLift(pubsub)
bme280 = BME280(pubsub)
timers = [
Timer(pubsub, 120),
Timer(pubsub, 86400),
]
board_reload_calls_count = 0
def board_reload(_):
global board_reload_calls_count
if board_reload_calls_count > 0:
print("resetting board in 10 sec")
time.sleep(10)
supervisor.reload()
board_reload_calls_count += 1
pubsub.subscribe('tick 86400', board_reload)
while True:
try:
airlift.mqtt_client.loop()
for timer in timers:
t = time.time()
timer.tick(t)
except Exception as e:
# raise # for debugging
print("encountered problem", e)
time.sleep(60)
supervisor.reload()
except (ValueError, RuntimeError, ConnectionError) as e:
print("Ran into problem\n", e)
airlift.esp.reset()
time.sleep(5)
airlift.connect()
airlift.mqtt_client.reconnect()
time.sleep(5)
continue