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.

  • See your other ticket and the link there to an ticket from a year ago.

  • Hello, I remember well my ticket of one year ago. This was on an nRF9161 platform and the issue at that time was caused by the usage of the wrong LwM2M Sample (there are two samples: one form Zephyr and one from nrf). At that time the problem was solved by using the right sample (nRF LwM2M Sample). Keeping this in mind, on the nRF9151, I picked up the correct sample (nRF LwM2M Sample) which is now causing me the reported issue. Therefore , the previous ticket do not applies to the issue I'm experiencing.

    Regards, Joel

  • My bad, I was not that clear.

    I referred to the other ticket - DTLS PSK Handshake Failure on nRF9151 DK and that other ticket refers to an old ticket. I'm not sure, if that is related, but I think, it's worth to check, if the credentials are provided in the right way. Once the DTLS PSK issue is solved, there maybe some more issues in the lwm2m case.    

  • ok understood... I'll therefore first concentrate on the DTLS handshake issue ... 

  • In the meanwhile we switched to SDK 3.1.0. We regenerated the NRF LwM2M Client from original sample. We just added:

    #define SIM_PIN "8365"
    bool check_and_set_cfun()
    {
        char response[64];
        int ret = nrf_modem_at_cmd(response, sizeof(response), "AT+CFUN?");
        if (ret < 0) {
            LOG_ERR("Failed to send AT+CFUN? (%d)", ret);
            return false;
        }
    
        LOG_INF("CFUN response: %s", response);
    
        int cfun = -1;
        if (sscanf(response, "+CFUN: %d", &cfun) == 1) {
            if (cfun == 1) {
                LOG_INF("CFUN is %d.",cfun );
                return true;
            } else {
                LOG_INF("CFUN is %d, setting to 1...", cfun);
                ret = nrf_modem_at_printf("AT+CFUN=1");
                if (ret < 0) {
                    LOG_ERR("Failed to set CFUN (%d)", ret);
                    return false;
                }
                k_sleep(K_SECONDS(2));
                return true;
            }
        } else {
            LOG_ERR("Could not parse CFUN response.");
            return false;
        }
    }
    
    bool check_and_unlock_sim()
    {
    	check_and_set_cfun();
        char response[64];
        int ret = nrf_modem_at_cmd(response, sizeof(response), "AT+CPIN?");
        if (ret < 0) {
            LOG_ERR("Failed to send AT+CPIN? (%d)", ret);
            return false;
        }
    
        LOG_INF("Response: %s", response);
    
        if (strstr(response, "READY")) {
            LOG_INF("SIM is already unlocked.");
            return true;
        }
    
        if (strstr(response, "SIM PIN")) {
            LOG_INF("SIM requires PIN, entering...");
            ret = nrf_modem_at_printf("AT+CPIN=\"%s\"", SIM_PIN);
            if (ret < 0) {
                LOG_ERR("Failed to send PIN (%d)", ret);
                return false;
            }
    
            // Wait a bit for SIM to unlock
            k_sleep(K_SECONDS(3));
    
            // Verify again
            ret = nrf_modem_at_cmd(response, sizeof(response), "AT+CPIN?");
            if (ret >= 0 && strstr(response, "READY")) {
                LOG_INF("SIM unlocked successfully.");
                return true;
            } else {
                LOG_ERR("Failed to unlock SIM, response: %s", response);
                return false;
            }
        }
    
        LOG_WRN("Unexpected SIM state: %s", response);
        return false;
    }

    To enter the SIM PIN and set CFUN 1 when required.

    check_and_unlock_sim() is called in:

    static void modem_connect(void)
    {
    	int ret;
    	do {
    		LOG_INF("Connecting to network.");
    		LOG_INF("This may take several minutes.");
     		check_and_unlock_sim();
    		ret = lte_lc_connect();
    		if (ret < 0) {
    			LOG_WRN("Failed to establish LTE connection (%d).", ret);
    			LOG_WRN("Will retry in a minute.");
    			lte_lc_offline();
    			k_sleep(K_SECONDS(15));
    		} else {

    We're seeing now a different problem:

    *** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
    *** Using Zephyr OS v4.1.99-1612683d4010 ***
    [00:00:00.256,744] <inf> app_lwm2m_client: Run LWM2M client
    [00:00:00.525,878] <inf> nrf_modem_lib_trace: Trace thread ready
    [00:00:00.534,027] <inf> nrf_modem_lib_trace: Trace level override: 2
    [00:00:00.595,520] <inf> app_lwm2m_client: endpoint: urn:imei:359404230143217
    [00:00:01.030,944] <inf> lwm2m_lte_notification: Registering ncell notification handler
    [00:00:01.031,036] <inf> lwm2m_firmware: Image is confirmed OK
    [00:00:01.031,066] <inf> app_lwm2m_client: Connecting to network.
    [00:00:01.031,097] <inf> app_lwm2m_client: This may take several minutes.
    [00:00:01.094,238] <inf> app_lwm2m_client: CFUN response: +CFUN: 0
    OK
    
    [00:00:01.094,299] <inf> app_lwm2m_client: CFUN is 0, setting to 1...
    [00:00:03.140,533] <inf> app_lwm2m_client: Response: +CPIN: SIM PIN
    OK
    
    [00:00:03.140,563] <inf> app_lwm2m_client: SIM requires PIN, entering...
    [00:00:06.181,854] <inf> app_lwm2m_client: SIM unlocked successfully.
    [00:00:06.195,709] <inf> app_lwm2m_client: Connected to LTE network
    [00:00:06.218,414] <inf> app_lwm2m_client: Client connect to server
    [00:00:06.218,475] <inf> net_lwm2m_rd_client: Start LWM2M Client: urn:imei:359404230143217
    [00:00:06.218,566] <inf> app_lwm2m_client: LwM2M is connecting to server
    [00:00:06.218,811] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143217' with client lifetime 43200 using server object 0
    [00:00:06.723,358] <inf> lwm2m_security: Need to write credentials, requesting LTE and GNSS offline...
    [00:00:08.020,111] <inf> lwm2m_security: Requesting LTE and GNSS online
    [00:10:08.061,492] <inf> lte_lc: Network connection attempt timed out
    [00:10:08.065,734] <err> lwm2m_security: lte_lc_connect() failed -116
    [00:10:08.065,734] <inf> lwm2m_security: Modem connection restored
    [00:10:08.065,765] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-116)
    [00:10:08.065,979] <err> net_lwm2m_rd_client: sm_do_network_error, retries 0
    [00:10:08.066,162] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143217' with client lifetime 43200 using server object 0
    [00:10:08.072,998] <err> net_lwm2m_message_handling: Unable to resolve address
    [00:10:08.072,998] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
    [00:10:08.073,181] <err> net_lwm2m_rd_client: sm_do_network_error, retries 1
    [00:10:09.073,577] <err> net_lwm2m_rd_client: sm_do_network_error, retries 1
    [00:10:09.073,699] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143217' with client lifetime 43200 using server object 0
    [00:10:09.082,855] <err> net_lwm2m_message_handling: Unable to resolve address
    [00:10:09.082,855] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
    [00:10:09.083,038] <err> net_lwm2m_rd_client: sm_do_network_error, retries 2
    [00:10:11.083,374] <err> net_lwm2m_rd_client: sm_do_network_error, retries 2
    [00:10:11.083,526] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143217' with client lifetime 43200 using server object 0

    The client connects to the LTE network successfully but then lwm2m needs to write credential and switches modem into CFUN 4. After this it requests modem to return into CFUN 1 or similar but this never happens or more precisely CFUN 1 is entered but the firmware seems to not catch it (as shown in wireshark_log.pcapng).

    Any suggestion about what is the cause of this behaviour (lwm2m client project is 100% as it can be found in the samples of SDK 3.1.0 with exception of the above mentioned SIM unlock  code)?

    wireshark_lwm2m_log.pcapng

    Thanks, Joel

Related