I the example below I created a class "service" which executed a function at a certain interval. In the example below the wathcdog feed function is caled every second, however the board resets after 10 sec ( the watchdogs timeout )
Must the watchdog be feed from the main thread?
Code: Select all
import machine
import time
import _thread
class service:
def __init__(self,function,delay=10):
self.function = function
self.delay=delay
self.shutdown=False
def main_loop(self):
while not self.shutdown:
self.function()
for i in range(self.delay*10):
time.sleep_ms(100)
def start(self):
self.shutdown=False
try:
print("Starting service. Function '%s' executed every %i sec" % (self.function.__name__,self.delay))
except:
print("Starting service. Function '%s' executed every %i sec" % ("bound method",self.delay))
self.thread=_thread.start_new_thread(self.main_loop,())
def stop(self):
self.shutdown=True
wd_timeout = 10000
wd = machine.WDT(id=0, timeout=wd_timeout)
service_wd=service(function=wd.feed,delay=1)
service_wd.start()