File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ def user_task(client):
4141 client ["clight" ].bri = round (uniform (0 , 100 ), 1 )
4242
4343
44+ def wdt_task (client ):
45+ global wdt
46+ # Update the WDT to prevent it from resetting the system
47+ wdt .feed ()
48+
49+
4450def wifi_connect ():
4551 if not WIFI_SSID or not WIFI_PASS :
4652 raise (Exception ("Network is not configured. Set SSID and passwords in secrets.py" ))
@@ -109,5 +115,18 @@ def wifi_connect():
109115 # to client.register().
110116 client .register (Task ("user_task" , on_run = user_task , interval = 1.0 ))
111117
118+ # If a Watchdog timer is available, it can be used to recover the system by resetting it, if it ever
119+ # hangs or crashes for any reason. NOTE: once the WDT is enabled it must be reset periodically to
120+ # prevent it from resetting the system, which is done in another user task.
121+ # NOTE: Change the following to True to enable the WDT.
122+ if False :
123+ try :
124+ from machine import WDT
125+ # Enable the WDT with a timeout of 5s (1s is the minimum)
126+ wdt = WDT (timeout = 7500 )
127+ client .register (Task ("watchdog_task" , on_run = wdt_task , interval = 1.0 ))
128+ except (ImportError , AttributeError ):
129+ pass
130+
112131 # Start the Arduino IoT cloud client.
113132 client .start ()
You can’t perform that action at this time.
0 commit comments