To help developers who would like to use our LwM2M client, we've decided to make another demonstration client for an embedded platform. This time we used Zephyr OS, which is an open-source real-time operating system, managed by The Linux Foundation.
For this purpose, we used the B-L475E-IOT01A development board. The board boasts a wide variety of sensors, including thermometer, humidity sensor, accelerometer, magnetometer, barometer, gyrometer and distance sensor. What’s more, thanks to the built-in WLAN modem, we could easily connect to the LwM2M server.
The big advantage of B-L475E-IOT01A is that no additional components (such as sensor boards, modems or SIM cards) are required. What’s more, Zephyr OS provides support for the selected board, as well as drivers for all sensors and WLAN modem, which made the implementation process quite easy.
The biggest problem we faced during the development of this client was Zephyr's
recvfrom function. The function fails when anything other than
NULL is passed as
src_addr and because of that, Anjay initially didn't work at all. However, we came to the conclusion that
src_addr isn't actually even used by Anjay and the passed non-NULL pointer comes from the compatibility layer in
avs_commons. With this information, we were able to improve our compatibility layer and Anjay was able to connect to the Server immediately.
Our next step was to successfully report values from sensors. In order to do that, we needed to implement a few LwM2M Objects. This time we decided not to use the
anjay_codegen.py, because there were only two types of sensors – single-value sensors and three-axis sensors. They have similar resources, when represented as LwM2M Objects, and they use the same API provided by Zephyr OS, so it was possible to create only two object implementations and reuse them to decrease the application size. We strongly recommend this approach if you want to reduce the amount of work required to support sensors in your applications.
The results of our work are available on our GitHub page, as we made the Anjay-Zephyr-client available publicly on Apache 2.0 license. It might come in handy as a starting point for your projects if you want to use LwM2M. The client should be portable between all boards supported by Zephyr, however, some changes related to the hardware may be required.