How to select a preferred network operator with Electron


I’ve tested for days an Electron in a town succesfully and now after moving it in a different place it has problems connecting to the cellular network and even when connected it seems it can not send data.

I’m using a third-party SIM (thingsmobile) that works with all operators.

I’ve found that when in the town it was connected to ITAWI operator (Wind) and after moving it was connected to ITAOM (Vodafone). We know that Vodafone there has some problem even with phones, but we are pretty sure there are other carrier that works well (Wind / Tim / tre).

Question is there a way to skip the ITAOM operator?

How the cellular choose the best operator to connect with?

I found the AT+COPS=4,… command can help me choosing a preferred operator and switch back in automatic mode if fails. I still have few doubts when call it.

Hi @not103.

I’m also using the Things Mobile SIM, and the first time I’ve powered the device It took an unusual long time before connecting to the network.

I’m also having problems with the connection (specially receiving data from the Particle Cloud). Did you have problems like that? What’s your keep alive timeout configuration?

I’m using:

cellular_credentials_set("TM", "", "", NULL);
Particle.keepAlive(2 * 60);

Thank you

In system firmware 0.6.x and 0.7.0 and at least through 0.8.0-rc.3 the keep-alive setting is tricky to do properly due to a bug. You can only set the keep alive after Particle.connected() has returned true, otherwise it does not take effect.

Also, I’m pretty sure if Particle.connected() ever returns false (you’ve disconnected), you should call Particle.keepAlive() again after the connection is reestablished.

Otherwise, the setting won’t stick and will make it impossible to send data from the cloud to the device.

1 Like

I just noticed the bug report.

Does it makes sense to call keepAlive function at the execution of every loop to “solve” this? I need to execute code even if there is no connection to the cloud.

Thank you

I wouldn’t call it on every loop. I’d have a global variable flag such as:

bool hasSetKeepAlive = false;

And add this to your loop:

	if (Particle.connected()) {
		if (!hasSetKeepAlive) {
			hasSetKeepAlive = true;
	else {
		hasSetKeepAlive = false;		
1 Like

I just checked your solution, but it keeps failing (maybe it works better now).

Is there a way to verify that this is working?

Yes, add this to the top of your source file:

SerialLogHandler logHandler(LOG_LEVEL_TRACE);

and monitor the USB debug serial output. You’ll see the keep-alive ping packets go out in the log if it’s working.

I’ve sent you a message with the LOG details I’ve received. If there is no critical information, we can make it public (even though it’s really long).

It seems to be related to these lines:

0000644560 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 0
0000644651 [comm.protocol] ERROR: Event loop error 3
0000644651 [system] WARN: Communication loop error, closing cloud socket

Thank you

Hi @rickkas7, any updates about it? Did you had the time to check it?

Thank you