LWM2M C Language Implementation for the Small Embedded IoT Devices

Hi group!

As a n00b in the IoT domain I have had trouble finding a suitable open sour ce implementation in C for the LWM2M protocol with DTLS support.

What I have found so far are following implementations:

- Contiki lwm2m:

formatting link

- Wakaama LWM2M:

formatting link

- Awa LWM2M:

formatting link

- Anjay:

formatting link

However I am not able to compare pros and cons of the different implementat ions in terms of code quality, features, maturity, code size etc.

The target device is built on an ARM Cortex M4 with 256 KB Flash memory, 48 KB of RAM and an Ethernet connection. The network stack might be LwIP supp orting IPv4 and IPv6, but if I decide to go for Contiki I probably will use the built-in uIP stack. The device is a OS-less bare-metal system or Conti ki.

I would appreciate very much if someone has experience in those implementat ions and could give me some feedback or point me to the right direction.

Best regards, Kalvin

Reply to
kalvin.news
Loading thread data ...

Small update: After some evaluation I decided to go with Wakaama LWM2M due to decent memory requirements and porting effort. I was able to port Wakaam a LWM2M Client with DTLS-support running on top of a LwIP 2.0.2 using the L wIP IPv4 event-driven Raw API (ie. no sockets) with a PPP connection, consu ming around 132KB Flash and 32KB RAM. The system is a bare-metal ARM M4 sys tem (ie. not actual operating system) targeted for very low power sensor ap plications requiring IoT connectivity for device management and sensor data uploading to the cloud server.

Br, Kalvin

Reply to
kalvin.news

hi Kalvin

any updates, sample code, im trying to do the same on an m4 g55 microchip m cu.

thanks

rp

urce implementation in C for the LWM2M protocol with DTLS support.

ations in terms of code quality, features, maturity, code size etc.

48 KB of RAM and an Ethernet connection. The network stack might be LwIP su pporting IPv4 and IPv6, but if I decide to go for Contiki I probably will u se the built-in uIP stack. The device is a OS-less bare-metal system or Con tiki.

ations and could give me some feedback or point me to the right direction.

Reply to
sys732

keskiviikko 30. toukokuuta 2018 22.48.12 UTC+3 snipped-for-privacy@gmail.com kirjoitti:

mcu.

e:

source implementation in C for the LWM2M protocol with DTLS support.

ntations in terms of code quality, features, maturity, code size etc.

, 48 KB of RAM and an Ethernet connection. The network stack might be LwIP supporting IPv4 and IPv6, but if I decide to go for Contiki I probably will use the built-in uIP stack. The device is a OS-less bare-metal system or C ontiki.

ntations and could give me some feedback or point me to the right direction .

Hi rp, Sorry this late reply, but I haven't been reading the newsgroups lately. An yway, here is how I proceeded with the porting effort:

  1. First, I took the Wakaama client source code and the LwIP 2.0.2 source c ode, and made the Wakaama client running on a PC using the LwIP socket inte rface. This required tweaking the Wakaama build scripts so that the build p rocess would also build the LwIP and link it with Wakaama.
  2. Modified Wakaama client to use the LwIP raw API running on a PC. The LwI P porting guide is a good place to start:
    formatting link

This all was pretty straight forward to do as Wakaama has quite simple and thin networking interface using only UDP protocol.

Wireshark proved to be a very valuable too in this process when debugging t he DTSL-related stuff for example.

You may need to use the TAP-interface adapter so that the LwIP is able to u se the Ethernet interface of your development machine:

formatting link

Now that I had the Wakaama client running on a PC using LwIP raw interface I had to make it running on my target hardware.

  1. I needed setup a LwIP PPP connection.

  1. Tweaked the LwIP configuration to fit the target hardware.

  2. Tweaked the TinyDTLS build scripts so that it compiles cleanly on the ta rget hardware and ARM C compiler.

  1. My target ARM-system did not provide the malloc and free, so I had to fi gure out what to do with that. Luckily the LwIP provided also malloc and fr ee, and modified the source code to use these library functions. There were some other minor functions that I needed to implement, like the time funct ions.

  2. After a clean build and some printf-debugging, I was able to connect my target hardware running Wakaama client to a server over PPP.

That's basically the whole process. Although I hadn't been working with the LwIP nor Wakaama before, it took me less than two weeks (with very little sleep) to get the things up and running and to get the Wakaama LWM2M client DTLS connection working with the Leshan server.

During more comprehensive testing it was found out that DTLS/Wakaama was bl eeding some memory. I added some printf's to LwIP malloc/free adapter stubs which were created to mimic the std malloc and free functions. Created a s imple Python tool to track the malloc/free memory blocks using the printf-o utput, and I was able to spot the problematic places and patched the code t o release the allocated memory so that the malloc/free was working without any further issues.

Hope this helps you to get started.

Br, Kalvin

Reply to
kalvin.news

:

ip mcu.

ote:

n source implementation in C for the LWM2M protocol with DTLS support.

