Watchdog - Hardware

Watchdog.onExpired

Watchdog.onExpired, onExpired

// As a global variable:
retained bool watchdogExpiredFlag = false;

// In setup():
Watchdog.onExpired([]() {
  // This is called from an ISR, beware!
  watchdogExpiredFlag = true;
});

It is possible to set an expired handler. Since the device is probably in an unstable state at that point, you are limited in what you can do from the expired handler. Additionally, it's called an interrupt context (ISR) so you cannot allocate memory, make Particle calls (like publish), cellular modem calls, etc.. About the only thing you can do safely is set a retained variable.

RTL872x platform (P2, Photon 2): If the onExpired() callback is used, the device will not automatically reset.

nRF52 platform (Boron, B-Series SoM, Argon, Tracker SoM): The onExpired() callback is available, and the device will always reset shortly after the callback is called.

Due to the limitations of onExpired() and the difference between platforms, we recommed not using this feature.