posted: August 13, 2020 

Developing Anjay for Raspberry Pi

Developing Anjay for Raspberry Pi

While Raspberry Pi is well known to all tinkerers and doesn't need any introduction, SenseHat is not that famous but still an interesting module. The device is attachable using the main Raspberry Pi 40-pin header and contains the following components:

  • Gyroscope
  • Accelerometer
  • Magnetometer
  • Barometer
  • Temperature sensor
  • Relative Humidity sensor
  • 8x8 LED matrix display
  • Small 5 button joystick

What's more, the SenseHat board has support libraries already written in Python, so accessing the sensors should be easy on Linux! And we'll be doing exactly that – our point of interest is to expose as many sensor readings to the Coiote IoT Device Management platform, as possible, using the least amount of work.

So, what's the LwM2M client that supports... Python? Let's consider our options: Anjay is written in C, there are also many other clients out there in C, there are some written in Python, but they're not mature enough. Are we stuck? Luckily, no.

As it happens, our client, Svetovid, has some pretty neat functionality called File System Data Model. Essentially, it is a tool that lets you provide implementations of LwM2M Objects in form of any kind of executables as long as they're located in a specific place in the file system and behave in a certain, well-defined way. Moreover, it has an extensive support for Python-based objects and provides some useful runtime APIs.

Additionally, we have a code generator (supporting Python and Bash) capable of generating implementation stubs from OMA LwM2M Object Registry XML's.

Let's make a list of the Objects that we'll implement having the SenseHat at our disposal:

  • Temperature (/3303)
  • Accelerometer (/3313)
  • Magnetometer (/3314)
  • Barometer (/3315)
  • Gyrometer (/3334)
  • Addressable Text Display (/3341)

Now, you may have noticed that the Joystick object did not land on the list. The reason for that is that, unfortunately, the APIs for getting joystick state are event-driven – or, in other words: you need to have a process that works in the background and periodically dequeues the events generated by the observed joystick device. However, when Svetovid handles requests that target an object implemented using File System Data Model, it pretty much just executes a few scripts, and expects them to finish quickly so that the results are made available to the requester (i.e. the server).

If on the other hand we ignore joystick for a while, we can get the desired readings pretty quickly with the help of the already mentioned code generator tool – svetovid-fsdmtool. We can use it for every object we mentioned to automatically generate code stubs and fill in all the "TODOs" ourselves.

To sum up: to support joystick readings an external service/process is necessary. It's definitely a topic for future explorations.

All in all, with our Client designed for rapid prototyping using Python or Bash programming languages, we can implement pretty much any Lightweight M2M Object by simply following the tutorial on GitHub page.

See for instructions on how to install Svetovid, the tool for code generation and how to implement an example Object.


Mateusz Krawiec
Software Engineer

Recommended posts

back icon

This website is using cookies

We use cookies for statistical and marketing purposes and to improve the quality of our services. The information stored in cookies usually allow the identification of a specific device or user’s browser, so they may contain personal data. By continuing to use this website with setting the web browser in a way which alows the use of cookies by the website means your’s consent to the use of cookies. You can change your web browser settings at any time.
More information on the processing of personal data and cookies you can find in our Privacy and cookies policy.