Forums

小型嵌入式IoT设备的LWM2M C语言实现

开始于 未知 2017年4月26日
Hi group!

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

What I have found so far are following implementations:

- Contiki lwm2m: //github.com/sics-iot/lwm2m-contiki
- Wakaama LWM2M: //github.com/eclipse/wakaama
- Awa LWM2M: //github.com/FlowM2M/AwaLWM2M
- Anjay: //github.com/AVSystem/Anjay

However I am not able to compare pros and cons of the different implementations 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 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.

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

Best regards,
Kalvin
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 Wakaama LWM2M Client with DTLS-support running on top of a LwIP 2.0.2 using the LwIP IPv4 event-driven Raw API (ie. no sockets) with a PPP connection, consuming around 132KB Flash and 32KB RAM. The system is a bare-metal ARM M4 system (ie. not actual operating system) targeted for very low power sensor applications requiring IoT connectivity for device management and sensor data uploading to the cloud server.

Br,
Kalvin
hi Kalvin

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

thanks 

rp


On Thursday, April 27, 2017 at 2:34:38 AM UTC+10, kalvi...@gmail.com wrote:
> Hi group! > > As a n00b in the IoT domain I have had trouble finding a suitable open source implementation in C for the LWM2M protocol with DTLS support. > > What I have found so far are following implementations: > > - Contiki lwm2m: //github.com/sics-iot/lwm2m-contiki > - Wakaama LWM2M: //github.com/eclipse/wakaama > - Awa LWM2M: //github.com/FlowM2M/AwaLWM2M > - Anjay: //github.com/AVSystem/Anjay > > However I am not able to compare pros and cons of the different implementations 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 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. > > I would appreciate very much if someone has experience in those implementations and could give me some feedback or point me to the right direction. > > Best regards, > Kalvin
keskiviikko 30. toukokuuta 2018 22.48.12 UTC+3 sys...@gmail.com kirjoitti:
> hi Kalvin > > any updates, sample code, im trying to do the same on an m4 g55 microchip mcu. > > thanks > > rp > > > On Thursday, April 27, 2017 at 2:34:38 AM UTC+10, kalvi...@gmail.com wrote: > > Hi group! > > > > As a n00b in the IoT domain I have had trouble finding a suitable open source implementation in C for the LWM2M protocol with DTLS support. > > > > What I have found so far are following implementations: > > > > - Contiki lwm2m: //github.com/sics-iot/lwm2m-contiki > > - Wakaama LWM2M: //github.com/eclipse/wakaama > > - Awa LWM2M: //github.com/FlowM2M/AwaLWM2M > > - Anjay: //github.com/AVSystem/Anjay > > > > However I am not able to compare pros and cons of the different implementations 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 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. > > > > I would appreciate very much if someone has experience in those implementations and could give me some feedback or point me to the right direction. > > > > Best regards, > > Kalvin
Hi rp, Sorry this late reply, but I haven't been reading the newsgroups lately. Anyway, 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 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 build process 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 LwIP porting guide is a good place to start: http://lwip.wikia.com/wiki/Porting_for_an_OS 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 the DTSL-related stuff for example. You may need to use the TAP-interface adapter so that the LwIP is able to use the Ethernet interface of your development machine: //backreference.org/2010/03/26/tuntap-interface-tutorial/ 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. 3. I needed setup a LwIP PPP connection. 4. Tweaked the LwIP configuration to fit the target hardware. 5. Tweaked the TinyDTLS build scripts so that it compiles cleanly on the target hardware and ARM C compiler. 6. My target ARM-system did not provide the malloc and free, so I had to 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 were some other minor functions that I needed to implement, like the time functions. 6. 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 bleeding 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 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 without any further issues. Hope this helps you to get started. Br, Kalvin