Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

Home monitoring system

Nowdays, an inexpensive hardware (Arduino boards, Raspberry Pi and similar boards, sensors,
actuators, etc.) and a huge amount of available information on the Internet gives you a possibility to
develop interesting systems with a limited knowledge about electronics, Web and other
technologies. These systems are usually part of the global network too which brings us toward
Internet of Things (IoT). One of the endless IoT possibilities is definitely home system monitoring.
Such systems can provide you the constant information about state of your home (for example
insight into past and current values of the physical variables in your home like temperatures and
humidity) and consequently advanced control of your everyday life quality (comfort, energy
consumption and security).

In this article, a simple home monitoring system is presented which provides you the constant
information about values of physical variables around your house or flat. The figure below shows the
current setup around my flat. I have two nodes that periodically measure temperature and humidity
and send measured data via radio transceiver to the main node. The nodes are based upon Arduino
Nano boards with nRF24L01 chips for wireless communication. The main node, based on Arduino
Uno, is connected with a serial link to a Raspberry Pi. The Raspberry Pi stores the received data to
MySQL database. Since the Raspberry Pi is connected to the home router, the data can be accessed
from everywhere (e.g. work PC, your mobile phone and so on). Appropriate Web site for
measurement visualization is also developed which is based on a javascript library Rgraph for data
visualization.

The article is divided into three parts. The first part gives the information about nodes (software and
hardware aspects), the second one deals with the Raspberry Pi setup and in the third one data
visualization is presented.
Nodes
The presented home monitoring system consists of a star like structure of wireless nodes. This
means that one node, the main node, collects information from the other nodes and forwards
them to Raspberry Pi. The other nodes act just like wireless sensors - periodically measure
physical values around the flat and send the measurements to the main node. There is possibility
to extend this structure by developing similar star like subnetwork around each wireless sensors
node. Such extended structure can be useful for larger objects. For example, in a house with the
three floors, wireless sensors on each floor can be treated like a subnetwork where one central
node on each floor collects information on its floor and sends it to the central house node.

Currently, the setup around my flat consists of two wireless sensors nodes and one main node. I
decided to build the wireless sensors nodes upon Arduino Nano board. The core of Arduino
Nano board is ATmega328P microcontroller (datasheet). Apart from MCU, this board has FTDI
USB-to-TTL Serial chip which enables MCU to communicate with other serial enabled devices
(like PC), thus simplifying development and debugging process. Each wireless sensor node has
a nRF24L01 transceiver for wireless communication. These chips are quite cheap and can be
found in two designs (module with built in antenna and module with power amplifier and SMA
antenna). With appropriate sensors attached to the Arduino Nano board, these nodes can
transmit the readings from sensors to the main node over free 2.4 GHz band. Additionally, I
wanted to see the current readings when I am near sensors so I added the possibility to stick
2x16 LCD to the wireless sensor node.

Hardware
The following images show the built wireless sensor board.
The Arduino Nano board, nRF24L01 module and, in this case, digital temperature and humidity
sensor DHT22 are mounted on the board by sticking to the appropriate headers which are
soldered on the PCB. Optionally, you can stick LCD to the board. Therefore, to build this wireless
sensor node you will need:

 2 x 10 pin single row female pin header


 1 x 4 pin single row female pin header
 1 x 4 pin double row female pin header
 1 x 16 pin single row male pin header
 1 x 10 uF electrolytic capacitor
 3 x 1N4001 diode
 1 x 4.7k resistor
 2 x trimmers
 1 x Arduino Nano board wilt soldered male pin header
 1 x nRF24L01 module
 1 x DHT22 or some other digital sensor
 1 x LCD 2x16 (optional)
 power supply (DC 5V)

I will skip detail explanation about connection between components. I will just mention following
issues that I came across while building this wireless sensor node. The nRF24L01 module
requires 3.3V power supply. However, 3.3V pin on Arduino Nano cannot provide as much current
as nRF24L01 module needs for operation if powered from the USB port. Therefore, I used three
diodes to get the 3.3V voltage from 5V pin of the Arduino Nano board. Second issue is also
concerned with the power supply. I am using adapter (DC 5V, 0.7A) with the micro USB plug
(such adapters are used for charging Android smartphones). At first I connected this adapter to
the mini USB socket on the Arduino Nano board (via appropriate mini-> micro USB adapter).
However, the FTDI chip couldn't provide as much current as needed for the operation of the
whole board with LCD. Therefore, I directly connected power adapter to the 5V and GND pins on
the Arduino Nano board.

