try and fix reliability issues
This commit is contained in:
parent
b4d6e97b46
commit
f5cd4501fe
3 changed files with 19 additions and 31 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue