Re: BLE Nano 2 - LWM2M DTLS demo example


Michael Scott
 

Hi again Christos,


On 04/23/2018 09:34 AM, Christos Vasilakis wrote:
Hi there,

I have recently purchased a BLE Nano 2 kit and I am trying to run the LWM2M client example found here [1]. I have successfully installed and run the simple (non-DTLS) example and works just fine (using a Raspberry PI  6lowpan BLE network as described in [2]). That is, I can successfully ping the Nano node as well as having it register with the Leshan LWM2M server and query it’s objects.

Now I am trying to setup the DTLS example and for this I have done the following:

- setup the pre-shared key on the Leshan server (as suggested in [3])
- enable the dlls configuration in the prj_dtls.conf. A dump of this configuration file can be found here [4]. 

>> Please note that I have lowered the CONFIG_MBEDTLS_HEAP_SIZE from 8192 to 4096 cause I got the following error printed in the console which resulted in a none working BT connection.

I think changing the CONFIG_MBEDTLS_HEAP_SIZE is what's causing the issues you're seeing.  I didn't get the "Unable to get TX packet, not enough memory." error when leaving the CONFIG_MBEDTLS_HEAP_SIZE and using the following changes:

1. Add the following CONFIG lines to the bottom of the prj_dtls.conf:
CONFIG_NET_L2_BT=y
CONFIG_BT_DEVICE_NAME="Test IPSP node"
CONFIG_NET_APP_BT_NODE=y

2. Build the sample for BLENano2 like so:
$ cd samples/net/lwm2m_client
$ mkdir build && cd build
$ cmake -GNinja -DBOARD=nrf52_blenano2 -DCONF_FILE="prj_dtls.conf" ..
$ ninja
$ pyocd-flashtool -ce -t nrf52 zephyr/zephyr.bin

3. NOTE: The host machine where I connect the BLENano2 via 6lowpan has a Leshan server connected to 2001:db8::2.  I'm assuming you have this running on your RPi.

4. I added the following information to the Leshan security settings:
Client endpoint: nrf52_blenano2
Security mode: Pre-Shared Key (already set by default)
Identity: Client_identity
Key: 000102030405060708090a0b0c0d0e0f

5. When monitoring the BLENano2 via UART, it should spew just a few lines like the Zephyr version and some initialization regaring LwM2M objects and then wait until joined via 6lowpan before attempting to connect to the Leshan server.  Also, you use the "net iface" shell command to see detailed information about the bluetooth network interface.

6. NOTE: Almost all of the RAM on BLENano2 is used by the sample when DTLS enabled (using the default configs).  If you were to enable almost ANY debug CONFIG at all, you would most certainly hit RAM issues.  To help with, you could consider disabling some of the following CONFIG items in prj_dtls.conf:
CONFIG_NET_IPV4=n
CONFIG_NET_APP_NEED_IPV4=n
CONFIG_SYS_LOG_SHOW_COLOR=n

Or tone down the logging output of the sample or disabling the command shell:
CONFIG_NET_LOG=n
CONFIG_NET_BUF_LOG=n
CONFIG_SYS_LOG_NET_LEVEL <lowering the # would reduce logging output>
CONFIG_SYS_LOG_NET_BUF_LEVEL <lowering the # would reduce logging output>
CONFIG_SYS_LOG_LWM2M_LEVEL <lowering the # would reduce logging output>
CONFIG_NET_SHELL=n

Let me know how this works on your end.

One last note: I think your experience proves it's too difficult to configure the LwM2M client for extended use-cases (DTLS + Bluetooth networking).  I'm going to submit some patches keeping just the primary "prj.conf" file, move just the DTLS specific settings from "prj_dtls.conf" into "overlay-dtls.conf" and having the Bluetooth enabling configs in "overlay-bt.conf".

