Generally I’ve also been having similar issues, and I’ve been working on replicating it (I’m using Automatic mode).
One thing, this block of code seems like it doesn’t serve a purpose because a delay of under 1000 won’t allow the System Firmware to be called. I would recommend either explicitly calling Particle.process() instead of delay(50) or maybe just delaying 1000 if you’re expecting any state change in that loop. Otherwise it’s just a guaranteed delay of 120 seconds if you aren’t connected.
while (!Particle.connected()) {
delay(50);
Serial.println("not connected");
Serial.println(millis() - startTime);
if ((millis() - startTime) > 120000) {
Serial.println("did not connect for 120 seconds!");
Serial.println("breaking out of first while loop");
int notConnected = 1;
break;
}
}
Also, this code seems like something to look closer into. I know I’ve recently experienced issues with calling Particle.disconnect() causing the Particle.connected() to still return true, and also issues with calling Particle.connected() sometimes causing the device to infinitely attempt to reconnect. This is my post EDIT: that post is no longer relevant, though I have experienced some similar issues from some other, unknown reasons
if (!success) {
Serial.printlnf("%7d(s): publish failed: %d", (millis() - b4Publish) / 1000);
if (retries < 3) {
Particle.disconnect();
delay(3000);
Particle.connect();
Serial.print("Retry: ");
Serial.println(retries + 1);
retries++;
goto RETRY_START;
}