P er la creazione del grafico si è usata la libreria JpGraph ( http://www.aditus.nu/jpgraph/ ) che consente di produrre grafici in PHP in modo molto semplice e flessibile.
Su Ubuntu la libreria si installa comodamente da riga di comando: $ sudo apt-get install libphp-jpgraph all the library files are then installed in the directory / usr / share / jpgraph / PLOTTER.PHP
\u0026lt;? Php
/***** ************************************************** ******************************************
*
* Motivation: builds a graph showing temperatures measured in the last 24hh * * Author: Francesco Parisi (fparisi at tiscali dot it), (fparisi at gmail dot com)
* * Requires: db.php, jpgraph.php , jpgraph_line.php *
*********************************** ************************************************** ************/ require_once
( '/usr/share/jpgraph/jpgraph.php' ); require_once
( '/usr/share/jpgraph/jpgraph_line.php' );
require_once ( 'db.php' );
// Apre la connessione al server $conn =
mysql_connect (
$host , $user , $pass )
or
day ( 'Could not connect to server:' .
mysql_error ());
/ / Select the database $ sel = mysql_select_db ($ dbname ,
$ conn) or
day ( 'Unable to select database:'
. mysql_error ()); / / Temperature latest 24hh
$ sql_last_24hh = 'SELECT * FROM `log` WHERE `time`> = NOW () - INTERVAL 1 DAY' ;
$ res = mysql_query
$ sql_last_24hh )
or
day
(
'Could not execute query:'
.
mysql_error ()); / / Format the timestamp and build the axes for the graph
if ($ row
=
mysql_fetch_assoc ($ res
)
or day
(
mysql_error ())
) {
do
{/ / Convert the timestamp to MySQL timestamp PHP $ timestamp
= strtotime ($ row
[ 'time'
]); / / Construct the vector of times (x axis) $ x [] =
sprintf ( "% s,% s" , dates (
'j / n' , $ timestamp) , dates (
'H: i' , $ timestamp ) ) / / Construct the vector of temperatures (y axis)
$ y [] =
$ row [
'temp_int' ];}
while ($ row =
mysql_fetch_assoc ($ res ) );}
/ / Create the graph $ graph =
new Graph
(
1024 , 800
, "auto" ); $graph ->
SetScale ( "textlin" ); $graph
-> img -> SetMargin (
60 , 40 , 40 ,
110 );
$graph
-> title -> Set
(
'Temperature rilevate nelle ultime 24hh' ); $graph -> title -> SetFont ( FF_FONT2 , FS_BOLD ); $graph -> xaxis -> SetTickLabels
(
$x );
$graph -> xgrid ->
Show
(
true
);
$graph
-> xaxis
->
SetLabelAngle
-> (
90
);
$graph
->
();
// Crea il plot
$lineplot
=
new
LinePlot
( $y
); $lineplot
-> value ->
Show ();
$lineplot ->
SetColor (
"blue" );
$lineplot ->
SetWeight (
2 );
// Two pixel wide $lineplot -> value ->
SetColor ( "darkred" ); $lineplot
-> value -> SetFormat (
"% 0.1F"
) / / $ lineplot-> mark -> settype (MARK_FILLEDCIRCLE)
/ / Add the plot to the graph $ graph -> Add ( $ lineplot )
/ / Show the graph $ graph -> Stroke (); / / Close connection
mysql_close ($ conn ) or day ( 'Could not close connection:'
. mysql_error ()); ?> Here's an example of generated chart (click on it to enlarge), which is then drawn into the web page:
.
}
) this should be removed because it conflicts with the FTDI driver.
you are ready for testing hardware ...