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

LWM2M client using bootstrap on Leshan demo server not working

modem fw v1.3.0

ncs 1.5.0 and master

I'm trying to test LWM2M bootstrapping using https://leshan.eclipseprojects.io/ but my board is failing to connect to the LWM2M server after being served the URL from the bootstrap server. The device was added to both the bootstrap server and normal server, you can search for nrf-352656106650180 to check the configuration.

Log of connecting to bootstrap server and failing to connect to LWM2M server below

uart:~$ *** Booting Zephyr OS build v2.4.99-ncs1  ***
[00:00:00.207,824] <dbg> net_lwm2m_engine.lwm2m_engine_init: LWM2M engine socket receive thread started
[00:00:00.207,885] <dbg> net_lwm2m_obj_security.security_create: Create LWM2M security instance: 0
--- 19 messages dropped ---
[00:00:00.207,946] <dbg> net_lwm2m_obj_server.server_create: Create LWM2M server instance: 0
[00:00:00.208,038] <dbg> net_lwm2m_obj_device.device_create: Create LWM2M device instance: 0
[00:00:00.208,068] <dbg> net_lwm2m_obj_conn_mon.connmon_create: Create LWM2M connectivity monitoring instance: 0
[00:00:00.208,099] <dbg> net_lwm2m_obj_firmware.firmware_create: Create LWM2M firmware instance: 0
[00:00:00.208,129] <dbg> net_lwm2m_obj_location.location_create: Create Location instance: 0
[00:00:00.208,557] <inf> app_lwm2m_client: Run LWM2M client
[00:00:00.208,831] <dbg> app_lwm2m_client.main: Set DNS to custom address 8.8.8.8
[00:00:00.209,594] <inf> app_lwm2m_client: Initializing modem.
[00:00:00.227,722] <dbg> net_ipso_onoff_switch.switch_create: Create IPSO On/Off Switch instance: 1
[00:00:00.227,752] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3342/1/5500, value:0x2002611f, len:1
[00:00:00.227,844] <dbg> net_lwm2m_engine.lwm2m_engine_create_obj_inst: path:3313/0
[00:00:00.227,874] <dbg> net_ipso_accel.accel_create: Create IPSO Accelerometer instance: 0
[00:00:00.227,966] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:3/0/13, buf:0x2002610c, buflen:4
[00:00:00.227,996] <inf> app_lwm2m_accel: accelerometer normal
[00:00:00.228,057] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5702, value:0x20026110, len:8
[00:00:00.228,088] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5703, value:0x20026110, len:8
[00:00:00.228,149] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5704, value:0x20026110, len:8
[00:00:00.228,210] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5518, value:0x200260fc, len:4
[00:00:00.228,271] <inf> app_lwm2m_firmware: Update Counter: current 0, update 0
[00:00:00.228,302] <inf> app_lwm2m_firmware: Image is not confirmed OK
[00:00:00.228,363] <inf> app_lwm2m_firmware: Marked image as OK
[00:00:00.228,576] <inf> app_lwm2m_firmware: Update Counter updated
[00:00:00.228,576] <inf> app_lwm2m_firmware: Firmware updated successfully
[00:00:00.228,607] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:5/0/5, value:0x2002610f, len:1
[00:00:02.082,427] <inf> app_lwm2m_client: Connecting to LTE network.
[00:00:02.082,458] <inf> app_lwm2m_client: This may take several minutes.
[00:00:02.082,519] <dbg> lte_lc.lte_lc_system_mode_set: Sending AT command to set system mode: AT%XSYSTEMMODE=0,1,1,0
[00:00:07.898,010] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 2,"2332","02592A20",9

[00:00:08.649,627] <dbg> lte_lc.at_handler: +CSCON notification
[00:00:10.377,044] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 5,"2332","02592A20",9,,,"11100000","00101000"

[00:00:10.377,349] <dbg> lte_lc.parse_psm_cfg: TAU: 28800 sec, active time: -1 sec

