Particle connection process - Modem::cancel bug if modem registration aborted

Hello,

The Particle firmware connection process has a major bug in it. (I’m running firmware version release/v0.6.2)

If you call Cellular.disconnect() and then Cellular.off() while the Electron is attempting to register to the cellular network, it breaks the Particle connection state machine.

A subsequent call to Cellular.on() will fail.

#Here is a simple test program that demonstrates this bug

#include "Particle.h"

SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);

/*=============================================>>>>>
= Function forward declarations =
===============================================>>>>>*/

// Forward declarations
void waitForSerialInput();
void printSectionBreak();
void printHeaderBreak();

void Disconnect_Particle();
void Disconnect_Cellular();
void Connect_Particle();
void Connect_Cellular();
void Turn_On_Cellular();
void Turn_Off_Cellular();

SerialLogHandler logHandler(LOG_LEVEL_ALL,  //Default logging level for non-application messages
   {
      { "app", LOG_LEVEL_ALL },             //Logging level for logs from any application .cpp file not specified below
   }
);

static Logger myLog("app.main");  //Logger object used in this "main.cpp" file

void showConnectionBug(){
   myLog.info("Demonstrating the bug in the Particle firmware:");
   Turn_On_Cellular();
   Particle.process();
   delay(10000);
   Connect_Cellular();
   Particle.process();
   delay(5000);
   myLog.warn("PREMATURE ABANDONMENT OF Cellular.connect() process will cause problems after modem power down/up:");
   Disconnect_Cellular();
   Particle.process();
   delay(5000);
   Turn_Off_Cellular();
   Particle.process();
   delay(15000);
   Turn_On_Cellular();
   Particle.process();
   delay(25000);
   Connect_Cellular();
   Particle.process();
   delay(180000);
}

/*=============================================>>>>>
= SETUP FUNCTION =
===============================================>>>>>*/

void setup() {
   Serial.begin(115200);
   //Wait for user to open the serial monitor
   waitForSerialInput();
   //Show the bug with the Particle connection process
   showConnectionBug();
}



/*=============================================>>>>>
= MAIN LOOP =
===============================================>>>>>*/


void loop() {

}


//Function that waits for user to input a character via the serial monitor
#define WAIT_FOR_SERIAL_MONITOR_TIMEOUT 10000   //Time after the Electron restarts to wait for a serial character to be entered before proceeding

void waitForSerialInput(){
   unsigned long timeStart = millis();
   while(!Serial.available()){
      if((millis() - timeStart) > WAIT_FOR_SERIAL_MONITOR_TIMEOUT){
         myLog.warn("Waiting for serial input timed out!");
         return;
      }
      myLog.warn("Waiting for serial input before proceeding");
      delay(500);
   }
   //Now we need to empty the serial buffer
   while(Serial.available()){
      /*char uselessChar = */Serial.read();
   }
   myLog.warn("Received serial input, now proceeding!");

   // while(!Serial.isConnected())
   //     Particle.process();

   myLog.info("Serial monitor open!  Now proceeding!");

}


void printSectionBreak(){
   for(int i = 0; i < 5; i++){
      for(int ii = 0; ii < 5; ii++){
         Serial.print('~');
      }
      Serial.print("\r\n");
   }
}

void printHeaderBreak(){
   for(int i = 0; i < 2; i++){
      for(int ii = 0; ii < 25; ii++){
         Serial.print('~');
      }
      Serial.print("\r\n");
   }
}

void Disconnect_Particle(){
   printHeaderBreak();
   myLog.warn("!!!!! CALLING Particle.disconnect() !!!!!");
   printHeaderBreak();
   Particle.disconnect();
}
void Connect_Particle(){
   printHeaderBreak();
   myLog.warn("!!!!! CALLING Particle.connect() !!!!!");
   printHeaderBreak();
   Particle.connect();
}

void Disconnect_Cellular(){
      printHeaderBreak();
      myLog.warn("!!!!! CALLING Cellular.disconnect() !!!!!");
      printHeaderBreak();
      Cellular.disconnect();
}

void Connect_Cellular(){
      printHeaderBreak();
      myLog.warn("!!!!! CALLING Cellular.connect() !!!!!");
      printHeaderBreak();
      Cellular.connect();
}

void Turn_On_Cellular(){
         printHeaderBreak();
         myLog.warn("!!!!! CALLING Cellular.on() !!!!!");
         printHeaderBreak();
         Cellular.on();
}

void Turn_Off_Cellular(){
         printHeaderBreak();
         printHeaderBreak();
         Cellular.off();
}

_
_
_
#Here is the debug output from running the above program:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2017.05.24 16:27:34 =~=~=~=~=~=~=~=~=~=~=~=
0000001555 [app.main] WARN: Waiting for serial input before proceeding
0000002055 [app.main] WARN: Waiting for serial input before proceeding
0000002556 [app.main] WARN: Waiting for serial input before proceeding
0000003056 [app.main] WARN: Waiting for serial input before proceeding
0000003556 [app.main] WARN: Waiting for serial input before proceeding
0000004057 [app.main] WARN: Waiting for serial input before proceeding
0000004557 [app.main] WARN: Received serial input, now proceeding!
0000004557 [app.main] INFO: Serial monitor open!  Now proceeding!
0000004558 [app.main] INFO: Demonstrating the bug in the Particle firmware:
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
0000004559 [app.main] WARN: !!!!! CALLING Cellular.on() !!!!!
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
[ ElectronSerialPipe::begin ] = = = = = = = =

