File tree 1 file changed +19
-0
lines changed
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):
41
41
client ["clight" ].bri = round (uniform (0 , 100 ), 1 )
42
42
43
43
44
+ def wdt_task (client ):
45
+ global wdt
46
+ # Update the WDT to prevent it from resetting the system
47
+ wdt .feed ()
48
+
49
+
44
50
def wifi_connect ():
45
51
if not WIFI_SSID or not WIFI_PASS :
46
52
raise (Exception ("Network is not configured. Set SSID and passwords in secrets.py" ))
@@ -109,5 +115,18 @@ def wifi_connect():
109
115
# to client.register().
110
116
client .register (Task ("user_task" , on_run = user_task , interval = 1.0 ))
111
117
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
+
112
131
# Start the Arduino IoT cloud client.
113
132
client .start ()
You can’t perform that action at this time.
0 commit comments