This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf9160 modem not responding after switching to offline mode

My application uses the nrf9160 in eDRX mode. I regularly have the problem, that when switching the modem to OFFLINE mode (same for POWER-OFF mode), the modem is not responding anymore to any AT commands. I need to switch to OFFLINE mode for battery saving and for switching between Cat-M1 and Cat-NB1.

I wrote a minimalistic application for the demo board (PCA10090 0.8.5, modem Firmware 1.0.0), where I can reproduce the problem.

First the modem is configured to LTE Cat-M1 mode with an eDRX intervall of 82 seconds. Then it is set so ONLINE mode. After a connection is established or a timeout of 100 seconds expires, the modem is set to OFFLINE mode. Then this sequence is repeated.

For the application to run, the AT Command Driver and Logging with synchronous processing must be configured.

Here is the application code for the demo board:

#include <zephyr.h>
#include <stdio.h>
#include <stdlib.h>
#include <uart.h>
#include <string.h>
#include <logging/log.h>
#include <at_cmd.h>

LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);

volatile int regStatus = 0;

static void modem_NotificationHandler(char* msg)
{
  LOG_DBG("%s", msg);
  if (memcmp(msg, "+CEREG:", strlen("+CEREG:")) == 0)
  {
    char* p = msg + strlen("+CEREG:");
    regStatus = strtol(p, NULL, 10);
  }
}

void main(void)
{
  const u32_t timeout = 100;
  bool connected;
  u32_t t = 0;

	LOG_DBG("application started");

  at_cmd_set_notification_handler(modem_NotificationHandler);
  at_cmd_write("AT+CEREG=3", NULL, 0, NULL);

  while (1)
  {
    regStatus = 0;
    LOG_DBG("configuring modem");
    at_cmd_write("AT%XSYSTEMMODE=1,0,0,0", NULL, 0, NULL); // LTE Cat-M1
    at_cmd_write("AT+CEDRXS=2,4,\"0101\"", NULL, 0, NULL); // 81.92 seconds
    LOG_DBG("modem configured");
    at_cmd_write("AT+CFUN=1", NULL, 0, NULL);
    LOG_DBG("connecting . . .");
    t = 0;
    connected = false;
    while (!connected && t++ < timeout)
    {
      k_sleep(1000);
      connected = regStatus == 1 || regStatus == 5;
    }
    if (connected)
    {
      LOG_DBG("connected");
      k_sleep(10000);
    }
    else
    {
      LOG_DBG("connection timed out");
    }
    LOG_DBG("setting modem to OFFLINE");
    at_cmd_write("AT+CFUN=4", NULL, 0, NULL);
    LOG_DBG("modem set to OFFLINE");
  }
}

After the second connection cycle, when setting the modem to OFFLINE mode, the modem is not responding anymore.

Here is the output:

***** Booting Zephyr OS build v1.14.99-ncs3-snapshot2-1276-g4493a423a645 *****
[00:00:00.365,661] <dbg> main.main: application started
[00:00:00.371,734] <dbg> main.main: configuring modem
[00:00:00.379,455] <dbg> main.main: modem configured
[00:00:00.415,435] <dbg> main.main: connecting . . .
[00:00:30.800,292] <dbg> main.modem_NotificationHandler: +CEREG: 2,"0328","010D2B08",7,0,0

[00:01:05.904,235] <dbg> main.modem_NotificationHandler: +CEREG: 5,"0328","010D2B08",7

[00:01:05.912,994] <dbg> main.modem_NotificationHandler: +CEDRXP: 4,"0101","0101","0000"

[00:01:06.426,910] <dbg> main.main: connected
[00:01:16.431,854] <dbg> main.main: setting modem to OFFLINE
[00:01:16.592,407] <dbg> main.modem_NotificationHandler: +CEREG: 0,"0328","010D2B08",7,0,0

[00:01:18.002,746] <dbg> main.main: modem set to OFFLINE
[00:01:18.008,575] <dbg> main.main: configuring modem
[00:01:18.022,521] <dbg> main.main: modem configured
[00:01:18.064,727] <dbg> main.main: connecting . . .
[00:01:19.749,694] <dbg> main.modem_NotificationHandler: +CEREG: 2,"0328","01158B05",7,0,0

[00:02:58.079,345] <dbg> main.main: connection timed out
[00:02:58.085,144] <dbg> main.main: setting modem to OFFLINE

Any suggestions?

  • Hey,

    Just want to check, are you closing your at sockets after each AT command. I count 9 sockets being used in that code before the modem stops responding. If I remember back to my early days with the nRF9160, that was around the maximum number of sockets that could be open.

    Are you calling the function close() or nrf_close() (depending on which library you are using for the socket commands) at the end of at_cmd_write()?

  • Hi,

    No, I'm not closing the socket. Do I have to? A socket is opened once in at_cmd_driver_init(), then it is reused as far as I can see... Btw, I am using the at_cmd driver from the nRF SDK, found in ncs\nrf\drivers\at_cmd.

  • Once the socket has been used, it should be closed. Another can be opened for the next AT command but there is only a finite number of socket resources.

    Looking over that driver, I don't see where in your code you are calling an API to open a socket that can then be reused. Unless I'm being blind (which is possible as I have just spent all day writing code so forgive me), you are just calling the API to write a command to the modem with at_cmd_write, which calls at_write and then send().

    I would question if each time you are calling at_cmd_write, if the command is opening a socket for you as it doesn't actually know what socket is avaliable.

  • I don't think I am supposed to close the socket the at_cmd driver is using, as the file descriptor common_socket_fd is a static variable in at_cmd.c and cannot be accessed globally without modification of the at_cmd driver.

    Opening of the socket is hidden in the last few lines in at_cmd.c, when configured in the project config:

    #ifdef CONFIG_AT_CMD_SYS_INIT
    SYS_INIT(at_cmd_driver_init, APPLICATION, CONFIG_AT_CMD_INIT_PRIORITY);
    #endif

  • I was also able to reproduce this behavior using the AT_HOST sample and LTE Link Monitor:

    AT+CFUN?
    +CFUN: 4
    OK
    AT+CEREG=3
    OK
    AT%XSYSTEMMODE=1,0,0,0
    OK
    AT+CEDRXS=2,4,"0101"
    OK
    AT+CFUN=1
    OK
    +CEREG: 2,"0328","01158B05",7,0,0
    +CEREG: 5,"0328","01158B05",7
    +CEDRXP: 4,"0101","0101","0000"
    AT+CFUN=4
    OK
    +CEREG: 0,"0328","01158B05",7,0,0
    AT%XSYSTEMMODE=1,0,0,0
    OK
    AT+CEDRXS=2,4,"0101"
    OK
    AT+CFUN=1
    OK
    +CEREG: 2,"0328","01158B05",7,0,0
    AT+CFUN=4
    
    LTE Link Monitor output:
    18:31:44.929    Modem port is opened
    18:35:31.702    Error: 'AT+CFUN=4' timed out
    18:36:10.630    Error: 'AT+CFUN=4' timed out
    18:55:44.775    Error: 'AT+CFUN?' timed out
    

Related