[00:00:10.377,471] <inf> app_lwm2m_client: Connected to LTE network
[00:00:10.378,997] <inf> net_lwm2m_rd_client: Start LWM2M Client: nrf-352656106650180
[00:00:10.413,330] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/0, value:0x20027277, len:1
[00:00:10.413,482] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/8, value:0x20027274, len:4
[00:00:10.413,513] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/9, value:0x20027276, len:2
[00:00:10.413,543] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/10, value:0x20027276, len:2
[00:00:10.482,849] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/2, value:0x2002726f, len:1
[00:00:11.209,991] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023c37, buflen:1
[00:00:11.210,052] <inf> net_lwm2m_rd_client: Bootstrap started with endpoint 'nrf-352656106650180' with client lifetime 0
[00:00:11.210,113] <dbg> net_lwm2m_engine.lwm2m_parse_peerinfo: Parse url: coaps://leshan.eclipseprojects.io
[00:00:13.019,439] <dbg> net_lwm2m_rd_client.sm_send_bootstrap_registration: Register ID with bootstrap server as 'ep=nrf-352656106650180'
[00:00:13.273,193] <err> net_lwm2m_engine: Unknown IP address family:0
[00:00:13.273,223] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
[00:00:13.273,254] <dbg> net_lwm2m_rd_client.do_bootstrap_reply_cb: Bootstrap callback (code:2.4)
[00:00:13.273,254] <inf> net_lwm2m_rd_client: Bootstrap registration done!
[00:00:13.273,254] <dbg> app_lwm2m_client.rd_client_event: Bootstrap registration complete
[00:00:13.273,315] <dbg> net_lwm2m_engine.lwm2m_udp_receive: reply 0x2001505c handled and removed
[00:00:13.308,135] <err> net_lwm2m_engine: Unknown IP address family:0
[00:00:13.308,135] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
[00:00:13.308,166] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
[00:00:13.308,288] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023a07, buflen:1
[00:00:13.489,135] <err> net_lwm2m_engine: Unknown IP address family:0
[00:00:13.489,166] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
[00:00:13.489,196] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
[00:00:13.961,364] <err> net_lwm2m_engine: Unknown IP address family:0
[00:00:13.961,364] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
[00:00:13.961,425] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
[00:00:14.196,350] <err> net_lwm2m_engine: Unknown IP address family:0
[00:00:14.196,350] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
[00:00:14.196,411] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
[00:00:14.196,502] <dbg> net_lwm2m_obj_security.security_create: Create LWM2M security instance: 1
[00:00:14.381,225] <err> net_lwm2m_engine: Unknown IP address family:0
[00:00:14.381,256] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
[00:00:14.381,317] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
[00:00:14.381,408] <dbg> net_lwm2m_obj_server.server_create: Create LWM2M server instance: 0
[00:00:14.560,150] <err> net_lwm2m_engine: Unknown IP address family:0
[00:00:14.560,180] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
[00:00:14.560,211] <inf> net_lwm2m_rd_client: Bootstrap data transfer done!
[00:00:15.022,857] <dbg> app_lwm2m_client.rd_client_event: Bootstrap transfer complete
[00:00:15.022,888] <dbg> app_lwm2m_client.rd_client_event: Boostrap finished, provisioning credentials.
[00:00:15.022,918] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023bef, buflen:1
[00:00:15.023,010] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/1, buf:0x20023bef, buflen:1
[00:00:15.023,040] <dbg> app_lwm2m_client.find_server_security_instance: Security instance found, 1
[00:00:15.023,101] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/2, buf:0x20023c14, buflen:1
[00:00:15.023,101] <dbg> app_lwm2m_client.provision_credentials: PSK mode, provisioning key and identity.
[00:00:15.023,223] <inf> net_lwm2m_rd_client: Stop LWM2M Client: nrf-352656106650180
[00:00:15.520,477] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 0

[00:00:15.611,511] <dbg> lte_lc.at_handler: +CSCON notification
[00:00:16.097,412] <dbg> lte_lc.lte_lc_system_mode_set: Sending AT command to set system mode: AT%XSYSTEMMODE=0,1,1,0
[00:00:17.309,997] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 2,"2332","02592A20",9

[00:00:17.769,927] <dbg> lte_lc.at_handler: +CSCON notification
[00:00:18.529,174] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 5,"2332","02592A20",9,,,"11100000","00101000"

[00:00:18.529,479] <dbg> lte_lc.parse_psm_cfg: TAU: 28800 sec, active time: -1 sec

