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:
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:
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 https://github.com/AVSystem/Svetovid-raspberry-client/ for instructions on how to install Svetovid, the tool for code generation and how to implement an example Object.