Using munin to visualize your arduino sensor data

I was looking for the easiest way to visualize the sensor data my arduino in the basement is sending to the linux server. The server receives a data triple every few seconds which I write to a log file using cat:

cat /dev/ttyUSB0 > /var/log/datalogger.log

and the result looks like this:

...
0.10 58.60 23.00
0.25 58.60 23.00
0.22 58.60 23.00
0.21 58.60 23.00
...

The first value is the power consumption of my drying machine, the second is the humidity and the third the temperature in the basement. You could use Processing to do wonderful visual presentations of your data, but I was afraid of the learning curve to handle Processing. So I looked for an easier solution, one that would let me access the data even from abroad. Munin seemd to be the perfect solution. After installing munin I had to add a plugin that would read the data triple from the file. For each of the values I created a little script in /etc/munin/plugins:

#!/bin/sh

case $1 in
   config)
        cat <<'EOM'
graph_title Humidity 
graph_vlabel humidity 
humidity.label humidity
EOM
        exit 0;;
esac

echo -n "humidity.value "
tail -n 1 /var/log/datalogger.log |  cut -d' ' -f2

Explanation: The config block defines titles and labels for the graph. The echo -n “humidity.value” defines the label for the current value. The tail command reads the last line from the data file and the cut command splits the line at every space. “-f2” takes the second value. And this is the resulting graph:

Munin sensor data – weekly view

Note: there are some gaps in the graph, because I’m using a log mover, that moves the file whenever it becomes bigger than 1MB. Now the cat command doesn’t know about the moving and keeps writing into the old file until I restart the cat command.

blank
Posted by Daniel Eichhorn

Daniel Eichhorn is a software engineer and an enthusiastic maker. He loves working on projects related to the Internet of Things, electronics, and embedded software. He owns two 3D printers: a Creality Ender 3 V2 and an Elegoo Mars 3. In 2018, he co-founded ThingPulse along with Marcel Stör. Together, they develop IoT hardware and distribute it to various locations around the world.

Leave a Reply