[00:00:18.529,632] <inf> net_lwm2m_rd_client: Start LWM2M Client: nrf-352656106650180
[00:00:19.029,846] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023c37, buflen:1
[00:00:19.029,907] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/1, buf:0x20023c37, buflen:1
[00:00:19.029,968] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/10, buf:0x20023c8a, buflen:2
[00:00:19.030,029] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'nrf-352656106650180' with client lifetime 0
[00:00:19.030,090] <dbg> net_lwm2m_engine.lwm2m_parse_peerinfo: Parse url: coaps://leshan.eclipseprojects.io:5684
[00:00:47.137,634] <dbg> lte_lc.at_handler: +CSCON notification
[00:00:53.611,175] <dbg> lte_lc.at_handler: +CSCON notification
[00:01:04.027,160] <dbg> lte_lc.at_handler: +CSCON notification
[00:01:26.307,189] <dbg> lte_lc.at_handler: +CSCON notification
[00:01:36.699,218] <dbg> lte_lc.at_handler: +CSCON notification
[00:02:26.577,270] <err> net_lwm2m_engine: Cannot connect UDP (-114)
[00:02:26.583,953] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-114)
[00:02:27.084,136] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/1, buf:0x20023c37, buflen:1
[00:02:27.084,197] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/10, buf:0x20023c8a, buflen:2
[00:02:27.084,259] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'nrf-352656106650180' with client lifetime 0
[00:02:27.084,320] <dbg> net_lwm2m_engine.lwm2m_parse_peerinfo: Parse url: coaps://leshan.eclipseprojects.io:5684
[00:02:27.748,168] <dbg> lte_lc.at_handler: +CSCON notification

I have set the DNS server manually as my SIM provider doesn't server it from the network, otherwise, the example is unchanged.

If I remove the bootstrap options and connect directly to the LWM2M server, it works fine

uart:~$ *** Booting Zephyr OS build v2.4.99-ncs1  ***
[00:00:00.207,794] <dbg> net_lwm2m_engine.lwm2m_engine_init: LWM2M engine socket receive thread started
[00:00:00.207,855] <dbg> net_lwm2m_obj_security.security_create: Create LWM2M security instance: 0
--- 20 messages dropped ---
[00:00:00.207,916] <dbg> net_lwm2m_obj_server.server_create: Create LWM2M server instance: 0
[00:00:00.207,977] <dbg> net_lwm2m_obj_device.device_create: Create LWM2M device instance: 0
[00:00:00.208,038] <dbg> net_lwm2m_obj_conn_mon.connmon_create: Create LWM2M connectivity monitoring instance: 0
[00:00:00.208,038] <dbg> net_lwm2m_obj_firmware.firmware_create: Create LWM2M firmware instance: 0
[00:00:00.208,068] <dbg> net_lwm2m_obj_location.location_create: Create Location instance: 0
[00:00:00.208,496] <inf> app_lwm2m_client: Run LWM2M client
[00:00:00.208,770] <dbg> app_lwm2m_client.main: Set DNS to custom address 8.8.8.8
[00:00:00.209,533] <inf> app_lwm2m_client: Initializing modem.
[00:00:00.233,428] <dbg> net_ipso_onoff_switch.switch_create: Create IPSO On/Off Switch instance: 1
[00:00:00.233,459] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3342/1/5500, value:0x20025c27, len:1
[00:00:00.233,551] <dbg> net_lwm2m_engine.lwm2m_engine_create_obj_inst: path:3313/0
[00:00:00.233,581] <dbg> net_ipso_accel.accel_create: Create IPSO Accelerometer instance: 0
[00:00:00.233,673] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:3/0/13, buf:0x20025c14, buflen:4
[00:00:00.233,703] <inf> app_lwm2m_accel: accelerometer normal
[00:00:00.233,764] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5702, value:0x20025c18, len:8
[00:00:00.233,795] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5703, value:0x20025c18, len:8
[00:00:00.233,856] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5704, value:0x20025c18, len:8
[00:00:00.233,917] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5518, value:0x20025c04, len:4
[00:00:00.233,978] <inf> app_lwm2m_firmware: Update Counter: current 0, update 0
[00:00:00.234,008] <inf> app_lwm2m_firmware: Image is not confirmed OK
[00:00:00.234,069] <inf> app_lwm2m_firmware: Marked image as OK
[00:00:00.234,283] <inf> app_lwm2m_firmware: Update Counter updated
[00:00:00.234,283] <inf> app_lwm2m_firmware: Firmware updated successfully
[00:00:00.234,313] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:5/0/5, value:0x20025c17, len:1
[00:00:00.616,241] <inf> app_lwm2m_client: Connecting to LTE network.
[00:00:00.616,271] <inf> app_lwm2m_client: This may take several minutes.
[00:00:00.616,333] <dbg> lte_lc.lte_lc_system_mode_set: Sending AT command to set system mode: AT%XSYSTEMMODE=0,1,1,0
[00:00:03.693,847] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 2,"2332","02592A20",9

