# I'm trying to test the application watchdog

**URL:** <https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403>\
**Category:** Troubleshooting\
**Created:** [May 4, 2017, 10:30pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403 "2017-05-04T22:30:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tahl](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tahl/32/9609_2.png) [@Tahl](https://community.particle.io/u/Tahl)\
**Post date:** [May 4, 2017, 10:30pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/1 "2017-05-04T22:30:47Z")

</div>

Seems simple enough:

ApplicationWatchdog wd(60000, System.reset);

But to test it, I’m doing this inside the loop() – like 15 seconds after boot:

while (1==1) {  
}

Doesn’t that “starve” the loop and cause a reboot like in 60 seconds? I’ve turned off System Thread just in case.

Sort of related, when it downloads new firmware, I get a reset reason of 140 (user reason) instead of 70 (successful firmware update). What am I missing?

Thanks!  
Tahl

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 4, 2017, 11:14pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/2 "2017-05-04T23:14:16Z")

</div>

@Tahl, I just tried a very simple app and had the same problem so I can confirm the issue.

```auto
ApplicationWatchdog wd(60000, System.reset);

void setup() {

}

void loop() {

    while(1) Particle.process();

}

```

However, I can’t confirm the OTA reset reason issue.

@rickkas7 can you please confirm?

---

<div class="post-metadata">

**Author:** ![Tahl](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tahl/32/9609_2.png) [@Tahl](https://community.particle.io/u/Tahl)\
**Post date:** [May 4, 2017, 11:35pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/3 "2017-05-04T23:35:26Z")

</div>

@peekay123, Actually your code looks it would keep things alive and not trigger the watchdog if I understand it. If you did a tight loop with any BUT Particle.process(), the watchdog should step in since the loop() is not looping.

Tahl

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 4, 2017, 11:46pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/4 "2017-05-04T23:46:39Z")

</div>

@Tahl, `Particle.process()` should NOT keep the watchdog going. Removing it, however, will cause the Cloud connection to drop since the background process is not allowed to run. What I see is the Photon comes online (breathing cyan) then goes to breathing green after about 10 seconds. After almost 2 mins, the Photon seems to reset and start over.

I will try with SYSTEM\_THREAD(ENABLED).

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 5, 2017, 12:18am UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/5 "2017-05-05T00:18:37Z")

</div>

@Tahl, I ran with SYSTEM\_THREAD(ENABLED), with and without Particle.process(). Without, the Photon resets after about 2 minutes, showing `spark/device/last_resetuser` in the console. After that, the Photon reset every minute, as expected.

With Particle.process(), the Photon doesn’t reset which is perplexing since that should not reset the watchdog.

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [May 5, 2017, 4:03am UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/6 "2017-05-05T04:03:02Z")

</div>

I use the Watchdog in some Electron testing I have been doing and I planned on adding it to some code I’m using to test the RFM95 radio modules.

What exactly have you figured out here?

I’m a little confused and just want to know conditions trigger the watchdog to not work.

Is this only with the new 6.2 firmware?

I don’t want to rely on something that is not working when I just expect it to do it’s job.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [May 5, 2017, 5:42am UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/7 "2017-05-05T05:42:31Z")

</div>

