Initialize watchdog timer from function

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Initialize watchdog timer from function

Post by bulletmark » Wed Jun 29, 2022 9:35 am

PM-TPI wrote:
Wed Jun 29, 2022 8:36 am
wdt = WDT(timeout=120_000) is run before wdt.feed()
No it's not.

PM-TPI
Posts: 75
Joined: Fri Jun 28, 2019 3:09 pm

Re: Initialize watchdog timer from function

Post by PM-TPI » Thu Jun 30, 2022 11:34 am

PM-TPI wrote:
Wed Jun 29, 2022 8:36 am
Note: start_up() is run before run_ing()
isn't the order...
a) wdt = WDT(timeout=120_000) to Initialize
then..
b) wdt.feed

Or do I have this backwards ?

bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Initialize watchdog timer from function

Post by bulletmark » Thu Jun 30, 2022 11:49 am

The error you report here shows that `wdt.feed()` is being called at startup *before* `wdt = WDT(timeout=120_000)`.

PM-TPI
Posts: 75
Joined: Fri Jun 28, 2019 3:09 pm

Re: Initialize watchdog timer from function

Post by PM-TPI » Thu Jun 30, 2022 3:09 pm

Code: Select all

from machine import WDT

def start_up():	# This is run FIRST... init wifi ble etc
	global wdt
	other stuff....
	
	wdt = WDT(timeout=120_000) # 2min

def run_ing():	# This is run AFTER start_up and is run every min.
	global wdt
	wdt.feed()
	other stuff....
wdt.feed() is in... run_ing()
not start_up()

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Initialize watchdog timer from function

Post by karfas » Thu Jun 30, 2022 3:33 pm

PM-TPI wrote:
Thu Jun 30, 2022 3:09 pm

Code: Select all

from machine import WDT

def start_up():	# This is run FIRST... init wifi ble etc
	global wdt
	other stuff....
	
	wdt = WDT(timeout=120_000) # 2min

def run_ing():	# This is run AFTER start_up and is run every min.
	global wdt
	wdt.feed()
	other stuff....
wdt.feed() is in... run_ing()
not start_up()
Nobody cares how you name the functions where WDT() and wdt.feed() get called.

In your case, run_ing() is (obviously) called somewhere before the Watchdog object instance (=wdt) gets created.
Also note that you need to declare the global variable near the beginning of your file ("wdt = None" like in a previous post).
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

Post Reply