I was testing some code for turning off and on the WiFi, and got a stack overflow error with the following simple code. The SOS is shown twice, then it connects like it should. Any ideas why this is happening?
Timer fifteenSecondTimer(15000, turnOffWifi, true);
Timer resetTimer(30000, connectToCloud, true);
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
void setup() {
Serial.begin();
Time.zone(-7);
connectToCloud();
}
void loop() {}
void connectToCloud() {
if (!Particle.connected()) {
Particle.connect();
if (waitFor(Particle.connected, 60000)) {
Serial.println("starting timer");
fifteenSecondTimer.start();
}else {
System.reset();
}
}
}
void turnOffWifi() { // handler for fifteenSecondTimer
Particle.disconnect();
WiFi.off();
resetTimer.start();
}
This is on a Photon running 0.7.0