> [@peekay123](#):
>
> Particle.process() should NOT keep the watchdog going.

The docs state this tho'

> [@](#):
>
> If the application has not exited loop, or called _**`Particle.process()`**_ within the given timeout, or called ApplicationWatchdog.checkin(), the watchdog calls the given timeout function, which is typically System.reset

But it might be that the forceful nature of `SYSTEM_MODE(AUTOMATIC)` might play a role here.  
Try with `SYSTEM_MODE(SEMI_AUTOMATIC)`

BTW, I agree that the implicit `ApplicationWatchdog.checkin()` in `Particle.process()` limits the use of the watchdog as you have no control in your code whether you want to spin a loop keeping the cloud connected but still bail out if the loop takes too long.  
One proposal to overcome this would be a `void CloudClass::process(bool wdCheckin = true)` to get control whether or not you want to reset the watchdog (@rickkas7?)

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 5, 2017, 3:42pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/8 "2017-05-05T15:42:56Z")

</div>

@ScruffR, I’d missed that, partially because I didn’t expect it! An APPLICATION watchdog should only be kept alive by the application, not the system firmware. Call Particle.process() should not, in any way, update the watchdog IMO. The checkIn() call should unequivocally and explicitly be called in the used app. Should we post this as an issue?

---

<div class="post-metadata">

**Author:** ![Tahl](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tahl/32/9609_2.png) [@Tahl](https://community.particle.io/u/Tahl)\
**Post date:** [May 5, 2017, 4:11pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/9 "2017-05-05T16:11:40Z")

</div>

@peekay123 and @ScruffR,

I’m a bit confused on the Particle.process() bit. I never call Particle.process() as the equivalent functionality is performed already. Here’s what the doc says:

“Particle.process() is called automatically after every loop() and during delays. Typically you will not need to call Particle.process() unless you block in some other way and need to maintain the connection to the Cloud, or you change the system mode.”

So in order to test the watchdog, I should only have to block on something within the loop() such as with while (1) { } and the watchdog should kick in.

Btw, I SYSTEM\_MODE(SEMI\_AUTOMATIC) and SYSTEM\_THREAD(ENABLED) and running 6.2.

Assuming we can’t get this to work, any advice / suggestions on using a hardware watchdog a la SPARKINTERVALTIMER? In lieu of or in addition to?

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 5, 2017, 4:14pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/10 "2017-05-05T16:14:40Z")

</div>

@Tahl, in my test where I did NOT call `Particle.process()` in loop(), the watchdog did reset the processor. Oddly on reboot, it took 2 minutes but subsequently, it rebooted every minute.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [May 5, 2017, 4:26pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/11 "2017-05-05T16:26:23Z")

</div>

Yup, I’d also think the current behaviour is rather counterproductive.  
I could live with the implicit checkin when dropping out of `loop()` as this inevitably means the application does not block, but `Particle.process()` should definetly not or at least allow to opt-out to avoid breaking existing code.

---

<div class="post-metadata">

**Author:** ![Tahl](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tahl/32/9609_2.png) [@Tahl](https://community.particle.io/u/Tahl)\
**Post date:** [May 5, 2017, 4:29pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/12 "2017-05-05T16:29:56Z")

</div>

I got it working. I don’t call Particle.process() of course.

Suggest using hardware watchdog too (SPARKINTERVALTIMER)? Or is that overkill?

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 5, 2017, 4:43pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/13 "2017-05-05T16:43:19Z")

</div>

@Tahl, any timer based on FreeRTOS or an STM32 hardware timer is subject to hanging if code goes bad. A true external watchdog chip is the most reliable approach. However, the ApplicationWatchdog will work fine for 95% or more of cases.

---

<div class="post-metadata">

**Author:** ![joost](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/joost/32/18337_2.png) [@joost](https://community.particle.io/u/joost)\
**Post date:** [May 5, 2017, 4:49pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/14 "2017-05-05T16:49:20Z")

</div>

@peekay123 Exactly, the AppWD() function and performance is not clear and should not be kept alive by _anything_ else besides ones own code. Hence I rolled my own watchdog routines.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 5, 2017, 4:52pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/15 "2017-05-05T16:52:18Z")

</div>

@joost, can you share?

---

<div class="post-metadata">

**Author:** ![joost](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/joost/32/18337_2.png) [@joost](https://community.particle.io/u/joost)\
**Post date:** [May 5, 2017, 5:02pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/16 "2017-05-05T17:02:23Z")

</div>

As said above also, .checkin() is implicitly called in particle.process() this should:  
a) not happen  
b) be documented

There is a lot of little stuff like this throughout the particle platform that cause much pain and gnashing of teeth. The WD issues I ran into not too long ago since I have problems with the WiFi (as to others). Resetting the unit is needed under certain circumstances, one is if ones code has gone amok. I banged my had on the WD not understanding why it never got triggered when I created a problem scenario…

frustrating stuff

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [May 5, 2017, 5:28pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/17 "2017-05-05T17:28:46Z")

</div>

> [@joost](#):
>
> b) be documented

It is as stated above.

---

<div class="post-metadata">

**Author:** ![ftideman](https://avatars.discourse-cdn.com/v4/letter/f/b38774/32.png) [@ftideman](https://community.particle.io/u/ftideman)\
**Post date:** [May 16, 2017, 3:02pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/18 "2017-05-16T15:02:24Z")

</div>

I’d be very interested looking at your implementetions @joost ! I’m currently running an application WD but as I’m experiencing complete bricks (complete freeze of the system, status LED goes solid green/cyan/off) the WD aren’t able to catch this. I’m thinking using a hardware WD (based on the independent STM32 watchdog I guess?) _should_ catch a complete brick like that, right?

I’m looking into using @peekay123’s SparkTimerIntervall for this purpose. Because as far as I understand it, if based on the STM32 independent WD, should then be able to catch a complete brick of the system?

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [May 16, 2017, 3:13pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/19 "2017-05-16T15:13:36Z")

</div>

@ftideman, SparkIntervalTimer uses timer hardware interrupts, not. The STM32 watchdog which I believe is disabled due to FreeRTOS.

---

<div class="post-metadata">

**Author:** ![ftideman](https://avatars.discourse-cdn.com/v4/letter/f/b38774/32.png) [@ftideman](https://community.particle.io/u/ftideman)\
**Post date:** [May 16, 2017, 3:20pm UTC](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403/20 "2017-05-16T15:20:55Z")

</div>

Ah, so there’s no way of exposing / getting access to the STM32’s watchdog?

I’m still not sure how a WD implementation based on hardware timers, and the application watchdog, differs. Will the former be able to run even though you get a complete brick (RTOS crash?)?

[Next page](https://community.particle.io/t/im-trying-to-test-the-application-watchdog/32403.md?page=2)
