Electron - funky state

I’ve had an issue that pops up now and then with several of my Electrons. They get into a funky state wherein it appears they are connected to the cellular network, but not connected to the Particle cloud. This had required me to visit the site to do a full power cycle (battery & VIN) in order to clear up the situation. @rickkas7 advised me to try a double-tap of MODE. After it goes into soft-power off mode, wait 10 seconds and then press RESET to get it to successfully start up. This works! The devices are running 0.6.0 or later.

@rickkas7 indicated if the above works (MODE & RESET), I could try introducing code that would put the device into SLEEP_MODE_DEEP for 10 seconds if the device finds itself in a state where Cellular.ready() is true and Particle.connect() is false. So…armed with that suggestion, I believe I can introduce the following to mitigate this problem:

int funkyStateStartTime = 0;   // timestamp when funkyState started
boolean funkyState = false;    // condition of connected to the cellular network, but not connected to the Particle cloud
int funkyStateTimeLimit = 180; // number of seconds allowed to be in funkyState prior to reset

and then in loop():

if (Cellular.read() && !Particle.connected()) {
	if(!funkyState) {
		funkyState = true;
		funkyStateStartTime = now();		
	}
	else {
		if ((now()-funkyStateStartTime)>funkyStateTimeLimit) {
		System.sleep(SLEEP_MODE_DEEP, 10);
	}	
}
else {
	funkyState = false;
}

Do I need also need to add at the top SYSTEM_THREAD(ENABLED);

I guess these are typos:

  • Cellular.read() vs. Cellular.ready()
  • now() vs. Time.now()

One other thing might throw a spanner in your logic: Particle.connected() may well return true while it’s not really true. A dummy Particle.publish(..., WITH_ACK) or Particle.publish()/subscribe() combo might help clarify the actual state.

@ScruffR, yep! Sloppy-rushed typing on my part. Sorry. Thanks for the suggestion about the publish/subscribe.

Do I need to enable system thread or can I cruise along as is?

I’m still not convinced this isn’t a Particle cloud issue, as six devices going into this mode at the very same time is just too much of a coincidence in my mind. The fact that it’s happened previously with multiple other devices further confounds me.

As always, this forum is amazing and incredibly helpful.

1 Like