LwM2M client with a B-L475E-IOT01A board (failed to setup networking)


Christos Vasilakis
 

Hello all,

I am experimenting with the LwM2M client example on a B-L475E-IOT01A board. Based on the lwm2m example that comes with Zephyr I have modified it and added code that initializes the Wi-Fi subsystem prior to the lwm2m setup. The code of the function can be found here:

https://github.com/cvasilak/zephyr-lwm2m-client/blob/master/src/lwm2m-client.c#L94-L140

It is based on some networking example snippet found around the net. I can see from the logs that the connection to the WIFI succeeds and an IP address is assigned to the board (I can ping the board from another machine) . Unfortunately, the LwM2M subsystem complains with the following error when trying to establish a connection:
..
00:00:25.263,000] <err> net_lwm2m_engine: fcntl(F_GETFL) failed (-22)
[00:00:25.296,000] <err> net_lwm2m_rd_client: Cannot init LWM2M engine ()
..

Here are the full logs:

*** Booting Zephyr OS build zephyr-v3.2.0-3154-g3c4783042eed ***
[00:00:00.546,000] <dbg> net_lwm2m_engine: lwm2m_engine_init: LWM2M engine socket receive thread started
[00:00:00.546,000] <dbg> net_lwm2m_obj_security: security_create: Create LWM2M security instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_server: server_create: Create LWM2M server instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_device: device_create: Create LWM2M device instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_firmware: firmware_create: Create LWM2M firmware instance: 0
[00:00:00.546,000] <inf> net_lwm2m_client_app: Initializing network connection...
Connected
[00:00:07.554,000] <inf> net_lwm2m_client_app: Connected to network
[00:00:07.554,000] <inf> net_lwm2m_client_app: Your address: 192.168.1.43
[00:00:07.554,000] <inf> net_lwm2m_client_app: Lease time: 0 seconds
[00:00:07.554,000] <inf> net_lwm2m_client_app: Subnet: 0.0.0.0
[00:00:07.554,000] <inf> net_lwm2m_client_app: Router: 0.0.0.0
[00:00:07.554,000] <inf> net_lwm2m_client_app: Run LWM2M client
[00:00:07.554,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:0/0/2, value:0x2000d497, len:1
[00:00:07.554,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:0/0/10, value:0x2000d496, len:2
[00:00:07.554,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:1/0/0, value:0x2000d496, len:2
[00:00:07.557,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3303/0
[00:00:07.557,000] <dbg> net_ipso_temp_sensor: temp_sensor_create: Create IPSO Temperature Sensor instance: 0
[00:00:07.557,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3311/0
[00:00:07.557,000] <dbg> net_ipso_light_control: light_control_create: Create IPSO Light Control instance: 0
[00:00:07.557,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3340/0
[00:00:07.557,000] <dbg> net_ipso_timer: timer_inst_create: Create IPSO Timer instance: 0
[00:00:07.557,000] <inf> net_lwm2m_rd_client: Start LWM2M Client: disco_l475_iot1
[00:00:07.557,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:3303/0/5700, value:0x2000d8f0, len:8
[00:00:08.547,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/1, buf:0x2000bfa7, buflen:1
[00:00:08.547,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/10, buf:0x2000bfde, buflen:2
[00:00:08.547,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:1/0/1, buf:0x2000bfb0, buflen:4
[00:00:08.548,000] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'disco_l475_iot1' with client lifetime 30
[00:00:08.548,000] <dbg> net_lwm2m_message_handling: lwm2m_parse_peerinfo: Parse url: coap://192.168.1.28
[00:00:08.649,000] <err> net_lwm2m_engine: fcntl(F_GETFL) failed (-22)
[00:00:08.679,000] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-22)
[00:00:09.679,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/1, buf:0x2000bfa7, buflen:1
[00:00:09.679,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/10, buf:0x2000bfde, buflen:2
[00:00:09.679,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:1/0/1, buf:0x2000bfb0, buflen:4
[00:00:09.679,000] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'disco_l475_iot1' with client lifetime 30
[00:00:09.679,000] <dbg> net_lwm2m_message_handling: lwm2m_parse_peerinfo: Parse url: coap://192.168.1.28
[00:00:09.772,000] <err> net_lwm2m_engine: fcntl(F_GETFL) failed (-22)
[00:00:09.803,000] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-22)
...

As I mentioned earlier, pinging the board from my development machine works.

...
$ ping 192.168.1.43
PING 192.168.1.43 (192.168.1.43) 56(84) bytes of data.
64 bytes from 192.168.1.43: icmp_seq=1 ttl=255 time=8.96 ms
64 bytes from 192.168.1.43: icmp_seq=2 ttl=255 time=4.30 ms
...

In contrast,  trying to ping from the board (using the network shell) I get this:

...
uart:~$ net ping 192.168.1.1
PING 192.168.1.1
Failed to send ping, err: -134
...

I am newbie to Zephyr and possibly miss something obvious, will appreciate any help

Kind regards,
-Christos


Lubos, Robert
 

Hi,

 

The Wi-Fi driver you use implements socket functions on its own (i. e. uses socket offloading feature), but the implementation seems to be incomplete. Generally, it fails when the LwM2M lib tries to configure the socket into non-blocking mode. The “eswifi” driver can also work in another offloading mode (NET_OFFLOAD), so you could try that (by disabling socket offloading with ` CONFIG_NET_SOCKETS_OFFLOAD=n`.) If this doesn’t work however, I see no other way around it other than improving the driver itself. You can raise a GH issue for that (but please be specific that it’s about “eswifi” driver_.

 

Regards,
Robert

 

From: users@... <users@...> On Behalf Of Christos Vasilakis via lists.zephyrproject.org
Sent: poniedziałek, 9 stycznia 2023 10:32
To: users@...
Subject: [Zephyr-users] LwM2M client with a B-L475E-IOT01A board (failed to setup networking)

 

Caution: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

 

Hello all,

I am experimenting with the LwM2M client example on a B-L475E-IOT01A board. Based on the lwm2m example that comes with Zephyr I have modified it and added code that initializes the Wi-Fi subsystem prior to the lwm2m setup. The code of the function can be found here:

https://github.com/cvasilak/zephyr-lwm2m-client/blob/master/src/lwm2m-client.c#L94-L140

It is based on some networking example snippet found around the net. I can see from the logs that the connection to the WIFI succeeds and an IP address is assigned to the board (I can ping the board from another machine) . Unfortunately, the LwM2M subsystem complains with the following error when trying to establish a connection:
..
00:00:25.263,000] <err> net_lwm2m_engine: fcntl(F_GETFL) failed (-22)
[00:00:25.296,000] <err> net_lwm2m_rd_client: Cannot init LWM2M engine ()
..

Here are the full logs:

*** Booting Zephyr OS build zephyr-v3.2.0-3154-g3c4783042eed ***
[00:00:00.546,000] <dbg> net_lwm2m_engine: lwm2m_engine_init: LWM2M engine socket receive thread started
[00:00:00.546,000] <dbg> net_lwm2m_obj_security: security_create: Create LWM2M security instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_server: server_create: Create LWM2M server instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_device: device_create: Create LWM2M device instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_firmware: firmware_create: Create LWM2M firmware instance: 0
[00:00:00.546,000] <inf> net_lwm2m_client_app: Initializing network connection...
Connected
[00:00:07.554,000] <inf> net_lwm2m_client_app: Connected to network
[00:00:07.554,000] <inf> net_lwm2m_client_app: Your address: 192.168.1.43
[00:00:07.554,000] <inf> net_lwm2m_client_app: Lease time: 0 seconds
[00:00:07.554,000] <inf> net_lwm2m_client_app: Subnet: 0.0.0.0
[00:00:07.554,000] <inf> net_lwm2m_client_app: Router: 0.0.0.0
[00:00:07.554,000] <inf> net_lwm2m_client_app: Run LWM2M client
[00:00:07.554,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:0/0/2, value:0x2000d497, len:1
[00:00:07.554,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:0/0/10, value:0x2000d496, len:2
[00:00:07.554,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:1/0/0, value:0x2000d496, len:2
[00:00:07.557,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3303/0
[00:00:07.557,000] <dbg> net_ipso_temp_sensor: temp_sensor_create: Create IPSO Temperature Sensor instance: 0
[00:00:07.557,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3311/0
[00:00:07.557,000] <dbg> net_ipso_light_control: light_control_create: Create IPSO Light Control instance: 0
[00:00:07.557,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3340/0
[00:00:07.557,000] <dbg> net_ipso_timer: timer_inst_create: Create IPSO Timer instance: 0
[00:00:07.557,000] <inf> net_lwm2m_rd_client: Start LWM2M Client: disco_l475_iot1
[00:00:07.557,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:3303/0/5700, value:0x2000d8f0, len:8
[00:00:08.547,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/1, buf:0x2000bfa7, buflen:1
[00:00:08.547,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/10, buf:0x2000bfde, buflen:2
[00:00:08.547,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:1/0/1, buf:0x2000bfb0, buflen:4
[00:00:08.548,000] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'disco_l475_iot1' with client lifetime 30
[00:00:08.548,000] <dbg> net_lwm2m_message_handling: lwm2m_parse_peerinfo: Parse url: coap://192.168.1.28
[00:00:08.649,000] <err> net_lwm2m_engine: fcntl(F_GETFL) failed (-22)
[00:00:08.679,000] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-22)
[00:00:09.679,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/1, buf:0x2000bfa7, buflen:1
[00:00:09.679,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/10, buf:0x2000bfde, buflen:2
[00:00:09.679,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:1/0/1, buf:0x2000bfb0, buflen:4
[00:00:09.679,000] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'disco_l475_iot1' with client lifetime 30
[00:00:09.679,000] <dbg> net_lwm2m_message_handling: lwm2m_parse_peerinfo: Parse url: coap://192.168.1.28
[00:00:09.772,000] <err> net_lwm2m_engine: fcntl(F_GETFL) failed (-22)
[00:00:09.803,000] <err> net_lwm2m_rd_client: Cannot init LWM2M engine (-22)
...

As I mentioned earlier, pinging the board from my development machine works.

...
$ ping 192.168.1.43
PING 192.168.1.43 (192.168.1.43) 56(84) bytes of data.
64 bytes from 192.168.1.43: icmp_seq=1 ttl=255 time=8.96 ms
64 bytes from 192.168.1.43: icmp_seq=2 ttl=255 time=4.30 ms
...

In contrast,  trying to ping from the board (using the network shell) I get this:

...
uart:~$ net ping 192.168.1.1
PING 192.168.1.1
Failed to send ping, err: -134
...

I am newbie to Zephyr and possibly miss something obvious, will appreciate any help

Kind regards,
-Christos


Christos Vasilakis
 

Hello Robert,

thanks a lot for the prompt reply! Adding 'CONFIG_NET_SOCKETS_OFFLOAD=n' did the trick and have managed to connect 🎉

...
*** Booting Zephyr OS build zephyr-v3.2.0-3154-g3c4783042eed ***
[00:00:00.545,000] <dbg> net_lwm2m_engine: lwm2m_engine_init: LWM2M engine socket receive thread started
[00:00:00.546,000] <dbg> net_lwm2m_obj_security: security_create: Create LWM2M security instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_server: server_create: Create LWM2M server instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_device: device_create: Create LWM2M device instance: 0
[00:00:00.546,000] <dbg> net_lwm2m_obj_firmware: firmware_create: Create LWM2M firmware instance: 0
[00:00:00.546,000] <inf> net_lwm2m_client_app: Initializing network connection...
Connected
[00:00:05.522,000] <inf> net_lwm2m_client_app: Connected to network
[00:00:05.522,000] <inf> net_lwm2m_client_app: Your address: 192.168.1.43
[00:00:05.522,000] <inf> net_lwm2m_client_app: Lease time: 0 seconds
[00:00:05.522,000] <inf> net_lwm2m_client_app: Subnet: 0.0.0.0
[00:00:05.522,000] <inf> net_lwm2m_client_app: Router: 0.0.0.0
[00:00:05.522,000] <inf> net_lwm2m_client_app: Run LWM2M client
[00:00:05.522,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:0/0/2, value:0x2000d497, len:1
[00:00:05.522,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:0/0/10, value:0x2000d496, len:2
[00:00:05.522,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:1/0/0, value:0x2000d496, len:2
[00:00:05.525,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3303/0
[00:00:05.525,000] <dbg> net_ipso_temp_sensor: temp_sensor_create: Create IPSO Temperature Sensor instance: 0
[00:00:05.525,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3311/0
[00:00:05.525,000] <dbg> net_ipso_light_control: light_control_create: Create IPSO Light Control instance: 0
[00:00:05.525,000] <dbg> net_lwm2m_registry: lwm2m_engine_create_obj_inst: path:3340/0
[00:00:05.525,000] <dbg> net_ipso_timer: timer_inst_create: Create IPSO Timer instance: 0
[00:00:05.525,000] <inf> net_lwm2m_rd_client: Start LWM2M Client: disco_l475_iot1
[00:00:05.525,000] <dbg> net_lwm2m_registry: lwm2m_engine_set: path:3303/0/5700, value:0x2000d8f0, len:8
[00:00:06.047,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/1, buf:0x2000bfa7, buflen:1
[00:00:06.047,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:0/0/10, buf:0x2000bfde, buflen:2
[00:00:06.047,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:1/0/1, buf:0x2000bfb0, buflen:4
[00:00:06.047,000] <inf> net_lwm2m_rd_client: RD Client started with endpoint 'disco_l475_iot1' with client lifetime 30
[00:00:06.047,000] <dbg> net_lwm2m_message_handling: lwm2m_parse_peerinfo: Parse url: coap://192.168.1.28
[00:00:06.162,000] <inf> net_lwm2m_engine: Connected, sock id 0
[00:00:06.162,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:1/0/1, buf:0x2000bf60, buflen:4
[00:00:06.163,000] <dbg> net_lwm2m_rd_client: sm_send_registration: registration sent [192.168.1.28]
[00:00:06.612,000] <dbg> net_lwm2m_message_handling: lwm2m_udp_receive: checking for reply from [192.168.1.28]
[00:00:06.612,000] <dbg> net_lwm2m_rd_client: do_registration_reply_cb: Registration callback (code:2.1)
[00:00:06.612,000] <dbg> net_lwm2m_client_app: rd_client_event: Registration complete
[00:00:06.612,000] <inf> net_lwm2m_rd_client: Registration Done (EP='pNA7MXGawK')
[00:00:06.613,000] <dbg> net_lwm2m_message_handling: lwm2m_udp_receive: reply 0x20004dbc handled and removed
[00:00:06.660,000] <dbg> net_lwm2m_message_handling: lwm2m_udp_receive: checking for reply from [192.168.1.28]
[00:00:06.660,000] <dbg> net_lwm2m_message_handling: lwm2m_engine_default_content_format: No accept option given. Assume SenML CBOR.
[00:00:06.660,000] <dbg> net_lwm2m_observation: engine_observe_node_init: OBSERVER ADDED 3303/0/5700/0(3)
[00:00:06.660,000] <inf> net_lwm2m_client_app: Observer added for 3303/0/5700
[00:00:06.660,000] <dbg> net_lwm2m_observation: engine_observe_node_init: token:'55624fcb7537c1ea' addr:192.168.1.28
[00:00:31.556,000] <dbg> net_lwm2m_registry: lwm2m_engine_get: path:1/0/1, buf:0x2000bf70, buflen:4
[00:00:31.556,000] <dbg> net_lwm2m_rd_client: sm_send_registration: registration sent [192.168.1.28]
[00:00:31.752,000] <dbg> net_lwm2m_message_handling: lwm2m_udp_receive: checking for reply from [192.168.1.28]
[00:00:31.752,000] <inf> net_lwm2m_rd_client: Update callback (code:2.4)
[00:00:31.752,000] <dbg> net_lwm2m_client_app: rd_client_event: Registration update complete
[00:00:31.752,000] <inf> net_lwm2m_rd_client: Update Done
...

Thanks a lot! 🙏

Kind regards,
-Christos