8000 WIP · micropython/micropython@acb263d · GitHub
[go: up one dir, main page]

Skip to content

Commit acb263d

Browse files
committed
WIP
1 parent 686908c commit acb263d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/esp32/tutorial/wdt.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.. _esp32_wdt:
2+
3+
When the WDT timeout is short, there is a software update issue:
4+
you don't have enough time to copy the updates to the device.
5+
ESP32 alows reinitialise the watchdog with a longer timeout - like an hour.
6+
7+
More comprehansive example usage::
8+
9+
# Save as 'main.py' and it will run automatically after 'boot.py'
10+
11+
import sys
12+
from time import sleep
13+
from machine import WDT, reset
14+
15+
try:
16+
print('Press Ctrl-C to break the program.')
17+
sleep(5)
18+
print('Enable the WDT with a timeout of 5s.')
19+
wdt = WDT(timeout=5000)
20+
21+
seconds = 1
22+
while True: # infinite work loop
23+
print('Do something useful in less than 5 seconds.')
24+
print(f'Sleep {seconds} seconds.')
25+
if seconds >= 5:
26+
print(f'WDT will reboot the board.')
27+
sleep(seconds)
28+
seconds += 1
29+
wdt.feed()
30+
31+
# 1/0 # uncoment this line to raise an runtime exception, then WDT reboot
32+
33+
# sys.exit() # uncomment this line for planned program exit
34+
35+
except SystemExit:
36+
wdt = WDT(timeout=1000 * 60 * 60) # 1 hour before WDT reboot
37+
print('Now you have 1 hour to update program on the board.')
38+
print('When ready, type reset() on the REPL/WebREPL command line to reboot.')
39+

0 commit comments

Comments
 (0)
0