[ Modem::powerOn ] = = = = = = = = = = = = = =
     4.870 AT send       4 "AT\r\n"
     4.880 AT read UNK   3 "AT\r"
     4.890 AT read OK    6 "\r\nOK\r\n"
     5.100 AT send       7 "AT E0\r\n"
     5.110 AT read UNK   6 "AT E0\r"
     5.120 AT read OK    6 "\r\nOK\r\n"
     5.120 AT send      11 "AT+CMEE=2\r\n"
     5.130 AT read OK    6 "\r\nOK\r\n"
     5.130 AT send      19 "AT+CMER=1,0,0,2,1\r\n"
     5.141 AT read OK    6 "\r\nOK\r\n"
     5.141 AT send      15 "AT+IPR=115200\r\n"
     5.151 AT read OK    6 "\r\nOK\r\n"
     5.251 AT send      10 "AT+CPIN?\r\n"
     5.261 AT read  +   16 "\r\n+CPIN: READY\r\n"
     5.271 AT read OK    6 "\r\nOK\r\n"
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
0000014560 [app.main] WARN: !!!!! CALLING Cellular.connect() !!!!!
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
0000014561 [system] INFO: Sim Ready
0000014561 [system] INFO: ARM_WLAN_WD 1

[ Modem::init ] = = = = = = = = = = = = = = =
    14.562 AT send       9 "AT+CGSN\r\n"
    14.582 AT read UNK  19 "\r\n353162076295659\r\n"
    14.592 AT read OK    6 "\r\nOK\r\n"
    14.592 AT send       9 "AT+CGMI\r\n"
    14.602 AT read UNK  10 "\r\nu-blox\r\n"
    14.612 AT read OK    6 "\r\nOK\r\n"
    14.612 AT send       9 "AT+CGMM\r\n"
    14.622 AT read UNK  13 "\r\nSARA-U260\r\n"
    14.632 AT read OK    6 "\r\nOK\r\n"
    14.632 AT send       9 "AT+CGMR\r\n"
    14.642 AT read UNK   9 "\r\n23.20\r\n"
    14.652 AT read OK    6 "\r\nOK\r\n"
    14.652 AT send       9 "AT+CCID\r\n"
    14.662 AT read  +   30 "\r\n+CCID: 8934076500002661015\r\n"
    14.673 AT read OK    6 "\r\nOK\r\n"
    14.673 AT send      11 "AT+UPSV=1\r\n"
    14.683 AT read OK    6 "\r\nOK\r\n"
    14.683 AT send      11 "AT+CMGF=1\r\n"
    14.693 AT read OK    6 "\r\nOK\r\n"
    14.693 AT send      13 "AT+CNMI=2,1\r\n"
    14.703 AT read OK    6 "\r\nOK\r\n"
    14.703 AT send       9 "AT+CIMI\r\n"
    14.713 AT read UNK  19 "\r\n214074300556497\r\n"
    14.723 AT read OK    6 "\r\nOK\r\n"

[ Modem::register ] = = = = = = = = = = = = = =
    14.723 AT send      10 "AT+CREG?\r\n"
    14.734 AT read  +   14 "\r\n+CREG: 0,0\r\n"
    14.744 AT read OK    6 "\r\nOK\r\n"
    14.744 AT send      11 "AT+CGREG?\r\n"
    14.754 AT read  +   15 "\r\n+CGREG: 0,0\r\n"
    14.764 AT read OK    6 "\r\nOK\r\n"
    14.764 AT send      12 "AT+CGREG=2\r\n"
    14.774 AT read OK    6 "\r\nOK\r\n"
    14.774 AT send      11 "AT+CREG=2\r\n"
    14.784 AT read OK    6 "\r\nOK\r\n"
    14.784 AT send      10 "AT+CREG?\r\n"
    14.794 AT read  +   14 "\r\n+CREG: 2,0\r\n"
    14.804 AT read OK    6 "\r\nOK\r\n"
    14.804 AT send      11 "AT+CGREG?\r\n"
    14.814 AT read  +   15 "\r\n+CGREG: 2,0\r\n"
    14.824 AT read OK    6 "\r\nOK\r\n"
0000019562 [app.main] WARN: PREMATURE ABANDONMENT OF Cellular.connect() process will cause problems after modem power down/up:
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
0000019564 [app.main] WARN: !!!!! CALLING Cellular.disconnect() !!!!!
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~

[ Modem::cancel ] = = = = = = = = = = = = = = =
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~

[ Modem::powerOff ] = = = = = = = = = = = = = =

[ Modem::resume ] = = = = = = = = = = = = = = =
    24.567 AT send      12 "AT+CPWROFF\r\n"
    24.568 AT read  +   12 "\r\n+CREG: 4\r\n"
    24.578 AT read  +   13 "\r\n+CGREG: 4\r\n"
    24.588 AT read  +   14 "\r\n+CIEV: 3,0\r\n"
    24.598 AT read  +   14 "\r\n+CIEV: 7,0\r\n"
    24.608 AT read  +   14 "\r\n+CIEV: 9,0\r\n"
CIEV matched: 9,0
    24.618 AT read  +   14 "\r\n+CIEV: 2,1\r\n"
    27.988 AT read OK    6 "\r\nOK\r\n"

[ Modem::cancel ] = = = = = = = = = = = = = = =
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
0000039567 [app.main] WARN: !!!!! CALLING Cellular.on() !!!!!
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~

[ Modem::powerOn ] = = = = = = = = = = = = = =

[ Modem::resume ] = = = = = = = = = = = = = = =
    39.878 AT send       4 "AT\r\n"
    41.198 AT send       4 "AT\r\n"
    42.518 AT send       4 "AT\r\n"
    42.528 AT read UNK   3 "AT\r"
    42.538 AT read OK    6 "\r\nOK\r\n"