mentations in terms of code quality, features, maturity, code size etc.

ry, 48 KB of RAM and an Ethernet connection. The network stack might be LwI P supporting IPv4 and IPv6, but if I decide to go for Contiki I probably wi ll use the built-in uIP stack. The device is a OS-less bare-metal system or Contiki.

mentations and could give me some feedback or point me to the right directi on.

Anyway, here is how I proceeded with the porting effort:

code, and made the Wakaama client running on a PC using the LwIP socket in terface. This required tweaking the Wakaama build scripts so that the build process would also build the LwIP and link it with Wakaama.

wIP porting guide is a good place to start:

d thin networking interface using only UDP protocol.

the DTSL-related stuff for example.

use the Ethernet interface of your development machine:

e I had to make it running on my target hardware.

target hardware and ARM C compiler.

figure out what to do with that. Luckily the LwIP provided also malloc and free, and modified the source code to use these library functions. There we re some other minor functions that I needed to implement, like the time fun ctions.

y target hardware running Wakaama client to a server over PPP.

he LwIP nor Wakaama before, it took me less than two weeks (with very littl e sleep) to get the things up and running and to get the Wakaama LWM2M clie nt DTLS connection working with the Leshan server.

bleeding some memory. I added some printf's to LwIP malloc/free adapter stu bs which were created to mimic the std malloc and free functions. Created a simple Python tool to track the malloc/free memory blocks using the printf

-output, and I was able to spot the problematic places and patched the code to release the allocated memory so that the malloc/free was working withou t any further issues.

Hello All, We are integrating Anjay LWM2M client on Murata Type 1LD (cypress psoc). if mbedTLS is enabled there is an error trying to register. Where as the code works in non -secure mode. Also the same code works fine in mbedTLS mode f rom linux machine. So this has to be an issue with Anjay LWM2M and WICED in tegration. Trying to debug and not sure what the following error means, any help is much appreciated

Setting IPv6 link-local address Obtaining IPv4 address via DHCP IPv6 Network ready IP: FE80::29D:6BFF:FE62:78AA IPv4 Network ready IP: 192.168.1.195 Wifi network up success Wifi network up success

TEST Version 1.0.4

*** mbedtls_ctr_drbg_seed ***

entropy_callback

######################## entropy_callback Seed_callback out buff : 536930016 Initializing Anjay RunningRunningRunningRunningRunningRunningRunningRunningRunningRunningRunni ngRunningRunningRunningRunningRunningRunningRunningRunningRunningRunningRun ningRunningRunning$$$$$ AVS_NET_DTLS_SOCKET $$$$$$ avs_net_dtls_socket_create WITH SSL $$$$$create_ssl_socket configure_ssl socket 0x2000e3cc, configuration= 0x2000e4e8

*initialize_ssl_socket AVS_NET_SECURITY_PSK

******** initialize_psk_security ******

******************* mbedtls_ssl_conf_psk ################### Psk key P4s$w0rd length 8 Identity testboard length 9 $$$$$$$ AVS_OK ************_anjay_server_connection_internal_bring_online

Start SSL

**Could not restore session; performing full handshake MBEDTLS_SSL_CLI_C end point 0 inside mbedtls_ssl_flush_output wrap_handshake_result Result 0, security mode 1, dane_ta_certs (null) verif y_result 0 handshake success: new session started **Return AVS_OK

ANJAY_REGISTRATION_ERROR_REJECTED update rejected for SSID 1 needs re-registration Attempting to register with LwM2M version 1.0 sending Register lwm2m version 0 coap_base->last_exchange_id 0 (*exchange_ptr)->id 0 avs_time_monotonic_now() second 0 nanosec 9 Register send Runningget_dtls_overhead avs_net_socket_send

send_ssl start

Output Bytes:48 2 B4 66 D 88 34 D0 23 5B 8B 31 B2 72 64 11 28 39 6C 77 6D 3

2 6D 3D 31 2E 30 C 65 70 3D 74 65 73 74 62 6F 61 72 64 5 6C 74 3D 36 30 FF 3C 2F 31 2F 30 3E send_ssl socket= 0x20015b18 , buffer= 0x20017014 , buffer_length= 53 Going for mbedtls_ssl_write Handshake not NULL Client id (null) client id length 0 Host name try-anjay.avsystem.com psk (n ull) psk_leng 0 Psk key P4s$w0rd ident testboard Hand shake not over MBEDTLS_SSL_CLI_C end point 0 inside mbedtls_ssl_flush_output inside mbedtls_ssl_flush_output avs_bio_send avs_net_socket_send inside mbedtls_ssl_flush_output avs_bio_send avs_net_socket_send wrap_handshake_result Result 53, security mode 1, dane_ta_certs (null) veri fy_result 0 Hand shake result : 53 RunningReceive_ssl socket = 0x20015b18, buffer= 0x200141e8 , buffer_len gth= 2048inside mbedtls_ssl_flush_output MBEDTLS_SSL_CLI_C end point 0 inside mbedtls_ssl_flush_output wrap_handshake_result Result -76, security mode 1, dane_ta_certs (null) ver ify_result 0 receive failed: -76 RunningRunningRunningavs_net_socket_send

