Photon SOS when using System.reset() from software timer (0.8.0-rc.8)

I’m trying to use a cloud function to request a photon to reboot on demand. To do this I’m using a software timer that runs 5 seconds after the cloud function is called. The timer runs System.reset().

For some reason, when using 0.8.0-rc.8 on my photon the following code will cause the photon to have an SOS and when the timer runs System.reset(). (In the attached video it looks like a Stack Overflow.)

Here is my code (simplified to cause the bug):

#include "Particle.h"

int reboot(String data);

void onTimedReset()
{
  System.reset();
}

Timer resetTimer(1000 * 5, onTimedReset, true); // one shot timer to reset the device

void setup() {
  Particle.function("reboot", reboot);
}

void loop() {

}

int reboot(String data) {
  resetTimer.start();
  return 0;
}

Here is the video:

I didn’t encounter this issue with 0.6.3, so I wonder what is going on here.

My guess is that it’s a stack size issue. There’s an issue where when using System.reset from the Application Watchdog with a stack smaller than 1536 bytes will SOS.

Software timers use a 1024 byte stack that’s probably the cause. Since you can’t change the size of the software timer stack, you’ll probably need to set a flag and reset from loop instead.

2 Likes

Using this now:

#include "Particle.h"

int reboot(String data);

bool rebootNow = false;

void setup() {
  Particle.function("reboot", reboot);
}

void loop() {

  if (rebootNow) {
    delay(1000);
    System.reset();
  }

}

int reboot(String data) {
  rebootNow = true;
  return 0;
}

Works great.

2 Likes

Though you already know this: using delay doesn’t allow the device to do anything in the meantime (safely shutting down, or finishing operations). Either Millis() timers or a flag in the software timer would allow you to have a ‘usable delay’.
If not for you, then for others who might stumble upon this :wink:

1 Like

Well, without delay the cloud function call times out. I’ll see if a good ol’ Particle.process() helps.

1 Like

… or continue to use the timer callback, as you had in round one, but use the technique from round two wrt setting a flag that is checked in loop.