The Arduin Yun has a builtin web server. One can install an old version of rrdtool on linino. And the Bridge is here to transmit values from the 32u4 to linino. We will exploit this to visualize at the address http://arduino.local/sd/ a graph of a sensor value. For this example the value is transmitted every five minutes. It is the temperature in my kitchen.
-
Install rrdtool1 package through the advanced configure interface of the Yun.
-
You must have a microSD. Make an
/mnt/sda1/arduino/scripts
directory. Make another/mnt/sda1/arduino/rrd
directory. Make a/mnt/sda1/arduino/www
directory. -
Write a sketch that updates the value. In setup you must initialize the Bridge.
void setup(){
...
Bridge.begin();
...
}
Somewhere in loop one have to update the value. For a float value for example. Other methods exist with the String class.
#include <stdlib.h>
void loop() {
float temperature;
char buf_tmp[8];
...
dtostrf(temperature,1,2,buf_tmp);
Bridge.put("temperature", buf_tmp);
...
}
- Create the round robbin database. In the rrd repertory :
rrdtool create temperature.rrd --step 300 DS:temp:GAUGE:600:0:50 RRA:AVERAGE:0.5:1:576
-
Create an
index.html
in/mnt/sda1/arduino/www
directory with<img src="cuisine.png"></img>
somewhere. -
A python script will be in charge to update the database and to recompute regularly the cuisine.png file. This script is to be launched in background.
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import sys
import subprocess
import time
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
import json
from bridgeclient import BridgeClient as bridgeclient
passerelle = bridgeclient()
while True:
try:
temperature = passerelle.get('temperature')
# run shell command : rrdtool update temperature.rrd N:latemperature
subprocess.check_call(["rrdupdate", "../rrd/temperature.rrd", "N:" + temperature])
# generate the graph
subprocess.check_call(["rrdtool", "graph", "../www/cuisine.png", "-a", "PNG",
"-w", "600", "-h", "300", "-l", "15", "-u", "24", "-r",
'--vertical-label', 'Degre Celsius',
'DEF:temp=../rrd/temperature.rrd:temp:AVERAGE',
'LINE3:temp#0400ff:'])
time.sleep(300)
except Exception as e:
print 'Error : ', e
time.sleep(30)
That's all.
- Pro : no extra work to adapt your sketch to have your graph. Your graph is local, you don’t have to use an external site like Xively.
- Cons : I personally don’t like very much graphes produced by rrdtool graph. But it is possible to make your own with some svg for example. It is not time accurate. At some time the sketch update the value and in an interval of five minutes the graph is updated so the incertitude on time is of five minutes.
:~ It requires that you are able to edit a file on linino and to launch a script or manage directories. So it is better if you known linux a little bit. (to edit file on linino I use the TRAMP mode of emacs, it is very handy). You also have to edit a minimal html file.
That's all. IMHO Arduino Yun which permits such a thing is a very nice tool.
Hope this help.
Alexandre from Marseilles