Serious connection problems with Electron

Hi,
I am testing connection with electron but witnessing a very strange behavior. With my test using AT commands to check connection I am seeing the following

  1. Connections only once in a while
  2. I must put Cellular.connect() in loop() to at least get any connection. If this function is not put in loop(), I don’t get any connection at all. If I call connect() only in setup(), nothing works. Really strange!
    With the current behavior it’s impossible to use the module for what we are planning to do. Has anyone noticed this behavior before? Below is the code and the output I get.
#include "AssetTracker.h"

//SYSTEM_MODE(MANUAL) //SEMI_AUTOMATIC
SYSTEM_THREAD(ENABLED)

String gAtResponse;

int callbackAT(int type, const char* buf, int len, char* param)
{
	gAtResponse = buf;
	gAtResponse[len]='\0';
	Serial.println("Length: " + (String) len+ " Buff:"+gAtResponse);

	return WAIT;
}

int bOnce = 0;

void setup()
{
    Cellular.on();
    Particle.connect();
   Serial.begin(9600);
}

int cnt = 0;

void loop()
{
	//Without constantly calling connect() here nothing works
	while (true) {
		if (Cellular.ready()) {
			Serial.printlnf("There is connection: %d", cnt);
			break;
		}
		Serial.printlnf("Not connected: %d", cnt);

       Cellular.connect();
       delay(1000);
        cnt++;
        if (cnt > 1000)
            cnt = 0;
	}

	char response[32] = "";
	int err = 0;
	err = Cellular.command(callbackAT, response, 10000, "AT+CIFSR\r\n");
	if (err == RESP_OK)
		Serial.printlnf("Wireless OK: "+gAtResponse);
	else
		Serial.println("Wireless fails :"+gAtResponse);

	err = Cellular.command(callbackAT, response, 10000, "AT+CIPSTATUS\r\n"); //IP STATUS
	if (err == RESP_OK)
	    Serial.println("Yeah we have an IP address: "+gAtResponse);
	else
	    Serial.println("No IP address: "+gAtResponse);
}

Output:

Length: 23 Buff: +CME ERROR: unknown    
         
No IP address:   +CME ERROR: unknown            
 
There is connection: 10                       
Length: 26 Buff: +UDNSRN: "54.89.10.58" 
 
Length: 26 Buff: +UDNSRN: "54.89.10.58"               
       
Length: 26 Buff: +UDNSRN: "54.89.10.58"                 
      
Length: 13 Buff: +USOCR: 0                  
         
Length: 37 Buff: +CME ERROR: operation not allowed               
  
Wireless fails : +CME ERROR: operation not allowed               

Yeah we have an IP address: OK

Not connected: 10
Not connected: 11
...
Not connected: 27
Not connected: 28

Wireless OK:  OK              
 
Yeah we have an IP address: OK

I guess you have to understand how SYSTEM_THREAD(ENABLED) works before you jump to conclusions.

For example, if you put your while() containing the call Cellular.connect() up into setup() I’d assume you’ll see it working too.

Or just add a waitUntil(Cellular.ready) as last line in setup() and remove that while() block and see.

I would suggest getting it working first with SYSTEM_THREAD() disabled, and SYSTEM_MODE(AUTOMATIC)… You won’t need Particle.connect() or Cellular.on() or Cellular.connect() at all. You can still use Cellular.ready() and also Cellular.localIP() https://docs.particle.io/reference/firmware/electron/#localip- for the IP address. However this IP is private, not public… so only really good for knowing you in fact do have an IP address, which means you have a PDP context and can communicate over the internet.

Something I’m wondering about… where did you get the CIFSR and CIPSTATUS commands from? I don’t see those listed in the latest AT command manual: https://www.u-blox.com/sites/default/files/u-blox-ATCommands_Manual_(UBX-13002752).pdf

The commnand “AT+CIFSR” is what I have been using to check is a module has an IP Address attached to it. I have not seen that in the recent link you sent. Perhaps it’s now absolute.
The reason why I use SYSTEM_THREAD(ENABLED) is because I was not getting any output to hyperterminal and when I inserted it in the code, I started getting output generated with Serial.print(). The output helped me and I didn’t check and further implication of using it. I have taken it out and things seem to look pretty fine.
The only issue I am having is that all my Serial.println() now do not print anything when I open hyperterminal.
Is this a known issue. The code is just as before with Cellular.on(), Cellular.connect() removed.

Thanks

Here is a sample code that doesn’t work anyway

#include "AssetTracker.h"

SYSTEM_MODE(AUTOMATIC) //SEMI_AUTOMATIC
//SYSTEM_THREAD(ENABLED)

AssetTracker t = AssetTracker()
String gAtResponse;

int callbackAT(int type, const char* buf, int len, char* param)
{
	gAtResponse = buf;
	gAtResponse[len]='\0';
	Serial.println("Length: " + (String) len+ " Buff:"+gAtResponse);
	return WAIT;
}


void setup()
{
       t.begin();

	t.gpsOn();
	pinMode(D7, OUTPUT);
	Serial.begin(9600);
}

void loop()
{
       t.updateGPS();
       Serial.println("NMEA:");
       Serial.println(t.preNMEA()); //Never print any output even when I have a fix

       Serial.println("IMEI READ:");
	err = Cellular.command(callbackAT, response, 10000, "AT+CGSN\r\n");
	if (err == RESP_OK)
	   Serial.println(gAtResponse);
	//Light up D7 LED
        digitalWrite(D7, HIGH);
        delay(1000);
	 //Switch off LED
	 digitalWrite(D7, LOW);
	 delay(500);
     
    //Check IP address
	Serial.print("IP Address: ");
	Serial.println(Cellular.localIP());
}


Observations:

  1. Without SYSTEM_THREAD(ENABLED), nothing is printed to hyperterminal and the LED D7 never lights up. The RGB LEDS however does blink white(indicating there is connection). Without LED D7 blinking and no output it shows the code is not even being executed.
  2. With SYSTEM_THREAD(ENABLED), I get outputs on hyperterminal, LED D7 blinks but I never get a connection i.e. RGB LED only blinks blue
  3. With SYSTEM_THREAD(ENABLED) and calling Cellular.connect() in loop(), I can get connection at time but most of the time not.
  4. I have not succeeded to print NMEA data with t.preNMEA(); evene when I have a fix
    So with this effect, I do not have any mean to see my code being executed (LED 7 on and off) and getting connections.

Blinking white is not an indication of a working connection and in AUTOMATIC mode this means no application code execution till you see breathing cyan.

Blinking blue would suggest a problem with the SIM (e.g. not inserted, bad connection, ...)

I'd try leaving your AT commands away for the test to see if they trip up the connection with treading enabled.

Are you using the Particle SIM or 3rd party?


There is a "double post" or spin-off of this thread at
Problem with using SYSTEM_THREAD on Electron?