Recently I have been working on a way to visualize data from a couple temperature and humidity sensors I have at home (DHT22). I would like to host it on my Raspberry Pi 3B so I don’t have to rely on an external server and it would be great if it was lightweight, easy to install and maintain.

IoT dashboards

IoT all the things (meme)

There is plenty of options when you want to send your sensor data to a central server for visualization, alerting and all that stuff. But most of them are hosted, and/or expensive, or they are not open source.

The alternatives

  • ThingsBoard is open source and has a free version you can host on a Raspberry Pi but requires Java, PostgreSQL and tweaks for it to work on such a low memory device.
  • KAA is another option, but you can’t host it yourself for free (99$ per month). The hosted and free version is limited to 5 devices. It is not really open source.
  • DeviceHive looked promising. It is open source but I wasn’t able to enter the Playground to test the dashboard (Grafana) and see if the thing was working.
  • Mainflux is also completely open source, it is written in Go and provides Docker images. It should work on ARM but considering it also uses PostgreSQL it might not be the most lightweight alternative if your Raspberry is doing other things or doesn’t have much RAM. I would try it on a Pi 4 but not on a Pi 3.

I also considered installing Prometheus directly. It has great support, it is reliable and Grafana can take care of the visualizations. But how do you integrate your Arduino-like board with Prometheus? In other words, how do I send data from a sensor on a Raspberry Pi to the server?
The Prometheus Python client library would work for the Raspberry but for Arduino there is no such thing.

Therefore I would need a gateway that accepts some kind of HTTP call and then sends the data to Prometheus.

I hate reinventing the wheel but using a super powerful tool for something that is simple (and not exactly what it was designed for) is usually a source of pain in the butt.
And I’m not really asking for much: one endpoint to send/store data and a way to plot it.

Well, it’s lockdown time because of COVID and I am on holidays, what am I going to loose if I try? Time? YOLO, let’s do it!

The requirements

I would like the client to be just an HTTP request. This way I can use whatever hardware I want as long as there is a way to make HTTP calls.

Regarding the server, it should work on a Raspberry Pi 3B. If possible I would like the installation process to be pretty much none. And I don’t really need a very powerful database for this, I prefer something simple. It is not going to be under heavy load nor have many concurrent users.

Oh and real time is not a requirement.

My approach

I picked Django for the server. I know it, I like it and it is very easy to install on a Raspberry Pi cause it already has Python.
Thanks to that I also have an admin panel for free where I can create or delete sensors. I have always loved this about Django.

The data the sensors measure and send to the server is stored in CSV files. A file is created for each sensor every day.
This way I can download the data I want right away in case I need it for something else.

I use SQLite but only for user authentication and a «Sensor» model containing a name and not much more for now.

For the frontend: Django templates, Bootstrap and Chart.js cause I am a backend guy.

You can have a look at the code, or install it if you want, it is on my Gitlab: SensorHub.

There is a sample code for a NodeMCU board connected to a DHT22 sensor sending data to Sensorhub on the repo.

And another sample with the same sensor but a Raspberry Pi Zero Wireless instead.

For now Sensorhub only supports temperature and humidity sensors but I will soon be adding support for other kind of sensors like atmospheric pressure, luminosity, soil moisture…

NodeMCU?

It is my first time using NodeMCU boards. They are Arduino compatible and have WiFi support. In fact they are like Arduino and ESP32 soldered together.

In theory you can also use Lua with these boards instead of the Arduino language but I have not tested that yet. I am afraid the tools and libraries are not as mature as with Arduino but I would probably give it a try at some point.

In conclusion, for just 3$ I find this board pretty impressive. Anything is just 3$ away from being connected to the internet.

If you think my content is worth it you can Buy me a Coffee at ko-fi.com Buy me a Ko-fi