[ Modem::cancel ] = = = = = = = = = = = = = = =
0000044638 [system] WARN: Resetting WLAN due to WLAN_WD_TO()

[ Modem::powerOff ] = = = = = = = = = = = = = =

[ Modem::resume ] = = = = = = = = = = = = = = =
    44.638 AT send      12 "AT+CPWROFF\r\n"
    44.699 AT read UNK  11 "AT+CPWROFF\r"
    44.709 AT read OK    6 "\r\nOK\r\n"

[ Modem::cancel ] = = = = = = = = = = = = = = =

[ Modem::powerOn ] = = = = = = = = = = = = = =

[ Modem::resume ] = = = = = = = = = = = = = = =
    45.119 AT send       4 "AT\r\n"
    46.439 AT send       4 "AT\r\n"
    47.759 AT send       4 "AT\r\n"
    47.769 AT read UNK   3 "AT\r"
    47.779 AT read OK    6 "\r\nOK\r\n"

[ Modem::cancel ] = = = = = = = = = = = = = = =
0000047779 [system] INFO: Sim Ready
0000047779 [system] INFO: ARM_WLAN_WD 1

[ Modem::init ] = = = = = = = = = = = = = = =
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
0000064568 [app.main] WARN: !!!!! CALLING Cellular.connect() !!!!!
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
0000077869 [system] WARN: Resetting WLAN due to WLAN_WD_TO()

[ Modem::powerOff ] = = = = = = = = = = = = = =

[ Modem::resume ] = = = = = = = = = = = = = = =
    77.870 AT send      12 "AT+CPWROFF\r\n"
    77.930 AT read UNK  11 "AT+CPWROFF\r"
    77.940 AT read OK    6 "\r\nOK\r\n"

[ Modem::cancel ] = = = = = = = = = = = = = = =

[ Modem::powerOn ] = = = = = = = = = = = = = =

[ Modem::resume ] = = = = = = = = = = = = = = =
    78.350 AT send       4 "AT\r\n"
    79.670 AT send       4 "AT\r\n"
    80.990 AT send       4 "AT\r\n"
    81.000 AT read UNK   3 "AT\r"
    81.010 AT read OK    6 "\r\nOK\r\n"

[ Modem::cancel ] = = = = = = = = = = = = = = =
0000081010 [system] INFO: Sim Ready
0000081010 [system] INFO: ARM_WLAN_WD 1

[ Modem::init ] = = = = = = = = = = = = = = =
0000111111 [system] WARN: Resetting WLAN due to WLAN_WD_TO()

[ Modem::powerOff ] = = = = = = = = = = = = = =

[ Modem::resume ] = = = = = = = = = = = = = = =
   111.112 AT send      12 "AT+CPWROFF\r\n"
   111.172 AT read UNK  11 "AT+CPWROFF\r"
   111.182 AT read OK    6 "\r\nOK\r\n"

[ Modem::cancel ] = = = = = = = = = = = = = = =

[ Modem::powerOn ] = = = = = = = = = = = = = =

[ Modem::resume ] = = = = = = = = = = = = = = =
   111.592 AT send       4 "AT\r\n"
   112.912 AT send       4 "AT\r\n"
   114.232 AT send       4 "AT\r\n"
   114.242 AT read UNK   3 "AT\r"
   114.252 AT read OK    6 "\r\nOK\r\n"

[ Modem::cancel ] = = = = = = = = = = = = = = =
0000114252 [system] INFO: Sim Ready
0000114252 [system] INFO: ARM_WLAN_WD 1

[ Modem::init ] = = = = = = = = = = = = = = =

_
_
_
As you can see, the Particle connection process gets caught in an infinite loop that goes something like:

  • [ Modem::powerOff ]

  • [ Modem::resume ]

  • [ Modem::cancel ]

  • [ Modem::powerOn ]

  • [ Modem::resume ]

  • [ Modem::cancel ]

  • [ Modem::init ]

_
_
_

This is extremely problematic for me since I need to be able to alter the radio access technology (RAT) being used by the modem if Cellular.connect() takes too long or times out.

The only way I have found to do that is to call Cellular.off(), wait, call Cellular.on(), wait, and then make my change with the AT+URAT command.

This flow works perfectly if the Electron can connect to the network, and then I disconnect, power down, change RAT, power up, and connect again.

However, if the Electron doesn’t manage to connect to a network, it appears that there is no way of powering down and powering back up the modem without encountering this bug based on my testing.

#Edit 1:

Even if I change the void showConnectionBug() function (see below) so that I am no longer turning off/turning on the modem, the premature abandonment of the Cellular.connect() process results in this same infinite loop behaviour. The subsequent call to Cellular.connect() fails.

void showConnectionBug(){
   myLog.info("Demonstrating the bug in the Particle firmware:");
   Turn_On_Cellular();
   Particle.process();
   delay(10000);
   Connect_Cellular();
   Particle.process();
   delay(5000);
   myLog.warn("PREMATURE ABANDONMENT OF Cellular.connect() process will cause problems after modem power down/up:");
   Disconnect_Cellular();
   Particle.process();
   delay(5000);
   Connect_Cellular();
   Particle.process();
   delay(180000);
}

Hi @jaza_tom

Have you tried using waitUntil(Cellular.ready); to avoid this problem?

Isn’t that the sort of thing that waitUntil was created for?

@bko

The problem is that Cellular.ready() never occurs, therefore waitUntil(Cellular.ready) would block forever.

I have a modem that I’m trying to get connected but it can’t register to the network. So I am trying to detect that when it happens and change the RAT (i.e. change from 2G to 3G or vice versa) and try to register again.

