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.

Parents
  • 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

  • Hi Joel, sorry my answer did not get sent to you. 

    Your connection is timing out i.e. #define NRF_ETIMEDOUT 116       /**< Connection timed out */ and #define NRF_ENOENT 2            /**< No such file or directory */

    Are you able to provide the .mtrace modem trace file as well? How long did you leave the modem trace running? Does your device receive an IP address? Based on the logs, which you probably know already, it looks like there is an issue with lwm2m_modem_mode_cb in  nrf\subsys\net\lib\lwm2m_client_utils\lwm2m\lwm2m_security.c

    Kind regards,
    Øyvind

  • Hi Øyvind. The Cellular modem tells me that itinitialli connects to LETE and goes into IP mode (received it's IP).. but then when the modem is switched into CFUN 4 for provisioning and set bach into CFUN 1 after it it hangs somewhere and the console simply reports:

    *** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
    *** Using Zephyr OS v4.1.99-1612683d4010 ***
    [00:00:01.140,625] <inf> app_lwm2m_client: Run LWM2M client
    [00:00:01.409,606] <inf> nrf_modem_lib_trace: Trace thread ready
    [00:00:01.417,724] <inf> nrf_modem_lib_trace: Trace level override: 2
    [00:00:01.479,187] <inf> app_lwm2m_client: endpoint: urn:imei:359404230143209
    [00:00:01.914,886] <inf> lwm2m_lte_notification: Registering ncell notification handler
    [00:00:01.914,978] <inf> lwm2m_firmware: Image is confirmed OK
    [00:00:01.914,978] <inf> app_lwm2m_client: Connecting to network.
    [00:00:01.915,008] <inf> app_lwm2m_client: This may take several minutes.
    [00:00:01.977,935] <inf> app_lwm2m_client: CFUN response: +CFUN: 0
    OK
    
    [00:00:01.977,996] <inf> app_lwm2m_client: CFUN is 0, setting to 1...
    [00:00:04.024,780] <inf> app_lwm2m_client: Response: +CPIN: SIM PIN
    OK
    
    [00:00:04.024,841] <inf> app_lwm2m_client: SIM requires PIN, entering...
    [00:00:07.058,715] <inf> app_lwm2m_client: Connected to LTE network
    [00:00:07.058,746] <inf> app_lwm2m_client: Client connect to server
    [00:00:07.058,807] <inf> net_lwm2m_rd_client: Start LWM2M Client: urn:imei:359404230143209
    [00:00:07.059,234] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
    [00:00:07.059,478] <inf> app_lwm2m_client: LwM2M is connecting to server
    [00:00:07.203,918] <inf> lwm2m_security: Need to write credentials, requesting LTE and GNSS offline...
    [00:00:07.881,805] <inf> lwm2m_security: Requesting LTE and GNSS online
    [00:10:07.923,217] <inf> lte_lc: Network connection attempt timed out
    [00:10:07.927,368] <err> lwm2m_security: lte_lc_connect() failed -116
    [00:10:07.927,398] <inf> lwm2m_security: Modem connection restored
    [00:10:07.927,429] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-116)
    [00:10:07.927,612] <err> net_lwm2m_rd_client: sm_do_network_error, retries 0
    [00:10:07.927,764] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
    [00:10:07.934,570] <err> net_lwm2m_message_handling: Unable to resolve address
    [00:10:07.934,600] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
    [00:10:07.934,783] <err> net_lwm2m_rd_client: sm_do_network_error, retries 1
    [00:10:08.935,150] <err> net_lwm2m_rd_client: sm_do_network_error, retries 1
    [00:10:08.935,272] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
    [00:10:08.944,396] <err> net_lwm2m_message_handling: Unable to resolve address
    [00:10:08.944,396] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
    [00:10:08.944,610] <err> net_lwm2m_rd_client: sm_do_network_error, retries 2
    [00:10:10.944,946] <err> net_lwm2m_rd_client: sm_do_network_error, retries 2
    [00:10:10.945,190] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'urn:imei:359404230143209' with client lifetime 43200 using server object 0
    [00:10:10.954,254] <err> net_lwm2m_message_handling: Unable to resolve address
    [00:10:10.954,284] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-2)
    [00:10:10.954,467] <err> net_lwm2m_rd_client: sm_do_network_error, retries 3
    [00:10:14.954,833] <err> net_lwm2m_rd_client: sm_do_network_error, retries 3

    trace-2025-11-19T15-24-37.925Z.mtrace

    Wireshark_capture.pcapng

    The client code is the original one as provided in SDK 3.1.0 with exception of the SIM PIN stuff (required fro the SIM I'm using).

    After 10 minutes ow waiting to get online a timeout is triggered.

    Joel

  • Hey Joel, I forwarded your modem trace to our experts to have a look at this. Hope to have an answer by end of Tuesday. 

    Kind regards,
    Øyvind

  • 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

Reply Children
No Data
Related