OK, so it seems that the watchdog is not fully implemented on the esp8266 as it is used internally.
It appears that all you can do is trigger it by disabling interrupts, not sure how useful that would be.
I would like to implement a watchdog in some devices, especially where they are battery powered and 100% stand-alone and unmanned, just to guard against something unexpected happening and the device exits it's main loop and just sits there draining the battery power until it is no more.
So this is what I have come up with and I don't see any reason why this should not work, but are looking for any feedback, comments or suggestions:
Code: Select all
import machine as mc
class WDOG():
def __init__(self):
self.timer = mc.Timer(-1)
self.fed = False
def feed(self):
self.fed = True
def wdcb(self):
pass
def wdtcb(self,tmr):
if not self.fed: mc.reset()
self.fed = False
self.wdcb()
def init(self,msec=5000):
self.timer.init(period=msec, mode=mc.Timer.PERIODIC, callback=self.wdtcb)
self.feed()
'''
import wdog, time
wd = wdog.WDOG()
wd.init(2000)
for i in range(10):
wd.feed()
time.sleep(1)
print('feeding')
'''