37 lines
885 B
Python
Executable file
37 lines
885 B
Python
Executable file
import time
|
|
import supervisor
|
|
from weather_station.pubsub import PubSub
|
|
from weather_station.timer import Timer
|
|
from weather_station.bme280 import BME280
|
|
from weather_station.airlift import AirLift
|
|
|
|
pubsub = PubSub()
|
|
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:
|
|
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()
|
|
|