Watchdogs on the Photon


we just published a new library for using the two HW watchdogs on the photon! For details look on on our blog or on the GitHub repository.

Live long, and prosper!


Your watchdog library may just be a nice fix for a problem I’m having.
What should happen in my program is :-
Wake up from 4 and half minutes of deep sleep , keep checking the clock to see if the minutes is now MOD 5 or 0, read a load of sensor data , send it to my server and back to sleep again , but a i2c sensor is fleezing my code.
So I m having to do a manual reset every few hours or days

What happens on a fleeze , a reset ?

Yeah, your code needs to call the tickle() function within a configured time period so the watchdogs will reset properly. If your code breaks/halts/gets stuck, the watchdogs will reset. Using deep sleep and the independent watchdog (IWDG) won’t work as far as I know (runs on own RC, cannot be stopped). So you can only depend on the window watchdog (WWDG). It is possible to pause and resume the watchdog, we already created and enhancement issue for that, and will implement it within the next week or so.


Very useful. Thanks folks!

@ampunix Did the pause and resume the watchdog feature even get tested successfully and added to your library?

I want to use the Watchdog to reset the Photon or P1 if it ever hangs or does not come out of deep sleep.

How exactly could the Window Watchdog be used to do that?

Any info is greatly appreciated!

1 Like

Also interested in a watchdog to reset in case of deep sleep wake up failure…

Any ideas on how this should be implemented would be welcomed!

Does the library is designed to works only with Photon?
I imported the example in WebIDE from libraries.
While compiling the example for Electron I get the following error.

First, how have you imported the sample? By use of the USE THIS EXAMPLE button?
Since when I do this, I actually get a missing #include "SparkIntervalTimer/SparkIntervalTimer.h".
And after importing that library some system files are not found for the Electron but (revolving around stm32f2xx_wwdg.h and STM32F2xx_Peripheral_Libraries.a).
But for the Photon they seem to be present.

So maybe @mdma might be able to help with that.

Hi! I’m trying this library but I have problem with OTA…
Do you have the same problem? How do you fix it?
I try to start the update via curl but I never receive the start update event, but only a timeout after a few time.
Thanks, Flavio

That'd be hard to tell, since we don't know what your problem with OTA is.

I’m sorry, you are right :smiley: I can’t flash the photon via OTA. Flashing always end up with time out.
I can flash it only in DFU mode. If I remove the watchdog I can flash via OTA again.
It seems that the library doesn’t catch the updatesPending, or the disableUpdates doesn’t work, so it doesn’t disable the timer…
Thank, Flavio

It seems that the problem is if(System.updatesPending()), not called on the last firmware.
I fixed in this way:
removed this piece of code from _tickleWDGs:

// deactivate WWDG if OTA updates pending
If(System.updatesPending()) {
   if(PhotonWdgs::_wwdgRunning) {

Added this line at the bottom of begin()

System.on(firmware_update_pending, handle_update);

Added this method:

void handle_update(system_event_t event, int param)
    Serial.println("UPDATE READY WDGS");
    if(PhotonWdgs::_wwdgRunning) {

It seems to work, let me know if this is working also for you.

Worked for me, as per

Hi flavio, I must be doing something wrong. Where do you add that line exactly?

void PhotonWdgs::begin(bool _enableWwdg,bool _enableIwdg,unsigned long _timeout, TIMid id)
    if(!_enableWwdg && !_enableIwdg) {
        // nothing to do ...
    PhotonWdgs::_aliveCount = 0;
    PhotonWdgs::_timeoutval = _timeout / 10;

    RCC_LSICmd(ENABLE); //LSI is needed for Watchdogs

    PhotonWdgs::_wdgTimer.begin(PhotonWdgs::_tickleWDGs, 20, hmSec, id);
    // OTA updates won't work with watchdog enabled
    PhotonWdgs::_wwdgRunning = _enableWwdg;
    if(_enableWwdg) {
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
    PhotonWdgs::_iwdgRunning = _enableIwdg;
    if(_enableIwdg) {
    System.on(firmware_update_pending, handle_update);
    System.on(setup_begin, handle_setup_begin);
    System.on(setup_end, handle_setup_end);
1 Like

Thank you!