Using munin to visualize your arduino sensor data

Do you like this post? A regular project like the PlaneSpotter Color takes many hours of my free time to develop and maintain. Would you offer me a beer for my hard work if I was your neighbour? Modern technology called teleportation makes it easy to send me a beer. Just click here. Thank you!

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.

Posted by squix78

Leave a Reply