The LCD can be connected on both sides of the printed circuit board (I soldered pin header
which has long pins on both side). The two trimmers on the board allow the user to set the
intensity of the backlight and contrast on the LCD.
The schematic and the printed circuit board layout can be found in this Eagle project. The
following image shows the PCB with already soldered components. If you want to make the PCB
yourself, check this page.

The main node, which collects the information from the wireless sensor nodes, is based on
the Arduino Uno board and nRF24L01 module with amplifier and SMA antenna. The
microcontroller on the Arduino board resets every time the serial port is opened. This means
whenever the Raspberry PI demands the data from the main node, the microcontroller will reset
and loose the gathered information from the wireless sensor nodes. To prevent this I connected
10uF electrolytic capacitor between RESET and GND pin on the Arduino Uno board.
Software
The applications for the wireless sensor nodes and main node were written in Atmel Studio 6.1. I
extensively used already available libraries for nRF24L01, LCD, DS18B20 temperature sensor
and DHT22 temperature and humidity sensor.

Description of the main program - wireless sensor node

A wireless sensor node measures some kind of physical quantity like temperature or humidity
with appropriate sensors. The measurements are performed with predefined sample time like
every 10 seconds but are sent to the main node with much lower frequency (e.g. every minute).
The measurement is sent to the main node in a packet which has the following structure:

# sensor_id M m_value

where sensor_id is a unique integer and m_value is value that was measured with the sensor.

Description of the main program - main node

The role of the main node is to collect the measurements from wireless sensor nodes and send
them to Raspberry Pi on request. The data are sent to Raspberry Pi in form of packet which has
the following structure (binary):

0x01 # sensor_id M m_value ... # sensor_id M m_value CRC 0x04

where 0x01 is used as a start of a packet, 0x04 marks end of the packet and CRC is protection
byte. However, then main node should only send the measurements which are received in the
predefined time interval (like 4 minutes) from the wireless sensor nodes.
nRF24L01 code

In this project I used nRF24L01 driver developed by Davide Gironi. Check his blog for the source
code and other cool projects. His driver practically works out of the box, I just had to adapt pins
and port that I am using for communication with the module. In my case, the nRF24L01 module
is connected to my Arduino Nano (i.e. ATmega328P) board via the following pins:

D9 (output), pin PB1 --> CE NRF24L01


D10 (output), pin PB2 --> CSN NRF24L01
D11 (output), pin PB3 --> MOSI NRF24L01
D12 (input), pin PB4 --> MISO NRF24L01
D13 (output), pin PB5 --> SCK NRF24L01

Therefore, I appropriately changed the lines in nrf24l01.h to:

//CE and CSN port definitions


#define NRF24L01_DDR DDRB
#define NRF24L01_PORT PORTB
#define NRF24L01_CE PB1
#define NRF24L01_CSN PB2

I also changed the payload (the nuber of bytes per message) to 32:

#define NRF24L01_PAYLOAD 32

There are other options in nrf24l01.h, I just used the default ones provided with the library. The
nRF24L01 module communicates with the ATmega328P via SPI interface. On the same site you
can find the working SPI library.

DHT22 code

Same fellow wrote a nice working library for DHT sensors. In my case I just changed pin and port
definition in dht.hto match the connections on my wireless sensors node:

//setup port
#define DHT_DDR DDRC
#define DHT_PORT PORTC
#define DHT_PIN PINC
#define DHT_INPUTPIN PC2

DS18B20 code

For the wireless sensors nodes with DS18B20 temperature sensors I used library provided
by Martin Thomas. To use it with the presented wireless sensor nodes, hardware connection
should be defined properly in onewire.h file:
#define OW_PIN PC2
#define OW_IN PINC
#define OW_OUT PORTC
#define OW_DDR DDRC

LCD code

LCD is optional on the presented wireless sensors modules. If you want to use LCD on your
wireless sensor node, then you have to include appropriate library in your project. I used
the Peter Fleury's library. LCD connection to Arduino Nano ATmega328 is as follows:

D4, pin PD4 --> LCD data 0


