The bit of code responsible for connectivity is pasted below. What I observe is that my Electron will briefly attempt to connect to the Particle Cloud (rapid cyan blinking) and within 2 seconds will show three red blinks, and then go back to connecting to the cellular network again (green blinking).
Any thoughts? I already tried "particle keys doctor" but the issue is persisting.
if (!Cellular.ready() && millis() - connectTime >= 8000) {
Serial.println("connecting to the cellular network");
connectTime = millis();
Cellular.connect();
}
if (Cellular.ready() && millis() - connectTime >= 8000) {
Serial.println("connecting to the Particle cloud");
connectTime = millis();
Particle.connect();
}
You should restore Tinker to the device and make sure itâs not a cloud-related issue, but Iâm pretty sure itâs that code.
You should only call Cellular.connect() or Particle.connect() once. They internally retry until connected once you start the process.
It looks like you call Cellular.connect(), then every 8 seconds you call it again. That can prevent ever connecting because when you Cellular.connect() again it restarts the process, so itâs possible that it will never complete if it takes longer than 8 seconds.
Really? I didn't know that - for some reason I always thought Cellular.connect() and Particle.connect() had to be re-called every once in a while....not sure where I got that from.
So this would be better to use?
if (!Cellular.ready() && !cellularConnect) {
Serial.println("connecting to the cellular network");
cellularConnect = true;
Cellular.connect();
}
if (Cellular.ready() && !particleConnect) {
Serial.println("connecting to the Particle Cloud");
particleConnect = true;
Particle.connect();
}
Another question: is it okay to call Cellular.connect() right after Cellular.on(), or is it advised to add a delay in to allow the modem to boot up?
Also, I experience the same problem still with this code:
if (!Cellular.ready() && !cellularConnect) {
Serial.println("connecting to the cellular network");
cellularConnect = true;
Cellular.connect();
}
if (Cellular.ready() && !particleConnect) {
Serial.println("connecting to the Particle Cloud");
particleConnect = true;
Particle.connect();
}
If SYSTEM_THREAD(ENABLED) is used, then you need to wait or use cellular_on(NULL) instead of using Cellular.on().
Itâs possible that itâs something else, as well, so make sure you try with Tinker or safe mode to make sure itâs a firmware issue before going too far.
I re-flashed Tinker which didnât fix itâŚCloud-side looks good with other devices still happily connecting. For this simcard Iâve only used up 0.4 out of 200MB this month.
If you don't intend to have some time with the cellular module on but not connected, you can omit Cellular.on() entirely since Cellular.connect() and Particle.connect() initiate all the prerequisite steps as needed.
Thanks for the suggestion, it does clear up my code a little bitâŚunfortunately I still have the same issue.
The device was working fine yesterday evening so I simply left it (itâs set to connect a few times per day). When I came back it was no longer connecting anymore. Not sure at what exact point the issues started.
I ran âparticle keys doctor [deviceID]â which didnât work. However, âparticle keys serverâ did work. Any thought on how this may have happened? The rest of my devices continued to connect fine.
Iâm interested in understanding this issue better as it came out of nowhere, and once my devices are out in the field I wonât be able to physically access them anymore to run this command if the issue emerges again.
Actually I was testing around with that device most of the day yesterday (last connection at 5.20pm). Then either at 12am or 8am, it woke up from Deep Sleep and mustâve started to experience this issue on its own.
Another possible reason could be some kind of brown-out condition which can also cause the dim blue D7 LED issue where the power condition may trigger a partial corruption of undpredictable flash areas.
The underlying cause for that is yet unknown and seems to only hit some devices and others not at all.
Itâs a 3G Electron and was connected by USB to my Desktop which was in sleep mode. I havenât come across this issue before yet, and I connect my Electrons in this manner all the time, but you think this couldâve been the cause?
Wondering if someone could help me out a bit more with this.
I started to see a pattern where whenever I cut power to one of my Electrons, thereâs a small chance this will invoke the â5 red led blinksâ issue thatâs only fixable by running âparticle keys serverâ + âparticle keys doctorâ. In a few weeks Iâm planning to have a couple dozen of these devices in remote areas and they may in fact lose power at some point (which can be restored by someone else - but that person wouldnât know how to run these commands). This is happening across several Electrons, so itâs not isolated to a single device. It has also happened several times to the same device, and even a 2-minute power outage is sufficient for this to happen.
For clarity, hereâs the code:
case CONNECT:
if (!initialized) {
Serial.println("connecting to the cellular network and Particle Cloud. Please allow up to 90 seconds.");
Particle.connect();
initialized = true;
}
if (Particle.connected()) {
Serial.println("connection established!");
Particle.syncTime();
stateTime = millis();
state = GPS;
break;
}
break;
LED blinks green, then cyan for a few seconds, then blinks red 5 times, continues to show cyan and eventually goes back to green.
Is there any way to avoid this problem? Or is the only solution ensuring that they are always powered up?
You might want to implement the Device Keys Helper written by @rickkas7 in your code. It is supposed to help you restore the device keys when the config memory gets corrupted. It sounds like what you are describing.