send_ssl start

Output Bytes:48 2 B4 66 D 88 34 D0 23 5B 8B 31 B2 72 64 11 28 39 6C 77 6D 3

2 6D 3D 31 2E 30 C 65 70 3D 74 65 73 74 62 6F 61 72 64 5 6C 74 3D 36 30 FF 3C 2F 31 2F 30 3E send_ssl socket= 0x20015b18 , buffer= 0x20017014 , buffer_length= 53 Going for mbedtls_ssl_write Handshake not NULL Client id (null) client id length 0 Host name try-anjay.avsystem.com psk (n ull) psk_leng 0 Psk key P4s$w0rd ident testboard Hand shake not over MBEDTLS_SSL_CLI_C end point 0 inside mbedtls_ssl_flush_output inside mbedtls_ssl_flush_output avs_bio_send avs_net_socket_send Handshake return -26880 Going for mbedtls_ssl_write Handshake not NULL Client id (null) client id length 0 Host name try-anjay.avsystem.com psk (n ull) psk_leng 0 Psk key P4s$w0rd ident testboard Hand shake not over MBEDTLS_SSL_CLI_C end point 0 inside mbedtls_ssl_flush_output Handshake return -76 wrap_handshake_result Result -76, security mode 1, dane_ta_certs (null) ver ify_result 0 Hand shake result : -76 socket bio_error send failed 0 53 : -76 AVS_COAP_CLIENT_REQUEST_FAIL failure while receiving Register response: Message too long mapping CoAP error Message too long to network error ANJAY_REGISTRATION_ERROR_NETWORK could not register to server 1

Thanks Anees

Reply to
Hanah anees

ti:

chip mcu.

pen source implementation in C for the LWM2M protocol with DTLS support.

lementations in terms of code quality, features, maturity, code size etc.

mory, 48 KB of RAM and an Ethernet connection. The network stack might be L wIP supporting IPv4 and IPv6, but if I decide to go for Contiki I probably will use the built-in uIP stack. The device is a OS-less bare-metal system or Contiki.

lementations and could give me some feedback or point me to the right direc tion.

. Anyway, here is how I proceeded with the porting effort:

ce code, and made the Wakaama client running on a PC using the LwIP socket interface. This required tweaking the Wakaama build scripts so that the bui ld process would also build the LwIP and link it with Wakaama.

LwIP porting guide is a good place to start:

and thin networking interface using only UDP protocol.

ng the DTSL-related stuff for example.

to use the Ethernet interface of your development machine:

ace I had to make it running on my target hardware.

e target hardware and ARM C compiler.

o figure out what to do with that. Luckily the LwIP provided also malloc an d free, and modified the source code to use these library functions. There were some other minor functions that I needed to implement, like the time f unctions.

my target hardware running Wakaama client to a server over PPP.

the LwIP nor Wakaama before, it took me less than two weeks (with very lit tle sleep) to get the things up and running and to get the Wakaama LWM2M cl ient DTLS connection working with the Leshan server.

s bleeding some memory. I added some printf's to LwIP malloc/free adapter s tubs which were created to mimic the std malloc and free functions. Created a simple Python tool to track the malloc/free memory blocks using the prin tf-output, and I was able to spot the problematic places and patched the co de to release the allocated memory so that the malloc/free was working with out any further issues.

if mbedTLS is enabled there is an error trying to register. Where as the co de works in non -secure mode. Also the same code works fine in mbedTLS mode from linux machine. So this has to be an issue with Anjay LWM2M and WICED integration. Trying to debug and not sure what the following error means, a ny help is much appreciated

ningRunningRunningRunningRunningRunningRunningRunningRunningRunningRunningR unningRunningRunning$$$$$ AVS_NET_DTLS_SOCKET $$$$$$

ify_result 0

32 6D 3D 31 2E 30 C 65 70 3D 74 65 73 74 62 6F 61 72 64 5 6C 74 3D 36 30 F F 3C 2F 31 2F 30 3E
3

(null) psk_leng 0

rify_result 0

ength= 2048inside mbedtls_ssl_flush_output

erify_result 0

32 6D 3D 31 2E 30 C 65 70 3D 74 65 73 74 62 6F 61 72 64 5 6C 74 3D 36 30 F F 3C 2F 31 2F 30 3E
3

(null) psk_leng 0

(null) psk_leng 0

erify_result 0

Hi Anees,

I'm also working with Wakaama LwM2M library. The customer server is secured (COAPS) so need to use DTLS. For this, I'm u sing mbedTLS. But somehow I'm not able to make a handshake with the server. Could you help to share the code snippet (mbedTLS) part? That will great he lp for me.

Thanks, Vikram

Reply to
Vikram Kerkar

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.