Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/micropython.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def user_task(client):
client["clight"].bri = round(uniform(0, 100), 1)


def wdt_task(client):
global wdt
# Update the WDT to prevent it from resetting the system
wdt.feed()


def wifi_connect():
if not WIFI_SSID or not WIFI_PASS:
raise (Exception("Network is not configured. Set SSID and passwords in secrets.py"))
Expand Down Expand Up @@ -109,5 +115,18 @@ def wifi_connect():
# to client.register().
client.register(Task("user_task", on_run=user_task, interval=1.0))

# If a Watchdog timer is available, it can be used to recover the system by resetting it, if it ever
# hangs or crashes for any reason. NOTE: once the WDT is enabled it must be reset periodically to
# prevent it from resetting the system, which is done in another user task.
# NOTE: Change the following to True to enable the WDT.
if False:
try:
from machine import WDT
# Enable the WDT with a timeout of 5s (1s is the minimum)
wdt = WDT(timeout=7500)
client.register(Task("watchdog_task", on_run=wdt_task, interval=1.0))
except (ImportError, AttributeError):
pass

# Start the Arduino IoT cloud client.
client.start()