@jaza_tom, is this only a typo or have you tried waitUntil(Cellular.ready()) with the parentheses?
If so, you need to leave them off - waitUntil(Cellular.ready)

OK great, but the delay(10000) and delay(5000) are just guesses and can be wrong too. I don’t know to solve your problem but I can state for sure that you are not programming in a defensive manner that tries to avoid problems.

You should at least use waitFor(condition,timeout); For instance, the doc says that Cellular.on() can take 30-60 seconds and I don’t see how your code allows for that.

One thing I have learnt of BDub is that a Cellular.connect() is allowed to take up to 5 (five!) minutes - which makes testing such issues a pain :stuck_out_tongue_closed_eyes:

1 Like

@ScruffR @bko

Let me re-iterate the problem:

In instances where the network never registers, I need a way to abort the Particle firmware’s network registration process ( [Modem::register] process) so that I can use AT commands to force the radio access technology to a different type (i.e. from 2G to 3G).

Currently, it appears that the Particle firmware’s network registration process cannot be aborted without breaking the firmware’s modem state machines.

For your piece of mind, here is the debug logs showing the infinitely blocking waitUntil(Cellular.ready) when I modify the connection process to the following:

void showConnectionBug(){
   myLog.info("Demonstrating the bug in the Particle firmware:");
   Turn_On_Cellular();
   Particle.process();
   delay(10000);
   Connect_Cellular();
   waitUntil(Cellular.ready);
   Disconnect_Cellular();
   Particle.process();
   delay(10000);
   Connect_Cellular();
   Particle.process();
   delay(180000);

}

