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

LTE network connection fails

Hi guys,

I am trying to connect the NRF9160-DK 0.9.0 to the LTE network with the supplied iBasis sim card.

For this purpose I have executed the following functions

bsdlib_init()
at_cmd_write(AT_SET_OFFLINE, atAns, RESPONSE_LEN, NULL)
err = lte_lc_init()
err = lte_lc_connect()

Unfortunately I could not connect to the LTE network

I receive the following error codes
err -8 for lte_lc_init()
and err -1 for lte_lc_connect()

I even tried to use the AT command AT%XSYSTEMMODE=1,0,0,0
The answer I received was at_cmd_rx 8 bytes, ERROR

In prj.conf i have the following config:
## Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
# CONFIG_NET_SOCKETS_OFFLOAD=y

## BSD library
CONFIG_BSD_LIBRARY=y

## AT host library
CONFIG_AT_HOST_LIBRARY=y
CONFIG_UART_INTERRUPT_DRIVEN=y

## LTE
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
CONFIG_LTE_NETWORK_MODE_LTE_M=y

## Modem
# CONFIG_MODEM_KEY_MGMT=y

Are there any essential settings missing for a successful network connection?

Parents
  • Hi.

    What network are you trying to connect to (which country and network operator)?
    What return codes do you get from bsdlib_init(), and at_cmd_write()?
    And what is AT_SET_OFFLINE?

    Also, a couple of notes on your code:

    The bsd library is initialized automatically unless CONFIG_BSD_LIBRARY_SYS_INIT is set to 'n'.

    The modem starts in offline mode after the device has been reset.

    The error code (-8 ENOEXEC) indicates that the LTE link control library are unable to send an AT command (or more) to the modem. If you add

    CONFIG_LOG=y and CONFIG_AT_CMD_LOG_LEVEL_DBG=y to your prj.conf, you can see what AT commands are sent to the modem, and which one of them returns an error.

    Best regards,

    Didrik

  • Hello Dirdrik

    Thanks for the reply

    Here my answers to your questions:

    What network are you trying to connect to (which country and network operator)?

    Switzerland, I didn't specify a network operator (I saw in the LTE link monitor when I connected the asset tracker example with Sunrise) (How do I select the network operator, I assumed this happens automatically)

    What return codes do you get from bsdlib_init(), and at_cmd_write()?

    Both times 0x0

    And what is AT_SET_OFFLINE?

    "AT+CFUN=4"

    The bsd library is initialized automatically unless CONFIG_BSD_LIBRARY_SYS_INIT is set to 'n'.

    Ok this means that I don't need to run bsdlib_init().

    Based on your answer, I assume that the following function calls are sufficient to connect to a network:

    err = lte_lc_init()
    
    err = lte_lc_connect()

    Is this the case?

    If yes, the only step to I need to do to connect to exchange data through TCP would be to create a socket, connect and use the send and receive functionality

      err = getaddrinfo("petstore.swagger.io", NULL, &hints, &res);
      
      fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 
    
      err = connect(fd, res->ai_addr, sizeof(struct sockaddr_in));
    
      size_t off = 0;
      int bytes = 0;
      do
      {
        bytes = send(fd, &send_buf[off], HTTP_HEAD_LEN - off, 0);
        off += bytes;
      }
      while (off < HTTP_HEAD_LEN);
    
      off = 0;
      bytes = 0;
      do
      {
        bytes = recv(fd, &recv_buf[off], RECV_BUF_SIZE - off, 0);
        off += bytes;
      }
      while (bytes != 0);

     

  • PSA said:
    How do I select the network operator, I assumed this happens automatically

     You can specify the network to connect to the +COPS AT command. However, as you say, by default it will happen automatically based on your subscription/SIM card.

     

    PSA said:
    Based on your answer, I assume that the following function calls are sufficient to connect to a network:

     Yes, that is correct. If you want to, you can further shorten it to lte_lc_init_and_connect().

     

    PSA said:
    If yes, the only step to I need to do to connect to exchange data through TCP would be to create a socket, connect and use the send and receive functionality

     Yes, that looks correct.

    Did you get any log from the at_cmd module to help you identify your problem?

  • Did you get any log from the at_cmd module to help you identify your problem?

    Yes i get the following log messsages now:

    [00:00:00.412,719] <ESC><dbg> at_cmd.at_cmd_driver_init: Common AT socket created<ESC><CR><LF>
    [00:00:00.412,750] <ESC><dbg> at_cmd.at_cmd_driver_init: Common AT socket processing thread created<ESC><CR><LF>
    [00:00:00.412,750] <ESC><dbg> at_notif.module_init: Initialization<ESC><CR><LF>
    [00:00:00.412,780] <ESC><dbg> at_cmd.at_cmd_set_notification_handler: Setting notification handler to 0x00012a25<ESC><CR><LF>
    [00:00:05.246,002] <ESC><dbg> at_cmd.at_write: Sending command AT+CFUN=4<ESC><CR><LF>
    [00:00:05.246,032] <ESC><dbg> at_cmd.socket_thread_fn: AT socket thread started<ESC><CR><LF>
    LteAtCmd_SetModemMode: ANS: <CR><LF>
    [00:00:05.246,063] <ESC><dbg> at_cmd.socket_thread_fn: Allocating memory slab for AT socket<ESC><CR><LF>
    [00:00:05.246,063] <ESC><dbg> at_cmd.socket_thread_fn: Allocation done<ESC><CR><LF>
    [00:00:05.252,258] <ESC><dbg> at_cmd.at_write: Awaiting response for AT+CFUN=4<ESC><CR><LF>
    [00:00:05.260,925] <ESC><dbg> at_cmd.socket_thread_fn: at_cmd_rx 5 bytes, OK<CR><LF>
    <ESC><CR><LF>
    [00:00:05.260,955] <ESC><dbg> at_cmd.at_write: Bytes sent: 9<ESC><CR><LF>
    [00:00:05.261,016] <ESC><dbg> at_cmd.socket_thread_fn: Allocating memory slab for AT socket<ESC><CR><LF>
    [00:00:05.261,047] <ESC><dbg> at_cmd.socket_thread_fn: Allocation done<ESC><CR><LF>
    Lte_Init<CR><LF>
    Lte_NetworkConnect: Waiting for network.. ERR: Lte_NetworkConnect: lte_lc_init, err -8<CR><LF>
    ERR: Lte_NetworkConnect: lte_lc_connect, err -1<CR><LF>
    LteHttp_Init: set modem online <CR><LF>
    LteAtCmd_SetModemMode: 1<CR><LF>
    [00:00:06.302,551] <ESC><dbg> lte_lc.lte_lc_system_mode_set: Sending AT command to set system mode: AT%XSYSTEMMODE=1,0,0,0<ESC><CR><LF>
    [00:00:06.302,581] <ESC><dbg> at_cmd.at_write: Sending command AT%XSYSTEMMODE=1,0,0,0<ESC><CR><LF>
    LteAtCmd_SetModemMode: ANS: <CR><LF>
    [00:00:06.311,218] <ESC><dbg> at_cmd.at_write: Awaiting response for AT%XSYSTEMMODE=1,0,0,0<ESC><CR><LF>
    [00:00:06.311,401] <ESC><dbg> at_cmd.socket_thread_fn: at_cmd_rx 8 bytes, ERROR<CR><LF>
    <ESC><CR><LF>

  • Hmm, for some reason, the %XSYSTEMMODE command fails.

    Do you get the same behavior if you are using the at_client sample, and are sending the following commands?

    AT+CFUN=4

    AT+CFUN?

    AT%XSYSTEMMODE=1,0,0,0

    If you do, I would appreciate a modem trace to debug further from the modem-side.

Reply Children
No Data
Related