machine.WDT does not appear to work [Sorted]
Re: machine.WDT does not appear to work
Thank you. I think I need to spend some time to actually understand this as I'd like to use wdt.feed() through-out my programs.
Re: machine.WDT does not appear to work
OK, have read-up about module-level Singletons and think I can manage to create one to use.
What I would like to know is why does the system watchdog call wdt.feed() work differently then using other library methods, ie import the library into various modules and call methods from it? Just a keyword is enough.
I use a software WDT written by some kind person on the forum and you just import it into multiple modules and then call wdt_feed() whenever and where ever you want.
What I would like to know is why does the system watchdog call wdt.feed() work differently then using other library methods, ie import the library into various modules and call methods from it? Just a keyword is enough.
I use a software WDT written by some kind person on the forum and you just import it into multiple modules and then call wdt_feed() whenever and where ever you want.
Re: machine.WDT does not appear to work
wdt_singleton.py
Still like to know why wdt.feed() needs to be treated like this.
Code: Select all
from machine import WDT
# system WDT set for 10 seconds
wdt = WDT(timeout = 10000)
def feed_my_wdt():
wdt.feed()
Re: machine.WDT does not appear to work
In my opinion this is basic python OO handling.davef wrote: ↑Thu Jul 28, 2022 9:59 amStill like to know why wdt.feed() needs to be treated like this.Code: Select all
from machine import WDT # system WDT set for 10 seconds wdt = WDT(timeout = 10000) def feed_my_wdt(): wdt.feed()
You have system-wide one watchdog, so you need to create the wdt object once. And you need the wdt object to call any of it's methods.
This can be done in main() - then you need to pass the object around (either using a global variable or a parameter).
Or you use your singleton module.
In case of the global variable or the singleton module, you need to import something wherever you want to retrigger the watchdog.
I'm pretty sure your software watchdog library also uses some module-global variable to save the watchdog object.
A few hours of debugging might save you from minutes of reading the documentation!
My repositories: https://github.com/karfas
My repositories: https://github.com/karfas
Re: machine.WDT does not appear to work
karfas,
Thank you for taking the time to explain.
The Software WDT (by mkiotdev):
The key appears to be global wdt_counter.
Cheers,
Dave
Thank you for taking the time to explain.
The Software WDT (by mkiotdev):
Code: Select all
## Simple software WDT implementation
wdt_counter = 0
def wdt_callback():
global wdt_counter
wdt_counter += 1
if (wdt_counter >= 10):
machine.reset()
def wdt_feed():
global wdt_counter
wdt_counter = 0
wdt_timer = machine.Timer(-1)
wdt_timer.init(period=1000, mode=machine.Timer.PERIODIC, callback=lambda t:wdt_callback())
## END Simple software WDT implementation
Cheers,
Dave