LwM2M Client Sample on nRF9151 DK not connecting to public Leshan server

We've a nRF9151 DK for which we built the Nordic Semiconductor LwM2M Client sample using SDK 3.0.2 (modem firmware 2.0.2).

We followed all steps listed in https://docs.nordicsemi.com/bundle/ncs-3.0.2/page/nrf/samples/cellular/lwm2m_client/sample_description.html for connecting the LwM2M to the public Leshan server.

Unfortunately we're not connecting to Leshan.

The client has been correctly registered using urn:imei:<imeinumber> and the key (DTLS).

On the console we get: 

*** Booting nRF Connect SDK v3.0.2-89ba1294ac9b ***
*** Using Zephyr OS v4.0.99-f791c49f492c ***
[00:00:00.255,584] <inf> app_lwm2m_client: Run LWM2M client
[00:00:00.592,193] <inf> app_lwm2m_client: endpoint: urn:imei:359404230143209
[00:00:01.021,484] <inf> lwm2m_lte_notification: Registering ncell notification handler
[00:00:01.021,545] <inf> lwm2m_firmware: Image is confirmed OK
[00:00:01.021,575] <inf> app_lwm2m_client: Unlock SIM
[00:00:05.671,478] <inf> app_lwm2m_client: Connecting to network.
[00:00:05.671,508] <inf> app_lwm2m_client: This may take several minutes.
[00:00:06.937,561] <dbg> app_lwm2m_client: lwm2m_lte_reg_handler_notify: LTE NW status: 2
[00:00:07.989,898] <dbg> app_lwm2m_client: lwm2m_lte_reg_handler_notify: LTE NW status: 1
[00:00:07.990,600] <inf> app_lwm2m_client: Connected to LTE network
[00:00:07.990,600] <inf> app_lwm2m_client: Client connect to server
[00:00:07.990,783] <inf> net_lwm2m_rd_client: Start LWM2M Client: urn:imei:359404230143209
[00:00:07.991,088] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
[00:00:07.991,271] <inf> app_lwm2m_client: LwM2M is connecting to server
[00:00:08.188,507] <inf> lwm2m_security: Need to write credentials, requesting LTE and GNSS offline...
[00:00:08.233,764] <dbg> app_lwm2m_client: lwm2m_lte_reg_handler_notify: LTE NW status: 0
[00:00:08.233,917] <inf> app_lwm2m_client: LwM2M is connecting to server
[00:00:09.497,955] <inf> lwm2m_security: Requesting LTE and GNSS online
[00:10:09.537,567] <inf> lte_lc: Network connection attempt timed out
[00:10:09.539,855] <err> lwm2m_security: lte_lc_connect() failed -116
[00:10:09.539,855] <inf> lwm2m_security: Modem connection restored
[00:10:09.539,886] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-116)
[00:10:09.540,069] <err> net_lwm2m_rd_client: sm_do_network_error, retries 0
[00:10:09.540,191] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
[00:10:09.546,966] <err> net_lwm2m_message_handling: Unable to resolve address
[00:10:09.546,997] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
[00:10:09.547,180] <err> net_lwm2m_rd_client: sm_do_network_error, retries 1
[00:10:10.547,454] <err> net_lwm2m_rd_client: sm_do_network_error, retries 1
[00:10:10.547,637] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
[00:10:10.556,640] <err> net_lwm2m_message_handling: Unable to resolve address
[00:10:10.556,671] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
[00:10:10.556,884] <err> net_lwm2m_rd_client: sm_do_network_error, retries 2
[00:10:12.557,159] <err> net_lwm2m_rd_client: sm_do_network_error, retries 2
[00:10:12.557,312] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
[00:10:12.566,345] <err> net_lwm2m_message_handling: Unable to resolve address
[00:10:12.566,375] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
[00:10:12.566,558] <err> net_lwm2m_rd_client: sm_do_network_error, retries 3
[00:10:16.566,833] <err> net_lwm2m_rd_client: sm_do_network_error, retries 3
[00:10:16.566,986] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
[00:10:16.575,988] <err> net_lwm2m_message_handling: Unable to resolve address
[00:10:16.576,019] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
[00:10:16.576,202] <err> net_lwm2m_rd_client: sm_do_network_error, retries 4
[00:10:24.576,477] <err> net_lwm2m_rd_client: sm_do_network_error, retries 4
[00:10:24.576,629] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
[00:10:24.585,632] <err> net_lwm2m_message_handling: Unable to resolve address
[00:10:24.585,662] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
[00:10:24.585,845] <err> net_lwm2m_rd_client: sm_do_network_error, retries 5
[00:10:40.586,120] <err> net_lwm2m_rd_client: sm_do_network_error, retries 5
[00:10:40.586,151] <err> net_lwm2m_rd_client: Network error, max retries reached (6)
[00:10:40.586,181] <err> net_lwm2m_obj_server: No server candidate found
[00:10:40.586,212] <err> app_lwm2m_client: LwM2M engine reported a network error.
[00:10:40.586,456] <dbg> app_lwm2m_client: rd_client_event: Disconnected
[00:10:40.586,547] <inf> net_lwm2m_rd_client: Stop LWM2M Client: urn:imei:359404230143209
[00:10:40.586,547] <inf> app_lwm2m_client: LwM2M restart requested. The sample will try to re-establish network connection.
[00:10:40.595,794] <inf> app_lwm2m_client: Unlock SIM
[00:10:45.189,910] <inf> app_lwm2m_client: Connecting to network.
[00:10:45.189,941] <inf> app_lwm2m_client: This may take several minutes.
[00:10:45.454,132] <dbg> app_lwm2m_client: lwm2m_lte_reg_handler_notify: LTE NW status: 1
[00:10:45.455,444] <inf> app_lwm2m_client: Connected to LTE network
[00:10:45.455,474] <inf> app_lwm2m_client: Client connect to server
[00:10:45.455,627] <inf> net_lwm2m_rd_client: Start LWM2M Client: urn:imei:359404230143209
[00:10:45.456,390] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
[00:10:45.456,634] <inf> app_lwm2m_client: LwM2M is connecting to server
[00:10:45.938,781] <inf> net_lwm2m_engine: Connected, sock id 1
[00:10:46.016,113] <err> net_lwm2m_rd_client: Failed with code 4.3 (Forbidden).
[00:10:46.017,547] <wrn> app_lwm2m_client: Registration failure!
[00:10:46.017,791] <err> net_lwm2m_rd_client: sm_do_network_error, retries 0
[00:11:18.018,066] <err> net_lwm2m_rd_client: sm_do_network_error, retries 0
[00:11:18.018,157] <err> net_lwm2m_obj_server: No server candidate found
[00:11:18.018,157] <err> net_lwm2m_rd_client: Unable to find a valid server instance.
[00:11:18.018,280] <err> net_lwm2m_rd_client: sm_do_network_error, retries 1
[00:11:19.018,524] <err> net_lwm2m_rd_client: sm_do_network_error, retries 1
[00:11:19.018,646] <err> net_lwm2m_obj_server: No server candidate found
[00:11:19.018,646] <err> net_lwm2m_rd_client: Unable to find a valid server instance.
[00:11:19.018,798] <err> net_lwm2m_rd_client: sm_do_network_error, retries 2
[00:11:21.019,073] <err> net_lwm2m_rd_client: sm_do_network_error, retries 2
[00:11:21.019,165] <err> net_lwm2m_obj_server: No server candidate found
[00:11:21.019,165] <err> net_lwm2m_rd_client: Unable to find a valid server instance.
[00:11:21.019,287] <err> net_lwm2m_rd_client: sm_do_network_error, retries 3
[00:11:25.019,561] <err> net_lwm2m_rd_client: sm_do_network_error, retries 3
[00:11:25.019,653] <err> net_lwm2m_obj_server: No server candidate found
[00:11:25.019,653] <err> net_lwm2m_rd_client: Unable to find a valid server instance.
[00:11:25.019,775] <err> net_lwm2m_rd_client: sm_do_network_error, retries 4
[00:11:33.020,050] <err> net_lwm2m_rd_client: sm_do_network_error, retries 4
[00:11:33.020,141] <err> net_lwm2m_obj_server: No server candidate found
[00:11:33.020,141] <err> net_lwm2m_rd_client: Unable to find a valid server instance.
[00:11:33.020,263] <err> net_lwm2m_rd_client: sm_do_network_error, retries 5
[00:11:49.020,538] <err> net_lwm2m_rd_client: sm_do_network_error, retries 5
[00:11:49.020,568] <err> net_lwm2m_rd_client: Network error, max retries reached (6)
[00:11:49.020,599] <err> net_lwm2m_obj_server: No server candidate found
[00:11:49.020,629] <err> app_lwm2m_client: LwM2M engine reported a network error.
[00:11:49.020,874] <dbg> app_lwm2m_client: rd_client_event: Disconnected
[00:11:49.020,965] <inf> net_lwm2m_rd_client: Stop LWM2M Client: urn:imei:359404230143209
[00:11:49.020,965] <inf> app_lwm2m_client: LwM2M restart requested. The sample will try to re-establish network connection.
[00:11:49.359,283] <dbg> app_lwm2m_client: lwm2m_lte_reg_handler_notify: LTE NW status: 0
[00:11:49.479,003] <inf> app_lwm2m_client: Unlock SIM
[00:11:54.096,435] <inf> app_lwm2m_client: Connecting to network.
[00:11:54.096,466] <inf> app_lwm2m_client: This may take several minutes.
[00:11:54.336,608] <dbg> app_lwm2m_client: lwm2m_lte_reg_handler_notify: LTE NW status: 1
[00:11:54.337,921] <inf> app_lwm2m_client: Connected to LTE network
[00:11:54.337,951] <inf> app_lwm2m_client: Client connect to server
[00:11:54.338,134] <inf> net_lwm2m_rd_client: Start LWM2M Client: urn:imei:359404230143209
[00:11:54.338,806] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
[00:11:54.339,050] <inf> app_lwm2m_client: LwM2M is connecting to server
[00:11:55.470,581] <inf> net_lwm2m_engine: Connected, sock id 1
[00:11:55.566,619] <err> net_lwm2m_rd_client: Failed with code 4.3 (Forbidden).
[00:11:55.568,267] <wrn> app_lwm2m_client: Registration failure!
[00:11:55.568,450] <err> net_lwm2m_rd_client: sm_do_network_error, retries 0