_
_
Debug logs:

    =~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2017.05.24 17:15:15 =~=~=~=~=~=~=~=~=~=~=~=
    0000006057 [app.main] WARN: Waiting for serial input before proceeding
    0000006557 [app.main] WARN: Waiting for serial input before proceeding
    0000007058 [app.main] WARN: Waiting for serial input before proceeding
    0000007558 [app.main] WARN: Received serial input, now proceeding!
    0000007559 [app.main] INFO: Serial monitor open!  Now proceeding!
    0000007559 [app.main] INFO: Demonstrating the bug in the Particle firmware:
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    0000007560 [app.main] WARN: !!!!! CALLING Cellular.on() !!!!!
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    [ ElectronSerialPipe::begin ] = = = = = = = =

    [ Modem::powerOn ] = = = = = = = = = = = = = =
         7.871 AT send       4 "AT\r\n"
         7.881 AT read UNK   3 "AT\r"
         7.891 AT read OK    6 "\r\nOK\r\n"
         8.101 AT send       7 "AT E0\r\n"
         8.111 AT read UNK   6 "AT E0\r"
         8.121 AT read OK    6 "\r\nOK\r\n"
         8.121 AT send      11 "AT+CMEE=2\r\n"
         8.131 AT read OK    6 "\r\nOK\r\n"
         8.131 AT send      19 "AT+CMER=1,0,0,2,1\r\n"
         8.142 AT read OK    6 "\r\nOK\r\n"
         8.142 AT send      15 "AT+IPR=115200\r\n"
         8.152 AT read OK    6 "\r\nOK\r\n"
         8.252 AT send      10 "AT+CPIN?\r\n"
         8.262 AT read  +   16 "\r\n+CPIN: READY\r\n"
         8.272 AT read OK    6 "\r\nOK\r\n"
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    0000017561 [app.main] WARN: !!!!! CALLING Cellular.connect() !!!!!
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    0000017563 [system] INFO: Sim Ready
    0000017563 [system] INFO: ARM_WLAN_WD 1

    [ Modem::init ] = = = = = = = = = = = = = = =
        17.563 AT send       9 "AT+CGSN\r\n"
        17.585 AT read UNK  19 "\r\n353162076295659\r\n"
        17.595 AT read OK    6 "\r\nOK\r\n"
        17.595 AT send       9 "AT+CGMI\r\n"
        17.605 AT read UNK  10 "\r\nu-blox\r\n"
        17.615 AT read OK    6 "\r\nOK\r\n"
        17.615 AT send       9 "AT+CGMM\r\n"
        17.625 AT read UNK  13 "\r\nSARA-U260\r\n"
        17.635 AT read OK    6 "\r\nOK\r\n"
        17.635 AT send       9 "AT+CGMR\r\n"
        17.645 AT read UNK   9 "\r\n23.20\r\n"
        17.655 AT read OK    6 "\r\nOK\r\n"
        17.655 AT send       9 "AT+CCID\r\n"
        17.665 AT read  +   30 "\r\n+CCID: 8934076500002661015\r\n"
        17.677 AT read OK    6 "\r\nOK\r\n"
        17.677 AT send      11 "AT+UPSV=1\r\n"
        17.687 AT read OK    6 "\r\nOK\r\n"
        17.687 AT send      11 "AT+CMGF=1\r\n"
        17.697 AT read OK    6 "\r\nOK\r\n"
        17.697 AT send      13 "AT+CNMI=2,1\r\n"
        17.707 AT read OK    6 "\r\nOK\r\n"
        17.707 AT send       9 "AT+CIMI\r\n"
        17.717 AT read UNK  19 "\r\n214074300556497\r\n"
        17.727 AT read OK    6 "\r\nOK\r\n"

    [ Modem::register ] = = = = = = = = = = = = = =
        17.727 AT send      10 "AT+CREG?\r\n"
        17.739 AT read  +   14 "\r\n+CREG: 0,2\r\n"
        17.749 AT read OK    6 "\r\nOK\r\n"
        17.749 AT send      11 "AT+CGREG?\r\n"
        17.759 AT read  +   15 "\r\n+CGREG: 0,2\r\n"
        17.769 AT read OK    6 "\r\nOK\r\n"
        17.769 AT send      12 "AT+CGREG=2\r\n"
        17.779 AT read OK    6 "\r\nOK\r\n"
        17.779 AT send      11 "AT+CREG=2\r\n"
        17.789 AT read OK    6 "\r\nOK\r\n"
        17.789 AT send      10 "AT+CREG?\r\n"
        17.799 AT read  +   14 "\r\n+CREG: 2,2\r\n"
        17.809 AT read OK    6 "\r\nOK\r\n"
        17.809 AT send      11 "AT+CGREG?\r\n"
        17.819 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
        17.829 AT read OK    6 "\r\nOK\r\n"
        32.829 AT send      10 "AT+CREG?\r\n"
        32.829 AT read  +   12 "\r\n+CREG: 0\r\n"
        32.841 AT read  +   13 "\r\n+CGREG: 0\r\n"
        32.851 AT read  +   12 "\r\n+CREG: 2\r\n"
        32.861 AT read  +   13 "\r\n+CGREG: 2\r\n"
        32.871 AT read  +   12 "\r\n+CREG: 0\r\n"
        32.881 AT read  +   13 "\r\n+CGREG: 0\r\n"
        34.731 AT read  +   14 "\r\n+CREG: 2,0\r\n"
        34.741 AT read OK    6 "\r\nOK\r\n"
        34.741 AT send      11 "AT+CGREG?\r\n"
        34.741 AT read  +   12 "\r\n+CREG: 2\r\n"
        34.753 AT read  +   13 "\r\n+CGREG: 2\r\n"
        34.763 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
        34.773 AT read OK    6 "\r\nOK\r\n"
        49.773 AT send      10 "AT+CREG?\r\n"
        49.773 AT read  +   12 "\r\n+CREG: 0\r\n"
        49.785 AT read  +   13 "\r\n+CGREG: 0\r\n"
        49.795 AT read  +   12 "\r\n+CREG: 2\r\n"
        49.805 AT read  +   13 "\r\n+CGREG: 2\r\n"
        49.815 AT read  +   12 "\r\n+CREG: 0\r\n"
        49.825 AT read  +   13 "\r\n+CGREG: 0\r\n"
        51.255 AT read  +   14 "\r\n+CREG: 2,0\r\n"
        51.265 AT read OK    6 "\r\nOK\r\n"
        51.265 AT send      11 "AT+CGREG?\r\n"
        51.275 AT read  +   15 "\r\n+CGREG: 2,0\r\n"
        51.285 AT read OK    6 "\r\nOK\r\n"
        66.285 AT send      10 "AT+CREG?\r\n"
        66.285 AT read  +   12 "\r\n+CREG: 2\r\n"
        66.297 AT read  +   13 "\r\n+CGREG: 2\r\n"
        68.087 AT read  +   14 "\r\n+CREG: 2,2\r\n"
        68.097 AT read OK    6 "\r\nOK\r\n"
        68.097 AT send      11 "AT+CGREG?\r\n"
        68.107 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
        68.117 AT read OK    6 "\r\nOK\r\n"
        83.117 AT send      10 "AT+CREG?\r\n"
        83.117 AT read  +   12 "\r\n+CREG: 0\r\n"
        83.129 AT read  +   13 "\r\n+CGREG: 0\r\n"
        83.139 AT read  +   12 "\r\n+CREG: 2\r\n"
        83.149 AT read  +   13 "\r\n+CGREG: 2\r\n"
        83.159 AT read  +   12 "\r\n+CREG: 0\r\n"
        83.169 AT read  +   13 "\r\n+CGREG: 0\r\n"
        84.779 AT read  +   14 "\r\n+CREG: 2,0\r\n"
        84.789 AT read OK    6 "\r\nOK\r\n"
        84.789 AT send      11 "AT+CGREG?\r\n"
        84.789 AT read  +   12 "\r\n+CREG: 2\r\n"
        84.801 AT read  +   13 "\r\n+CGREG: 2\r\n"
        84.811 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
        84.821 AT read OK    6 "\r\nOK\r\n"
        99.821 AT send      10 "AT+CREG?\r\n"
        99.821 AT read  +   12 "\r\n+CREG: 0\r\n"
        99.833 AT read  +   13 "\r\n+CGREG: 0\r\n"
        99.843 AT read  +   12 "\r\n+CREG: 2\r\n"
        99.853 AT read  +   13 "\r\n+CGREG: 2\r\n"
        99.863 AT read  +   12 "\r\n+CREG: 0\r\n"
        99.873 AT read  +   13 "\r\n+CGREG: 0\r\n"
       102.203 AT read  +   14 "\r\n+CREG: 2,0\r\n"
       102.213 AT read OK    6 "\r\nOK\r\n"
       102.213 AT send      11 "AT+CGREG?\r\n"
       102.223 AT read  +   15 "\r\n+CGREG: 2,0\r\n"
       102.233 AT read OK    6 "\r\nOK\r\n"
       117.233 AT send      10 "AT+CREG?\r\n"
       117.233 AT read  +   12 "\r\n+CREG: 2\r\n"
       117.245 AT read  +   13 "\r\n+CGREG: 2\r\n"
       117.255 AT read  +   12 "\r\n+CREG: 0\r\n"
       117.265 AT read  +   13 "\r\n+CGREG: 0\r\n"
       117.275 AT read  +   12 "\r\n+CREG: 2\r\n"
       117.285 AT read  +   13 "\r\n+CGREG: 2\r\n"
       117.295 AT read  +   12 "\r\n+CREG: 0\r\n"
       117.305 AT read  +   13 "\r\n+CGREG: 0\r\n"
       117.315 AT read  +   12 "\r\n+CREG: 2\r\n"
       117.325 AT read  +   13 "\r\n+CGREG: 2\r\n"
       117.335 AT read  +   12 "\r\n+CREG: 0\r\n"
       117.345 AT read  +   13 "\r\n+CGREG: 0\r\n"
       118.385 AT read  +   14 "\r\n+CREG: 2,0\r\n"
       118.395 AT read OK    6 "\r\nOK\r\n"
       118.395 AT send      11 "AT+CGREG?\r\n"
       118.405 AT read  +   15 "\r\n+CGREG: 2,0\r\n"
       118.415 AT read OK    6 "\r\nOK\r\n"
       133.415 AT send      10 "AT+CREG?\r\n"
       133.415 AT read  +   12 "\r\n+CREG: 2\r\n"
       133.427 AT read  +   13 "\r\n+CGREG: 2\r\n"
       133.437 AT read  +   12 "\r\n+CREG: 0\r\n"
       133.447 AT read  +   13 "\r\n+CGREG: 0\r\n"
       133.457 AT read  +   12 "\r\n+CREG: 2\r\n"
       133.467 AT read  +   13 "\r\n+CGREG: 2\r\n"
       134.987 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       134.997 AT read OK    6 "\r\nOK\r\n"
       134.997 AT send      11 "AT+CGREG?\r\n"
       135.007 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       135.017 AT read OK    6 "\r\nOK\r\n"
       150.017 AT send      10 "AT+CREG?\r\n"
       150.017 AT read  +   12 "\r\n+CREG: 0\r\n"
       150.029 AT read  +   13 "\r\n+CGREG: 0\r\n"
       150.039 AT read  +   12 "\r\n+CREG: 2\r\n"
       150.049 AT read  +   13 "\r\n+CGREG: 2\r\n"
       150.059 AT read  +   12 "\r\n+CREG: 0\r\n"
       150.069 AT read  +   13 "\r\n+CGREG: 0\r\n"
       150.079 AT read  +   12 "\r\n+CREG: 2\r\n"
       150.089 AT read  +   13 "\r\n+CGREG: 2\r\n"
       150.099 AT read  +   12 "\r\n+CREG: 0\r\n"
       150.109 AT read  +   13 "\r\n+CGREG: 0\r\n"
       151.229 AT read  +   12 "\r\n+CREG: 2\r\n"
       151.239 AT read  +   13 "\r\n+CGREG: 2\r\n"
       151.249 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       151.259 AT read OK    6 "\r\nOK\r\n"
       151.259 AT send      11 "AT+CGREG?\r\n"
       153.769 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       153.779 AT read OK    6 "\r\nOK\r\n"
       168.779 AT send      10 "AT+CREG?\r\n"
       170.579 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       170.589 AT read OK    6 "\r\nOK\r\n"
       170.589 AT send      11 "AT+CGREG?\r\n"
       170.599 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       170.609 AT read OK    6 "\r\nOK\r\n"
       185.609 AT send      10 "AT+CREG?\r\n"
       185.609 AT read  +   12 "\r\n+CREG: 0\r\n"
       185.621 AT read  +   13 "\r\n+CGREG: 0\r\n"
       185.631 AT read  +   12 "\r\n+CREG: 2\r\n"
       185.641 AT read  +   13 "\r\n+CGREG: 2\r\n"
       185.651 AT read  +   12 "\r\n+CREG: 0\r\n"
       185.661 AT read  +   13 "\r\n+CGREG: 0\r\n"
       185.671 AT read  +   12 "\r\n+CREG: 2\r\n"
       185.681 AT read  +   13 "\r\n+CGREG: 2\r\n"
       185.691 AT read  +   12 "\r\n+CREG: 0\r\n"
       185.701 AT read  +   13 "\r\n+CGREG: 0\r\n"
       187.691 AT read  +   14 "\r\n+CREG: 2,0\r\n"
       187.701 AT read OK    6 "\r\nOK\r\n"
       187.701 AT send      11 "AT+CGREG?\r\n"
       187.701 AT read  +   12 "\r\n+CREG: 2\r\n"
       187.713 AT read  +   13 "\r\n+CGREG: 2\r\n"
       187.723 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       187.733 AT read OK    6 "\r\nOK\r\n"
       202.733 AT send      10 "AT+CREG?\r\n"
       204.523 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       204.533 AT read OK    6 "\r\nOK\r\n"
       204.533 AT send      11 "AT+CGREG?\r\n"
       204.543 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       204.553 AT read OK    6 "\r\nOK\r\n"
       219.553 AT send      10 "AT+CREG?\r\n"
       220.963 AT read  +   12 "\r\n+CREG: 0\r\n"
       220.973 AT read  +   13 "\r\n+CGREG: 0\r\n"
       220.983 AT read  +   14 "\r\n+CREG: 2,0\r\n"
       220.993 AT read OK    6 "\r\nOK\r\n"
       220.993 AT send      11 "AT+CGREG?\r\n"
       223.513 AT read  +   15 "\r\n+CGREG: 2,0\r\n"
       223.523 AT read OK    6 "\r\nOK\r\n"
       238.523 AT send      10 "AT+CREG?\r\n"
       238.523 AT read  +   12 "\r\n+CREG: 2\r\n"
       238.535 AT read  +   13 "\r\n+CGREG: 2\r\n"
       238.545 AT read  +   12 "\r\n+CREG: 0\r\n"
       238.555 AT read  +   13 "\r\n+CGREG: 0\r\n"
       238.565 AT read  +   12 "\r\n+CREG: 2\r\n"
       238.575 AT read  +   13 "\r\n+CGREG: 2\r\n"
       240.325 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       240.335 AT read OK    6 "\r\nOK\r\n"
       240.335 AT send      11 "AT+CGREG?\r\n"
       240.345 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       240.355 AT read OK    6 "\r\nOK\r\n"
       255.355 AT send      10 "AT+CREG?\r\n"
       255.355 AT read  +   12 "\r\n+CREG: 0\r\n"
       255.367 AT read  +   13 "\r\n+CGREG: 0\r\n"
       257.747 AT read  +   14 "\r\n+CREG: 2,0\r\n"
       257.757 AT read OK    6 "\r\nOK\r\n"
       257.757 AT send      11 "AT+CGREG?\r\n"
       257.757 AT read  +   12 "\r\n+CREG: 2\r\n"
       257.769 AT read  +   13 "\r\n+CGREG: 2\r\n"
       257.779 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       257.789 AT read OK    6 "\r\nOK\r\n"
       272.789 AT send      10 "AT+CREG?\r\n"
       272.789 AT read  +   12 "\r\n+CREG: 0\r\n"
       272.801 AT read  +   13 "\r\n+CGREG: 0\r\n"
       272.811 AT read  +   12 "\r\n+CREG: 2\r\n"
       272.821 AT read  +   13 "\r\n+CGREG: 2\r\n"
       274.581 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       274.591 AT read OK    6 "\r\nOK\r\n"
       274.591 AT send      11 "AT+CGREG?\r\n"
       274.601 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       274.611 AT read OK    6 "\r\nOK\r\n"
       289.611 AT send      10 "AT+CREG?\r\n"
       289.611 AT read  +   12 "\r\n+CREG: 0\r\n"
       289.623 AT read  +   13 "\r\n+CGREG: 0\r\n"
       289.633 AT read  +   12 "\r\n+CREG: 2\r\n"
       289.643 AT read  +   13 "\r\n+CGREG: 2\r\n"
       292.113 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       292.123 AT read OK    6 "\r\nOK\r\n"
       292.123 AT send      11 "AT+CGREG?\r\n"
       292.133 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       292.143 AT read OK    6 "\r\nOK\r\n"
       307.143 AT send      10 "AT+CREG?\r\n"
       308.943 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       308.953 AT read OK    6 "\r\nOK\r\n"
       308.953 AT send      11 "AT+CGREG?\r\n"
       308.963 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       308.973 AT read OK    6 "\r\nOK\r\n"
       323.973 AT send      10 "AT+CREG?\r\n"
       323.973 AT read  +   12 "\r\n+CREG: 0\r\n"
       323.985 AT read  +   13 "\r\n+CGREG: 0\r\n"
       323.995 AT read  +   12 "\r\n+CREG: 2\r\n"
       324.005 AT read  +   13 "\r\n+CGREG: 2\r\n"
       325.775 AT read  +   14 "\r\n+CREG: 2,2\r\n"
       325.785 AT read OK    6 "\r\nOK\r\n"
       325.785 AT send      11 "AT+CGREG?\r\n"
       325.795 AT read  +   15 "\r\n+CGREG: 2,2\r\n"
       325.805 AT read OK    6 "\r\nOK\r\n"
    0000325805 [system] WARN: Resetting WLAN due to WLAN_WD_TO()

    [ Modem::powerOff ] = = = = = = = = = = = = = =
       325.807 AT send      12 "AT+CPWROFF\r\n"
       325.857 AT read OK    6 "\r\nOK\r\n"

    [ Modem::powerOn ] = = = = = = = = = = = = = =
       326.267 AT send       4 "AT\r\n"
       327.587 AT send       4 "AT\r\n"
       328.907 AT send       4 "AT\r\n"
       328.917 AT read UNK   3 "AT\r"
       328.927 AT read OK    6 "\r\nOK\r\n"
       329.137 AT send       7 "AT E0\r\n"
       329.147 AT read UNK   6 "AT E0\r"
       329.157 AT read OK    6 "\r\nOK\r\n"
       329.157 AT send      11 "AT+CMEE=2\r\n"
       329.167 AT read OK    6 "\r\nOK\r\n"
       329.167 AT send      19 "AT+CMER=1,0,0,2,1\r\n"
       329.179 AT read OK    6 "\r\nOK\r\n"
       329.179 AT send      15 "AT+IPR=115200\r\n"
       329.189 AT read OK    6 "\r\nOK\r\n"
       329.289 AT send      10 "AT+CPIN?\r\n"
       329.299 AT read  +   16 "\r\n+CPIN: READY\r\n"
       329.309 AT read OK    6 "\r\nOK\r\n"
    0000329309 [system] INFO: Sim Ready
    0000329309 [system] INFO: ARM_WLAN_WD 1

    [ Modem::init ] = = = = = = = = = = = = = = =
       329.311 AT send       9 "AT+CGSN\r\n"
       329.331 AT read UNK  19 "\r\n353162076295659\r\n"
       329.341 AT read OK    6 "\r\nOK\r\n"
       329.341 AT send       9 "AT+CGMI\r\n"
       329.351 AT read UNK  10 "\r\nu-blox\r\n"
       329.361 AT read OK    6 "\r\nOK\r\n"
       329.361 AT send       9 "AT+CGMM\r\n"
       329.371 AT read UNK  13 "\r\nSARA-U260\r\n"
       329.381 AT read OK    6 "\r\nOK\r\n"
       329.381 AT send       9 "AT+CGMR\r\n"
       329.391 AT read UNK   9 "\r\n23.20\r\n"
       329.401 AT read OK    6 "\r\nOK\r\n"
       329.401 AT send       9 "AT+CCID\r\n"
       329.411 AT read  +   30 "\r\n+CCID: 8934076500002661015\r\n"
       329.423 AT read OK    6 "\r\nOK\r\n"
       329.423 AT send      11 "AT+UPSV=1\r\n"
       329.433 AT read OK    6 "\r\nOK\r\n"
       329.433 AT send      11 "AT+CMGF=1\r\n"
       329.443 AT read OK    6 "\r\nOK\r\n"
       329.443 AT send      13 "AT+CNMI=2,1\r\n"
       329.453 AT read OK    6 "\r\nOK\r\n"
       329.453 AT send       9 "AT+CIMI\r\n"
       329.463 AT read UNK  19 "\r\n214074300556497\r\n"
       329.473 AT read OK    6 "\r\nOK\r\n"

    [ Modem::register ] = = = = = = = = = = = = = =
       329.473 AT send      10 "AT+CREG?\r\n"
       329.485 AT read  +   14 "\r\n+CREG: 0,0\r\n"
       329.495 AT read OK    6 "\r\nOK\r\n"
       329.495 AT send      11 "AT+CGREG?\r\n"
       329.505 AT read  +   15 "\r\n+CGREG: 0,0\r\n"
       329.515 AT read OK    6 "\r\nOK\r\n"
       329.515 AT send      12 "AT+CGREG=2\r\n"
       329.525 AT read OK    6 "\r\nOK\r\n"
       329.525 AT send      11 "AT+CREG=2\r\n"
       329.535 AT read OK    6 "\r\nOK\r\n"
       329.535 AT send      10 "AT+CREG?\r\n"
       329.545 AT read  +   14 "\r\n+CREG: 2,0\r\n"
       329.555 AT read OK    6 "\r\nOK\r\n"
       329.555 AT send      11 "AT+CGREG?\r\n"
       329.565 AT read  +   15 "\r\n+CGREG: 2,0\r\n"
       329.575 AT read OK    6 "\r\nOK\r\n"
       344.575 AT send      10 "AT+CREG?\r\n"
       344.575 AT read  +   14 "\r\n+CIEV: 5,1\r\n"
       344.587 AT read  +   12 "\r\n+CREG: 4\r\n"
       344.597 AT read  +   13 "\r\n+CGREG: 4\r\n"
       344.607 AT read  +   14 "\r\n+CIEV: 3,0\r\n"
       344.617 AT read  +   14 "\r\n+CIEV: 7,0\r\n"
       344.627 AT read  +   14 "\r\n+CIEV: 9,0\r\n"
    CIEV matched: 9,0
       346.687 AT read  +   14 "\r\n+CREG: 2,4\r\n"
       346.697 AT read OK    6 "\r\nOK\r\n"
       346.697 AT send      11 "AT+CGREG?\r\n"
       346.707 AT read  +   15 "\r\n+CGREG: 2,4\r\n"
       346.717 AT read OK    6 "\r\nOK\r\n"