This should be easier to maintain over time, *and* hopefully allow more build combinations using the -DCONF_FILE command line option which can take several filenames.
Building and flashing the DTLS-enabled client for BLENano2 would then look something like:
$ cd samples/net/lwm2m_client
$ mkdir build && cd build
$ cmake -GNinja -DBOARD=nrf52_blenano2 -DCONF_FILE="prj.conf overlay-bt.conf overlay-dtls.conf" ..
$ ninja
$ pyocd-flashtool -ce -t nrf52 zephyr/zephyr.bin

- Mike

'[lib/lwm2m_engine] [ERR] lwm2m_init_message: Unable to get TX packet, not enough memory."


Unfortunately the DTLS version doesn’t seem to work. In particular during bootstrap I get error (-72). Here is a dump of the console:

--------------------------------------------------------
***** Booting Zephyr OS v1.11.0-758-g541c3cb18 *****
[lib/lwm2m_engine] [DBG] lwm2m_engine_init: LWM2M engine thread started
[lwm2m_obj_security] [DBG] security_create: Create LWM2M security instance: 0
[lwm2m_obj_server] [DBG] server_create: Create LWM2M server instance: 0
[lwm2m_obj_device] [DBG] device_create: Create LWM2M device instance: 0
[lwm2m_obj_firmware] [DBG] firmware_create: Create LWM2M firmware instance: 0
[bt] [INF] hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
[bt] [INF] hci_vs_init: HW Variant: nRF52x (0x0002)
[bt] [INF] hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 1.11 Build 99
[bt] [INF] show_dev_info: Identity: e0:0f:f1:29:76:01 (random)
[bt] [INF] show_dev_info: HCI: version 5.0 (0x09) revision 0x0000, manufacturer 0x05f1
[bt] [INF] show_dev_info: LMP: version 5.0 (0x09) subver 0xffff
[bt] [WRN] bt_pub_key_gen: ECC HCI commands not available
[lwm2m-client] [INF] main: Run LWM2M client
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/0, value:0x0002f852, len:6
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/1, value:0x0002f85f, len:23
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/2, value:0x0002f87d, len:9
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/3, value:0x0002f88d, len:3
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/9, value:0x2000c2f7, len:1
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/10, value:0x2000c2f4, len:4
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/17, value:0x0002f8b0, len:16
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/18, value:0x0002f8c8, len:5
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/20, value:0x2000c2f7, len:1
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/21, value:0x2000c2f4, len:4
[lib/lwm2m_engine] [DBG] lwm2m_engine_create_obj_inst: path:3303/0
[ipso_temp_sensor] [DBG] temp_sensor_create: Create IPSO Temperature Sensor instance: 0
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3303/0/5700, value:0x2000c310, len:8
[lib/lwm2m_engine] [DBG] lwm2m_engine_create_obj_inst: path:3311/0
[ipso_light_control] [DBG] light_control_create: Create IPSO Light Control instance: 0
prio recv thread stack (real size 748): unused 488      usage 260 / 748 (34 %)
recv thread stack (real size 1324):     unused 424      usage 900 / 1324 (67 %)
[lib/lwm2m_engine] [ERR] lwm2m_engine_start: Cannot connect UDP (-72)
[lib/lwm2m_rd_client] [ERR] lwm2m_rd_client_start: Cannot init LWM2M engine (-72)
[lwm2m-client] [ERR] main: LWM2M init LWM2M RD client error (-72)
prio
--------------------------------------------------------


From the Raspberry PI I can successfully ping the node which implies that connectivity exists and is working.

root@raspberrypi:/home/pi# ping 2001:db8::1. <— BLE Nano 2 
PING 2001:db8::1(2001:db8::1) 56 data bytes
64 bytes from 2001:db8::1: icmp_seq=1 ttl=64 time=221 ms
64 bytes from 2001:db8::1: icmp_seq=2 ttl=64 time=194 ms
^C
--- 2001:db8::1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 194.834/208.153/221.472/13.319 ms


I would be grateful if someone can help me to debug the issue.

Thank you in advance

-Christos



Join users@lists.zephyrproject.org to automatically receive all group messages.