D5, pin PD5 --> LCD data 1
D6, pin PD6 --> LCD data 2
D7, pin PD7 --> LCD data 3
D2, pin PD2 --> LCD R/S
D8, pin PB0 --> LCD R/W
D3, pin PD3 --> LCD E

so you have to change the hardware connection definition in lcd.h appropriately:

#define LCD_PORT PORTD /**< port for the LCD lines */


#define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT PORTB /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN PD5 /**< pin for 4bit data bit 0 */
#define LCD_DATA1_PIN PD6 /**< pin for 4bit data bit 1 */
#define LCD_DATA2_PIN PD7 /**< pin for 4bit data bit 2 */
#define LCD_DATA3_PIN PB0 /**< pin for 4bit data bit 3 */
#define LCD_RS_PORT LCD_PORT /**< port for RS line */
#define LCD_RS_PIN PD2 /**< pin for RS line */
#define LCD_RW_PORT PORTD /**< port for RW line */
#define LCD_RW_PIN PD3 /**< pin for RW line */
#define LCD_E_PORT LCD_PORT /**< port for Enable line */
#define LCD_E_PIN PD4 /**< pin for Enable line */

UART code

There are number of available libraries for AVR UART. I just wrote my own for this project.
Raspberry Pi setup
In the previous part the wireless sensor nodes and the main node were discussed in details. Now
it's time to store the measurements that are collected by the main node and to enable the user to
access them by some means. For this purpose I've connected the main node to the Raspberry Pi
over serial connection. The Raspberry Pi job scheduler periodically starts Python script which
over serial connection gets the available data from the main node and store it to MySQL
database. Apart from that, I installed Apache Web server on Raspberry Pi to enable the users to
see the measurements stored in database through appropriate Web site.

Main node connected to Raspberry Pi with USB serial connection

Hence, Raspberry Pi setup for the home monitoring system consists of the following parts:

 basic Raspberry Pi setup


 MySQL setup
 python script for reading the data from the main node and storing it into MySQL database
 cron setup
 Web server setup

Basic Raspberry Pi setup

There are several available distributions for Raspberry Pi. I am currently using Raspbian (Debian
Wheezy). Assuming that you have working installation on SD card of your Raspberry Pi, you
have to find the way how to log in into Raspberry Pi OS. I prefer using SSH to log in Raspberry
Pi. Once you are in, make sure that you have latest stable version of the already installed
packages by running the following commands:

sudo apt-get update


sudo apt-get upgrade

MySQL setup

Now you can install packages regarding MySQL. The following command installs MySQL
database along with the package that provide module for MySQL database connections directly
from PHP scripts:

sudo apt-get install mysql-server php5-mysql

You will be prompted for the root password for MySQL database. Remeber it because you will
use it for database administration. After completing the installation, see if the MySQL is running:

sudo service mysql status

Similarly, if you want to start/stop/restart the MySQL server use one of the following commands:

sudo service mysql start


sudo service mysql stop
sudo service mysql restart

Now you can log to your MySQL server with the root account. We need to make one database
that contains two tables. If you are not familiar with the MySQL language then it would be wise to
check the tutorial (like this one) before proceeding. Log in to MySQL shell with the root account:

sudo mysql -u root -p

Make the database "sensors" where we are going to store the informations regarding home
system monitoring:

CREATE DATABASE sensors;

Make sure you have created the database "sensor" by running the following command:

SHOW DATABASES;

Now we are going to make the two tables in "sensors" database. One table ("sensorInfo") will
contain the information about available sensors in our wireless sensor network. These are:
unique sensor id (I used numbers 1, 2, 3, ...), physical value that sensor measures (e.g.
temperature, humidity, energy consumption and so on), unit of measurement (like degrees C,
m3/s, ...) and location of the sensor (kitchen, living room, garage, ...). To make the table with
these columns simply run the folowing commands in MySQL shell:

USE sensors;
CREATE TABLE sensorInfo( sensor_id INT NOT NULL AUTO_INCREMENT, measurement VARCHA
R(50) NOT NULL, unit VARCHAR(50) NOT NULL, location VARCHAR(50) NOT NULL, PRIMARY
KEY ( sensor_id ));
Hereby, you can insert information about each of yours wireless sensors with the command
INSERT like in the following example:

INSERT INTO sensorInfo (measurement, unit, location) VALUES ( "humidity","%","livi


ng room");

In my case, this table has three entries:

mysql> select * from sensorInfo;


+-----------+-------------+-----------+-------------+
| sensor_id | measurement | unit | location |
+-----------+-------------+-----------+-------------+
| 1 | Temperature | degrees C | living room |
| 2 | Humidity | % | living room |
| 3 | Temperature | degrees C | balcony |
+-----------+-------------+-----------+-------------+
3 rows in set (0.00 sec)

Other table ("sensorData") stores the actual measurements which are periodically read from the
main node. Therefore, this table should have the following columns: value of the measurement,
appropriate id of the sensor, time and date when the data are read from the main node. Run the
following command in MySql shell to make the table with this columns:

CREATE TABLE sensorData(measurement_id INT NOT NULL AUTO_INCREMENT,


sensor_id INT NOT NULL, date DATE NOT NULL DEFAULT CURDATE(), time TIME NOT NULL D
EFAULT CURTIME(), value varchar(50), PRIMARY KEY ( measurement_id ));

The last thing to do in MySQL shell is to make another MySQL user under name "logger" which
can insert and retrieve the data from database "sensors". Since we will insert the data from
python script which runs on the same machine as MySQL server and later we will use PHP
scripts to retrieve the data which are again ran from the same machine, it is wise from security
aspects to enable this user to connect only from localhost. Additional security measure is to
enable this user only to INSERT or SELECT entries from the database:

GRANT INSERT,SELECT ON SENSORS.* TO 'logger'@'localhost' IDENTIFIED BY 'password'


;
FLUSH PRIVILEGES;

where "password" string should be replaced with the desired password for this user.

Python script for reading and storing the data

Connect the main node to the Raspberry Pi with the USB cable. Make sure that the connection is
correctly recognized by the Raspberry Pi OS:
lsusb -t

My node is sometimes not recognized so I pull the cable out from Raspberry Pi and attach it
again. When the serial port is recognized, it will be listed in /dev directory. Check the name of
the serial port by running the following command:

ls -la /dev/tty*

My Arduino Uno port is recognized as /dev/ttyACM0, but if you have another Arduino board with
different USB to serial chip it can appear as /dev/ttyUSB0.

Once you have the working serial connection, you can read the data from the main node. For this
purpose I installed pySerial, Python library for serial communication:

sudo apt-get install python-serial

You will need Python library for MySQL in order to store the data to database via Python:

sudo apt-get install python-mysqldb

Now we have all necessary libraries to make some code that will read the data from main node,
parse it and store it to MySQL. I will explain only some of the importan parts (the full hms.py script
can be obtained here). The script at first opens the appropriate serial port:

try:
ser = serial.Serial('/dev/ttyACM0',57600,timeout=1) except Exception, e:
print "Date: %s Time: %s Error open serial port: " % \ (time.strftime("%Y-%m-%
d"),time.strftime("%H:%M")) + str(e)
sys.exit(1)

and then makes the request for the data by sending character 'P' to the main node:

ser.write('P')
paket = ser.readline()

The received data from the main node are now in variable "paket" (see Part I for the structure of
the packets that main node sends on request). For the received data ("paket") CRC is calculated
in order to see if we got some errors during serial transmission:

(crcrez, measurement) = parsePacket(paket)

If the packet is errorless, the variable "measurement" contains the wireless sensor
measurements that are first separated and inserted in the table "sensorData" of database
"sensors":

insertDB(measurement)
Cron setup

Basically we want to periodically execute hms.py. For this purpose I used cron - time-based job
scheduler in Unix-like computer operating systems. It allows system to perform different
operations at certain time or at specified time interval. To add the job to the cron you have to
define it in the cron table called crontab. Therefore, open crontab by running the following
command:

sudo crontab -e

I wanted the script to be executed every 5 minutes. Additionally, it is wise to log some of the
errors that we catch in our python script. This can be accomplished by placing the following line
at the end of the crontab fie.

*/5 * * * * python /home/pi/hms.py >> /home/pi/monitoring.log 2>&1

After editing the crontab file you should restart the cron service:

sudo /etc/init.d/cron restart

Web server setup

To deliver web pages to the clients you need to install web server on your Raspberry Pi. There
are several choices for the web server, I am currently using Apache web server. To install
Apache on your Raspberry Pi, run the following command:

sudo apt-get install apache2 php5 libapache2-mod-php5

Now restart the server:

sudo service apache2 restart

and in a second your web server is running a default site (static html page with text: "It works!").
This web page is stored on Raspberry Pi, more precisely in file /var/www/index.html. Here you
can make web pages that will show recorded measurements of your home monitoring system
(see Part III).

Usually, Raspberry Pi is connected to the home network. In that case you can access web pages
from local network machines simply by typing Pi local IP address into the Web browser address
bar. However, if you want to enable access to the web server from outside, then you need to
forward port 80 in home router to the Raspberry Pi. In that way you can access web sites on your
Pi by typing your home IP address into the browser address bar. Since this IP address can
change sometimes, you should consider running some kind of dynamis dns service for your
Raspberry Pi.
Data visualization
So, at this point you should have python script which is periodically executed and which
populates MySQL database with the sensor readings of the wireless sensor nodes. To produce
web pages on your Raspberry Pi, appropriate web server have to be installed on it (check Part
II if you are not sure what I am talking about). Now we would like to make some nice visualisation
of the recorded data. For this purpose you will need some basic knowledge about (visit the
external links for tutorials on each technology):

 HTML
 PHP
 Javascript and jQuery
 Ajax

The basic idea is to use PHP to get the data from the database and then to use
Javascript Rgraph library to draw the graphs (see image below). On the resulting Web page the
user should be able to select one of the available sensors from the database and the desired
time span for which readings will be displayed. To get the feeling about the final results, you can
check the visualisation page for this project.

Simple php functions are used for fetching the data from MySQL database. As already explained
in Part II, there are two tables in our database "sensors". First table, "sensorInfo", stores the
information about sensors (unique id of each wireless sensor, physical value which it measures,
measurement unit and the location of the sensor). These informations are used in drop down
menu generation from which user selects the particular sensor.

<?php
function sensorInfo(){

$dbhandle = mysql_connect($hostname, $username, $password)


or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db($database,$dbhandle)
or die("Could not select database");

//query and make drop down menu in html


echo '<label for="selectedSensor">Sensor: </label>';
if(mysql_num_rows($sql)){
$select= '<select id="selectedSensor"><option value="">Pleas
e select</option>';
while($rs=mysql_fetch_array($sql))
{
$select.='<option value="'.$rs['sensor_id'].'">'.$rs['measurement'].
' ['.$rs['unit'].'] '.$rs['location'].'</option>';
}
}
$select.='</select>'
echo $select;
}
?>

Apart from the particular sensors, the user should be able to select particular time span which he
wants to be displayed. However, we have to enable the user to select only the range that is
available in database. The following php function gets time and date value of first and last entry
in our table "sensorData":

<?php
function getFirstLastTimeDate($what){

//connect to database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

$selected = mysql_select_db($database,$dbhandle)
or die("Could not select database");

//get first entry in database


$sql1=mysql_query("SELECT date, time from sensorData order by measurement_id a
sc limit 1");
$rs1=mysql_fetch_array($sql1);

//get last entry in database


$sql2=mysql_query("SELECT date, time from sensorData order by measurement_id d
esc limit 1");
$rs2=mysql_fetch_array($sql2);

//just for printing info about available range on web site


if($what==0){
$info = "<p>Measurements available from: '.$rs1['date'].' '.$rs1['time'].' t
o: '.$rs2['date'].' '.$rs2['time'].'</p>';
echo $info;
}

//return date of first entry


if($what==1)
echo $rs1["date"];

//return date of last entry


if($what==2)
echo $rs2["date"];
}
?>

Above functions provide information about sensor and the available time span of measurements
in MySQL database. The following php file sensor_data.php actually gets the requested
measurements from the database. However, since the graph of the measurements has to be
updated when user changes time span or sensor, this code is called from javascript by ajax
request. Since it is called from javascript, the sensor_data.php has to return json type of data in
order to enable further manipulation of the fetched data in the javascipt.

<?php
$sensor = $_GET['sensorid'];
$stopdate = $_GET['stopdate'];
$startdate = $_GET['startdate'];

//connection to the database


$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db($database,$dbhandle)
or die("Could not select examples");

$result = mysql_query("SELECT * FROM sensorData WHERE


sensor_id=".$sensor ." AND date BETWEEN '".$startdate ."' AND
'".$stopdate ."'");

$myjsons = array();
while($row = mysql_fetch_assoc($result))
{
$myjsons[] = $row;
}
echo json_encode($myjsons);

mysql_close($dbhandle);
?>

On a client side, javascript library Rgraph is used to produce the graphs of the fetched data. So,
for example, in body of our index.html following lines are needed which include necessary
javascript librabries for drawing graphs:

<script type="text/javascript" src="yourpath/RGraph.common.core.js" ></script>


<script type="text/javascript" src="yourpath/RGraph.line.js" ></script>

Using jQuery can help you in coding javascript, so it's wise to include it too:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></s
cript>

Now we will make parts of the site where user can select what he wants to be displayed. First we
will make the drop down menu which contains sensors from the database and print information
about availabe time span of measurements in database. This is simply done by calling already
written php functions in body part of index.html:

<?php
sensorInfo();
getFirstLastTimeDate(0);
?>
To enable user to select the desired time span, the following form is used which is of date type. If
using modern browser (which supports this type of form), the user will get small calendar where
he can select desired start and stop date:

<form>Start date:<input id="startdate" name="start" value="<?php getFirstLastTimeD


ate(1); ?>" min="<?php getFirstLastTimeDate(1); ?>" max="<?php getFirstLastTimeDat
e(2); ?>" type="date"></form>

<form>Stop date:<input id="stopdate" name="stop" value="<?php getFirstLastTimeDate


(2); ?>" min="<?php getFirstLastTimeDate(1); ?>" max="<?php getFirstLastTimeDate(2
); ?>" type="date"></form>

I added small checkbox to the site. If the user checks it, then the selection from the drop down
menu will be displayed with the previous ones (this is useful if you want to compare
measurements of the two or more sensors):

<form>
<input type="checkbox" id="ansHoldOn" disabled="true">Hold on<br>
</form>

The following javascipt code actually draws the graph, checks what did user select for the time
span and make ajax request to get the desired data from the database:

<script>
var text;

//draw the graph when user selects the sensor from the drop down menu
$("#selectedSensor").on("change", function(){
if($(this).val()!='')
drawGraph();
});

//if user changes stop date clear the graph and check the span
$("#stopdate").on("change", function(){
var canvas = document.getElementById('cvs');
RGraph.Clear(canvas);
$(selectedSensor).val('');
$("#ansHoldOn").attr("disabled", true);
$("#ansHoldOn").attr("checked", false);
if($('#stopdate').val()<$('#startdate').val()){
alert('wrong range!');
}
});

//if user changes start date clear the graph and check the span
$("#startdate").on("change", function(){
var canvas = document.getElementById('cvs');
RGraph.Clear(canvas);
$(selectedSensor).val('');
$("#ansHoldOn").attr("disabled", true);
$("#ansHoldOn").attr("checked", false);
if($('#stopdate').val()<$('#startdate').val()){
alert('wrong range!');
}
});

function drawGraph(){

$("#ansHoldOn").attr("disabled", false);
var selected = $('#selectedSensor').val();
var start = $('#startdate').val();
var stop = $('#stopdate').val();

$.ajax({
type: "GET",
url: "includes/sensordata.php",
data: { 'sensorid': selected, 'startdate' :
start, 'stopdate' : stop},
async: false,
timeout: 5000,
dataType: 'json',
error: function(){
alert("Oops can't fetch the data!");
},
success: function(msg){

if(!$('#ansHoldOn').is(':checked'
))
text = "[";
else
text += ", [";

for (var i = 0; i < msg.length-1;


i++)
text += msg[i].value +
", ";

text += msg[msg.length-1].value +
"]";
}
});

var canvas = document.getElementById('cvs');


RGraph.Clear(canvas);

if($('#ansHoldOn').is(':checked'))
var proba = '[' + text + ']';
else
var proba = text;

chart = new RGraph.Line('cvs', eval(proba))


.set('background.grid.autofit', true)
.set('gutter.left', 35)
.set('gutter.right', 5)
.set('hmargin', 10)
.set('tickmarks', 'endcircle')
.draw();

proba ="";
}

</script>

You can see the final result here. This is of course just a basic visualisation of the
measurements. You can try to make other graphs which are availabe within Rgraph library, add
labels to the x-axis, tooltips and so on.

You might also like