The console output confirms we are connected to the LTE network but we never appear in Leshan.

Any suggestion ? 

Some times ago we were able without any effort to successfully connect an nRF9161 DK to the Leshan public server. With nRF9151 DK instead this doesn't seems to work.

Thanks for the support.

  • Hello again Joel, I have finally got a suggestion/solution to your issue.

    The problem is that network reconnection fails after updating the credentials, because the SIM requires a PIN code to reconnect. By default, the modem mode change callback does not handle PIN entry. To resolve this, the customer should implement a custom callback for handling modem mode that can manage entering the SIM PIN when required.

    The default callback implementation can be found from here sdk-nrf/subsys/net/lib/lwm2m_client_utils/lwm2m/lwm2m_security.c at 0ffb46b8b9ae31bfd313a49789844406f4fb1fdb · nrfconnect/sdk-nrf

    You can set your own callback function using lwm2m_init_security() sdk-nrf/samples/cellular/lwm2m_client/src/main.c at 0ffb46b8b9ae31bfd313a49789844406f4fb1fdb · nrfconnect/sdk-nrf

    Below is an example of the required changes to the sample. Please note, we're not able to test the PIN registration but based on the log from customer check_and_unlock_sim() works and the device can connect to the network.

    diff --git a/samples/cellular/lwm2m_client/src/main.c b/samples/cellular/lwm2m_client/src/main.c
    index da7d863049..b2e51301f0 100644
    --- a/samples/cellular/lwm2m_client/src/main.c
    +++ b/samples/cellular/lwm2m_client/src/main.c
    @@ -261,15 +261,53 @@ static int lwm2m_firmware_event_cb(struct lwm2m_fota_event *event)
     }
     #endif
     
    +static int lwm2m_modem_mode_cb(enum lte_lc_func_mode new_mode, void *user_data)
    +{
    +       enum lte_lc_func_mode fmode;
    +       int ret;
    +
    +       if (lte_lc_func_mode_get(&fmode)) {
    +               LOG_ERR("Failed to read modem functional mode");
    +               ret = -EFAULT;
    +               return ret;
    +       }
    +
    +       if (new_mode == LTE_LC_FUNC_MODE_NORMAL) {
    +               /* I need to use the blocking call, because in next step
    +                * LwM2M engine would create socket and call connect()
    +                */
    +
    +               check_and_unlock_sim();
    +               ret = lte_lc_connect();
    +
    +               if (ret) {
    +                       LOG_ERR("lte_lc_connect() failed %d", ret);
    +               }
    +               LOG_INF("Modem connection restored");
    +       } else {
    +               ret = lte_lc_func_mode_set(new_mode);
    +               if (ret == 0) {
    +                       LOG_DBG("Modem set to requested state %d", new_mode);
    +               }
    +       }
    +
    +       return ret;
    +}
    +
     static int lwm2m_setup(void)
     {
    +       struct modem_mode_change mmode;
    +
    +       mmode.cb = lwm2m_modem_mode_cb;
    +       mmode.user_data = NULL;
    +
            /* Save power by not updating timestamp on device object */
            lwm2m_update_device_service_period(0);
     
            /* Manufacturer dependent */
            /* use IMEI as serial number */
            lwm2m_app_init_device(imei_buf);
    -       lwm2m_init_security(&client, endpoint_name, NULL);
    +       lwm2m_init_security(&client, endpoint_name, &mmode);
     
            if (sizeof(CONFIG_APP_LWM2M_PSK) > 1) {
                    /* Write hard-coded PSK key to engine */
    
    

    Let us know how that works for you!

    Kind regards,
    Øyvind

  • Hello  ... Øyvind, many thanks for the input.. 

    Your input solved the LTE network connection issue.

    The nRF9151 LwM2M is now connecting both to the public Leshan and to our custom server ... 

    Many thanks for the support!

    Cheers, Joel

Related