_
_
_

I’ve been trying different strategies to try and not break the state machine (extremely long delay times, changing what order I call functions in, etc) for about 16 hours but haven’t come up with anything that works

I believed you when you said it would loop forever, that is why I suggested waitFor() with a much larger timeout (120 seconds at least).

I think you should try figure out what part of the public API does the thing you want to do in this unforseen use-case. I might try using threading and go into and then out of listening mode, for instance, to see if that forces the modem handling code into the kind of reset you are looking for.

Another idea would be to use a retained variable and have startup code that tries to figure out based on that variable which way it should go so you can do a System.reset() and try another way.

I am sure there is some work-around.

I don’t actually think the title of this thread is correct since you are not really obeying the API rules. It is a bug that you can get into a bad state for sure, but I think how you got there is important too.

@bko

I had a similar thought about using retained variables and using System.reset() to nuke the Particle firmware state machines. I’ll give it a try tomorrow!

The entering/exiting listening mode is a good suggestion too. I’ll try that as well and report back.

I think you’re right about the title of the thread being somewhat inaccurate because my use case is unique. I’ve taken out the “major bug” tag.

It would seem to me that this bug would be encountered by any code that turns the Cellular module off before the modem has registered to the network, which would seem to have tons of use cases matching this. For example in projects with strict power budgets the connection process may be aborted if the application determines that an internet connection it thought it needed wasn’t actually needed after all, and it wants to re-enter a sleep state.