[00:00:04.460,479] <dbg> lte_lc.at_handler: +CSCON notification
[00:00:06.011,901] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 5,"2332","02592A20",9,,,"11100000","00101000"

[00:00:06.012,237] <dbg> lte_lc.parse_psm_cfg: TAU: 28800 sec, active time: -1 sec

[00:00:06.012,359] <inf> app_lwm2m_client: Connected to LTE network
[00:00:06.013,885] <inf> net_lwm2m_rd_client: Start LWM2M Client: nrf-352656106650180
[00:00:06.048,095] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/0, value:0x20026d7f, len:1
[00:00:06.048,248] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/8, value:0x20026d7c, len:4
[00:00:06.048,278] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/9, value:0x20026d7e, len:2
[00:00:06.048,309] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/10, value:0x20026d7e, len:2
[00:00:06.122,558] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/2, value:0x20026d77, len:1
[00:00:06.708,984] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023767, buflen:1
[00:00:06.709,075] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/10, buf:0x20023792, buflen:2
[00:00:06.709,106] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'nrf-352656106650180' with client lifetime 0
[00:00:06.709,167] <dbg> net_lwm2m_engine.lwm2m_parse_peerinfo: Parse url: coaps://leshan.eclipseprojects.io
[00:00:07.947,265] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:1/0/1, buf:0x20023750, buflen:4
[00:00:07.948,974] <dbg> net_lwm2m_rd_client.sm_send_registration: registration sent [23.97.187.154]
[00:00:08.199,005] <err> net_lwm2m_engine: Unknown IP address family:0
[00:00:08.199,035] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
[00:00:08.199,066] <dbg> net_lwm2m_rd_client.do_registration_reply_cb: Registration callback (code:2.1)
[00:00:08.199,066] <dbg> app_lwm2m_client.rd_client_event: Registration complete
[00:00:08.199,096] <inf> net_lwm2m_rd_client: Registration Done (EP='opfCyIbMWz')
[00:00:08.199,157] <dbg> net_lwm2m_engine.lwm2m_udp_receive: reply 0x2001505c handled and removed
[00:00:18.327,697] <dbg> lte_lc.at_handler: +CSCON notification

  • Hi, Ronan!

    Apologies for the slow response here. I cannot manage to reproduce your issue and your configuration on the server side seems correct. However, I see a lot of errors from the LWM2M_engine stating "Unknown IP address family:0". Could this be related to how you handle the DNS? If possible, please share the changes you have made to the code so that I can test.

    It could also be worth a try to do a full rebuild of the project (remove the build folder before building) and then erasing the flash on the nRF9160 (nrfjprog --eraseall) before programming the device with the application.

    Best regards,
    Carl Richard

  • Hi Carl,

    Sorry for the delay, was out for the past week. See diff attached on  v1.5.0 tag. I had issues using the overlay files so just copied the contents into prj.conf

    diff --git a/samples/nrf9160/lwm2m_client/overlay-nbiot.conf b/samples/nrf9160/lwm2m_client/overlay-nbiot.conf
    index 91a7c0277..83ffe18c7 100644
    --- a/samples/nrf9160/lwm2m_client/overlay-nbiot.conf
    +++ b/samples/nrf9160/lwm2m_client/overlay-nbiot.conf
    @@ -1,4 +1,4 @@
    -CONFIG_LTE_NETWORK_MODE_NBIOT=y
    +CONFIG_LTE_NETWORK_MODE_NBIOT_GPS=y
     CONFIG_COAP_INIT_ACK_TIMEOUT_MS=15000
     CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=90
     
    diff --git a/samples/nrf9160/lwm2m_client/prj.conf b/samples/nrf9160/lwm2m_client/prj.conf
    index 14d6a375c..21761b48b 100644
    --- a/samples/nrf9160/lwm2m_client/prj.conf
    +++ b/samples/nrf9160/lwm2m_client/prj.conf
    @@ -34,14 +34,16 @@ CONFIG_LWM2M_IPSO_TIMESTAMP_EXTENSIONS=y
     
     # DTLS settings
     CONFIG_LWM2M_DTLS_SUPPORT=y
    -CONFIG_LWM2M_PEER_PORT=5684
    +#CONFIG_LWM2M_PEER_PORT=5684
     
     # nRF9160 helper libraries
     CONFIG_MODEM_KEY_MGMT=y
     
     # Default app to debug logging
     CONFIG_LOG=y
    +#CONFIG_LOG_MODE_MINIMAL=y
     CONFIG_APP_LOG_LEVEL_DBG=y
    +CONFIG_LTE_LINK_CONTROL_LOG_LEVEL_DBG=y
     
     # Expand logging memory to avoid log_strdup() errors
     CONFIG_LOG_STRDUP_MAX_STRING=64
    @@ -51,7 +53,7 @@ CONFIG_LOG_STRDUP_BUF_COUNT=32
     CONFIG_LWM2M_SECURITY_KEY_SIZE=33
     
     # extend CoAP retry timing to 10 seconds for LTE/LTE-M
    -CONFIG_COAP_INIT_ACK_TIMEOUT_MS=10000
    +#CONFIG_COAP_INIT_ACK_TIMEOUT_MS=10000
     
     # Enable CoAP extended option length
     CONFIG_COAP_EXTENDED_OPTIONS_LEN=y
    @@ -108,4 +110,13 @@ CONFIG_ENTROPY_CC3XX=n
     CONFIG_TEST_RANDOM_GENERATOR=y
     
     # Set LwM2M Server IP address here
    -CONFIG_APP_LWM2M_SERVER=""
    +CONFIG_APP_LWM2M_SERVER="leshan.eclipseprojects.io"
    +CONFIG_LWM2M_LOG_LEVEL_DBG=y
    +#CONFIG_LWM2M_CLIENT_UTILS_LOG_LEVEL_DBG=y
    +
    +CONFIG_LTE_NETWORK_MODE_NBIOT_GPS=y
    +CONFIG_COAP_INIT_ACK_TIMEOUT_MS=15000
    +CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=90
    +
    +CONFIG_LWM2M_PEER_PORT=5784
    +CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP=y
    diff --git a/samples/nrf9160/lwm2m_client/src/main.c b/samples/nrf9160/lwm2m_client/src/main.c
    index 4cc10acc8..d09a1142b 100644
    --- a/samples/nrf9160/lwm2m_client/src/main.c
    +++ b/samples/nrf9160/lwm2m_client/src/main.c
    @@ -12,6 +12,8 @@
     #include <modem/nrf_modem_lib.h>
     #include <settings/settings.h>
     
    +#include <nrf_socket.h>
    +
     #include <logging/log.h>
     LOG_MODULE_REGISTER(app_lwm2m_client, CONFIG_APP_LOG_LEVEL);
     
    @@ -409,6 +411,19 @@ void main(void)
     
     	k_sem_init(&lwm2m_restart, 0, 1);
     
    +	struct nrf_in_addr dns;
    +    int err = nrf_inet_pton(NRF_AF_INET, "8.8.8.8", &dns);
    +    if (err != 1) {
    +        LOG_ERR("Failed to convert custom DNS address to %s, err %d", "8.8.8.8", errno);
    +        return ;
    +    }
    +    err = nrf_setdnsaddr(NRF_AF_INET, &dns);
    +    if (err) {
    +        LOG_ERR("Failed to set custom DNS address to %s, err %d", "8.8.8.8", errno);
    +        return ;
    +    }
    +    LOG_DBG("Set DNS to custom address %s", "8.8.8.8");
    +
     	ui_init(ui_evt_handler);
     
     	ret = fota_settings_init();
    

    I'm pretty sure I would've done a fresh build using "west build -p"

    Would "west flash" do the full erase?

  • Hi again, Ronan!

    Thanks for the code. I've not managed to reproduce the issue with the changes you made, so it's likely that something else is going on. However, I did get the same behavior when initially testing this. It went away after I did the following:
    - A clean build:  west build -b nrf9160dk_nrf9160ns -p -- -DOVERLAY_CONFIG="overlay-bootstrap.conf"
    - Erasing: nrfjprog --eraseall (west flash does not do a full erase)
    - Flashing: west flash

    Could you try this?


    Best regards,
    Carl Richard

  • Hi Carl,

    Sadly still no luck. I left my changes as is and ran your commands but got the same behaviour of not connecting to leshan server over port 5684 after bootstrap.

    I did notice when erasing I got a message saying "applying system reset" but the board didn't reset from looking at the serial terminal, this expected?

    : nrfjprog --eraseall 
    Erasing user available code and UICR flash areas.
    Applying system reset.

    Would it possible to share your logs running the code with my changes on v1.5.0? Just to see if I can spot any differences?

  • Sorry my mistake on the system reset, there's no logs because there's no code running.

    But I have been doing more digging, if I set up the bootstrap server as no security for the LWM2M server, it works but enabling preshared key security fails. 

    So as I already have the preshared keys and identity written to the modem, I commented out the provisioning and modem resetting section of code in the main and it worked.

    diff --git a/samples/nrf9160/lwm2m_client/src/main.c b/samples/nrf9160/lwm2m_client/src/main.c
    index 4cc10acc8..b14027698 100644
    --- a/samples/nrf9160/lwm2m_client/src/main.c
    +++ b/samples/nrf9160/lwm2m_client/src/main.c
    @@ -12,6 +12,8 @@
     #include <modem/nrf_modem_lib.h>
     #include <settings/settings.h>
     
    +#include <nrf_socket.h>
    +
     #include <logging/log.h>
     LOG_MODULE_REGISTER(app_lwm2m_client, CONFIG_APP_LOG_LEVEL);
     
    @@ -247,7 +249,7 @@ static void provision_psk(int instance)
            }
     
            lwm2m_rd_client_stop(&client, rd_client_event);
    -       lte_lc_offline();
    +       /*lte_lc_offline();
     
            ret = modem_key_mgmt_write(client.tls_tag,
                                       MODEM_KEY_MGMT_CRED_TYPE_PSK,
    @@ -266,10 +268,10 @@ static void provision_psk(int instance)
                    LOG_ERR("Error setting cred tag %d type %d: Error %d",
                            client.tls_tag, MODEM_KEY_MGMT_CRED_TYPE_IDENTITY,
                            ret);
    -       }
    +       }*/
     
     exit:
    -       lte_lc_connect();
    +       //lte_lc_connect();
            lwm2m_rd_client_start(&client, endpoint_name, false, rd_client_event);
     }
     #endif
    @@ -409,6 +411,19 @@ void main(void)
     
            k_sem_init(&lwm2m_restart, 0, 1);
     
    +       struct nrf_in_addr dns;
    +    int err = nrf_inet_pton(NRF_AF_INET, "8.8.8.8", &dns);
    +    if (err != 1) {
    +        LOG_ERR("Failed to convert custom DNS address to %s, err %d", "8.8.8.8", errno);
    +        return ;
    +    }
    +    err = nrf_setdnsaddr(NRF_AF_INET, &dns);
    +    if (err) {
    +        LOG_ERR("Failed to set custom DNS address to %s, err %d", "8.8.8.8", errno);
    +        return ;
    +    }
    +    LOG_DBG("Set DNS to custom address %s", "8.8.8.8");
    +
            ui_init(ui_evt_handler);
     
            ret = fota_settings_init();

    See working log below

    uart:~$ *** Booting Zephyr OS build v2.4.99-ncs1  ***
    [00:00:00.208,190] <dbg> net_lwm2m_engine.lwm2m_engine_init: LWM2M engine socket receive thread started
    [00:00:00.208,282] <dbg> net_lwm2m_obj_security.security_create: Create LWM2M security instance: 0
    --- 19 messages dropped ---
    [00:00:00.208,374] <dbg> net_lwm2m_obj_server.server_create: Create LWM2M server instance: 0
    [00:00:00.208,465] <dbg> net_lwm2m_obj_device.device_create: Create LWM2M device instance: 0
    [00:00:00.208,526] <dbg> net_lwm2m_obj_conn_mon.connmon_create: Create LWM2M connectivity monitoring instance: 0
    [00:00:00.208,557] <dbg> net_lwm2m_obj_firmware.firmware_create: Create LWM2M firmware instance: 0
    [00:00:00.208,587] <dbg> net_lwm2m_obj_location.location_create: Create Location instance: 0
    [00:00:00.209,045] <inf> app_lwm2m_client: Run LWM2M client
    [00:00:00.215,301] <dbg> app_lwm2m_client.main: Set DNS to custom address 8.8.8.8
    [00:00:00.216,186] <inf> app_lwm2m_client: Initializing modem.
    [00:00:00.232,482] <dbg> net_ipso_onoff_switch.switch_create: Create IPSO On/Off Switch instance: 1
    [00:00:00.232,513] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3342/1/5500, value:0x200261c7, len:1
    [00:00:00.232,604] <dbg> net_lwm2m_engine.lwm2m_engine_create_obj_inst: path:3313/0
    [00:00:00.232,696] <dbg> net_ipso_accel.accel_create: Create IPSO Accelerometer instance: 0
    [00:00:00.232,788] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:3/0/13, buf:0x200261c4, buflen:4
    [00:00:00.232,818] <inf> app_lwm2m_accel: accelerometer normal
    [00:00:00.232,879] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5702, value:0x200261bc, len:8
    [00:00:00.232,940] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5703, value:0x200261bc, len:8
    [00:00:00.233,001] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5704, value:0x200261bc, len:8
    [00:00:00.233,062] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:3313/0/5518, value:0x200261ac, len:4
    [00:00:00.233,123] <inf> app_lwm2m_firmware: Update Counter: current 0, update 0
    [00:00:00.233,154] <inf> app_lwm2m_firmware: Image is not confirmed OK
    [00:00:00.233,245] <inf> app_lwm2m_firmware: Marked image as OK
    [00:00:00.233,459] <inf> app_lwm2m_firmware: Update Counter updated
    [00:00:00.233,489] <inf> app_lwm2m_firmware: Firmware updated successfully
    [00:00:00.233,520] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:5/0/5, value:0x200261c7, len:1
    [00:00:00.604,064] <inf> app_lwm2m_client: Connecting to LTE network.
    [00:00:00.604,095] <inf> app_lwm2m_client: This may take several minutes.
    [00:00:00.604,156] <dbg> lte_lc.lte_lc_system_mode_set: Sending AT command to set system mode: AT%XSYSTEMMODE=0,1,0,0
    [00:00:08.039,276] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 2,"2332","024FDE1F",9
    
    [00:00:22.860,137] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 2,"2332","02592A20",9
    
    [00:00:23.651,397] <dbg> lte_lc.at_handler: +CSCON notification
    [00:00:25.316,833] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 5,"2332","02592A20",9,,,"11100000","00101000"
    
    [00:00:25.317,138] <dbg> lte_lc.parse_psm_cfg: TAU: 28800 sec, active time: -1 sec
    
    [00:00:25.317,260] <inf> app_lwm2m_client: Connected to LTE network
    [00:00:25.318,756] <inf> net_lwm2m_rd_client: Start LWM2M Client: nrf-352656106650180
    [00:00:25.352,508] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/0, value:0x2002731f, len:1
    [00:00:25.352,661] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/8, value:0x2002731c, len:4
    [00:00:25.352,691] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/9, value:0x2002731e, len:2
    [00:00:25.352,722] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/10, value:0x2002731e, len:2
    [00:00:25.488,464] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/2, value:0x2002731f, len:1
    [00:00:26.214,813] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023d67, buflen:1
    [00:00:26.214,874] <inf> net_lwm2m_rd_client: Bootstrap started with endpoint 'nrf-352656106650180' with client lifetime 0
    [00:00:26.214,965] <dbg> net_lwm2m_engine.lwm2m_parse_peerinfo: Parse url: coaps://leshan.eclipseprojects.io
    [00:00:26.845,916] <inf> net_lwm2m_engine: Port 5784:38934
    [00:00:27.581,451] <dbg> net_lwm2m_rd_client.sm_send_bootstrap_registration: Register ID with bootstrap server as 'ep=nrf-352656106650180'
    [00:00:27.977,966] <err> net_lwm2m_engine: Unknown IP address family:0
    [00:00:27.977,996] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
    [00:00:27.978,027] <dbg> net_lwm2m_rd_client.do_bootstrap_reply_cb: Bootstrap callback (code:2.4)
    [00:00:27.978,027] <inf> net_lwm2m_rd_client: Bootstrap registration done!
    [00:00:27.978,027] <dbg> app_lwm2m_client.rd_client_event: Bootstrap registration complete
    [00:00:27.978,088] <dbg> net_lwm2m_engine.lwm2m_udp_receive: reply 0x20015064 handled and removed
    [00:00:28.020,904] <err> net_lwm2m_engine: Unknown IP address family:0
    [00:00:28.020,935] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
    [00:00:28.020,965] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
    [00:00:28.021,057] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023c6f, buflen:1
    [00:00:28.254,913] <err> net_lwm2m_engine: Unknown IP address family:0
    [00:00:28.254,943] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
    [00:00:28.254,974] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
    [00:00:28.495,117] <err> net_lwm2m_engine: Unknown IP address family:0
    [00:00:28.495,147] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
    [00:00:28.495,208] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
    [00:00:28.846,160] <err> net_lwm2m_engine: Unknown IP address family:0
    [00:00:28.846,160] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
    [00:00:28.846,221] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
    [00:00:28.846,343] <dbg> net_lwm2m_obj_security.security_create: Create LWM2M security instance: 1
    [00:00:29.041,015] <err> net_lwm2m_engine: Unknown IP address family:0
    [00:00:29.041,046] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
    [00:00:29.041,107] <dbg> net_lwm2m_engine.handle_request: No accept option given. Assume OMA TLV.
    [00:00:29.041,198] <dbg> net_lwm2m_obj_server.server_create: Create LWM2M server instance: 0
    [00:00:29.259,948] <err> net_lwm2m_engine: Unknown IP address family:0
    [00:00:29.259,948] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
    [00:00:29.259,979] <inf> net_lwm2m_rd_client: Bootstrap data transfer done!
    [00:00:29.584,655] <dbg> app_lwm2m_client.rd_client_event: Bootstrap transfer complete
    [00:00:29.584,655] <dbg> app_lwm2m_client.rd_client_event: Boostrap finished, provisioning credentials.
    [00:00:29.584,716] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023d67, buflen:1
    [00:00:29.584,808] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/1, buf:0x20023d67, buflen:1
    [00:00:29.584,838] <dbg> app_lwm2m_client.find_server_security_instance: Security instance found, 1
    [00:00:29.584,899] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/2, buf:0x20023d83, buflen:1
    [00:00:29.584,899] <dbg> app_lwm2m_client.provision_credentials: PSK mode, provisioning key and identity.
    [00:00:29.585,021] <inf> net_lwm2m_rd_client: Stop LWM2M Client: nrf-352656106650180
    [00:00:29.585,052] <inf> net_lwm2m_rd_client: Start LWM2M Client: nrf-352656106650180
    [00:00:30.583,435] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/0/1, buf:0x20023d67, buflen:1
    [00:00:30.583,526] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/1, buf:0x20023d67, buflen:1
    [00:00:30.583,587] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:0/1/10, buf:0x20023d8a, buflen:2
    [00:00:30.583,648] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'nrf-352656106650180' with client lifetime 0
    [00:00:30.583,709] <dbg> net_lwm2m_engine.lwm2m_parse_peerinfo: Parse url: coaps://leshan.eclipseprojects.io:5684
    [00:00:30.584,350] <inf> net_lwm2m_engine: Port 5684:13334
    [00:00:31.912,658] <dbg> net_lwm2m_engine.lwm2m_engine_get: path:1/0/1, buf:0x20023d68, buflen:4
    [00:00:31.914,306] <dbg> net_lwm2m_rd_client.sm_send_registration: registration sent [23.97.187.154]
    [00:00:32.103,118] <err> net_lwm2m_engine: Unknown IP address family:0
    [00:00:32.103,149] <dbg> net_lwm2m_engine.lwm2m_udp_receive: checking for reply from [unk]
    [00:00:32.103,179] <dbg> net_lwm2m_rd_client.do_registration_reply_cb: Registration callback (code:2.1)
    [00:00:32.103,179] <dbg> app_lwm2m_client.rd_client_event: Registration complete
    [00:00:32.103,210] <inf> net_lwm2m_rd_client: Registration Done (EP='25iLO3yOrz')
    [00:00:32.103,271] <dbg> net_lwm2m_engine.lwm2m_udp_receive: reply 0x20015064 handled and removed
    [00:00:42.219,848] <dbg> lte_lc.at_handler: +CSCON notification
    [00:00:43.002,197] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 5,"2332","0255B020",9,,,"11100000","00101000"
    
    [00:00:43.002,502] <dbg> lte_lc.parse_psm_cfg: TAU: 28800 sec, active time: -1 sec
    
    [00:00:49.831,176] <dbg> lte_lc.at_handler: +CEREG notification: +CEREG: 5,"2332","02592A20",9,,,"11100000","00101000"
    
    [00:00:49.831,481] <dbg> lte_lc.parse_psm_cfg: TAU: 28800 sec, active time: -1 sec
    
    [00:02:22.265,777] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/2, value:0x2002731f, len:1
    [00:03:24.041,931] <dbg> net_lwm2m_engine.lwm2m_engine_set: path:4/0/2, value:0x2002731f, len:1
    

    Do you know why writing the certificates or resetting the modem is breaking the connection to the server?

Related