Given that this issue hasn’t been brought up before, perhaps entering/exiting sleep state would also reset the connection state machines properly?

2 Likes

Thanks @jaza_tom for the post! I’ll loop in some folks from our embedded development team to investigate, though we’re currently a bit underwater and might not be able to take steps to validate / reproduce immediately. Thank you for the well-documented and communicated feedback.

4 Likes

#Update:

  • Using System.sleep(10) to abort the network registration process results in same bug described above.

  • Using System.sleep(D4, CHANGE, 10); to abort the network registration process results in Electron never waking from sleep with either a pin interrupt or the timer!
    This seems like a major bug!
    _
    I have started a new thread about this bug here:

#Update:

As expected, simply restartig the Electron gets the state machines back to where they should be. So that is the workaround that I will use for the time being (not ideal as my whole application has to be reset if network connectivity is lost). This means in my full application, I will need to make my startup process very quick so that the end user doesn’t notice the Electron resetting.

So the takeaway is: if you want to abort the network registration/PDP context activation process, you will need to reset the Electron before attempting to connect again.

1 Like

Did you ever find a workaround for this other than a System.reset();?

I’ve got an application that I do not want to reset for a loss of connectivity.

There have been several system revisions since. At least one of them was dealing with this issue.
Give the most recent system version (including currently most recent 0.7.0-rc.6) a try and see if you still experience issues.