Ws2300 - scripts RRDTool

De MicElectroLinGenMet.

Sommaire

Scripts Shell pour générer des graphiques de la station météo Ws2300 avec RRDTool

Voir pages:


Création de la base RRD

Script à lancer 1 seul fois.

#!/bin/bash
rrdtool create ws2300.rrd \
	--step 300 \
	DS:temp_in:GAUGE:600:-10:60 \
	DS:temp_out:GAUGE:600:-30:70 \
	DS:dewpoint:GAUGE:600:-100:100 \
	DS:rel_hum_in:GAUGE:600:0:100 \
	DS:rel_hum_out:GAUGE:600:0:100 \
	DS:windspeed:GAUGE:600:0:200 \
	DS:wind_angle:GAUGE:600:0:360 \
	DS:wind_chill:GAUGE:600:-100:100 \
	DS:rain_1h:GAUGE:600:0:1000 \
	DS:rain_24h:GAUGE:600:0:1000 \
	DS:rain_total:GAUGE:600:0:2500 \
	DS:rel_pressure:GAUGE:600:300:1100 \
        RRA:AVERAGE:0.5:1:600  \
	RRA:AVERAGE:0.5:6:600   \
	RRA:AVERAGE:0.5:24:600  \
	RRA:AVERAGE:0.5:288:600


Mise à jour de la base RRD à partir d'une base MySql

Les données sont enregistrées dans une base MySql avec le programme Open2300:

/usr/local/bin/mysql2300


Ci-dessous script Perl de mise à jour RRD lancé toutes le 5 mn en crontab:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * ~/bin/ws2300/rrd/rrd-update-ws2300.pl

Les données sont lus dans la base MySql pour être insérées dans la base RRD.


#!/usr/bin/perl
use DBI ;
use Time::Local ;
 
# DBI.pm API
# http://www.hk8.org/old_web/linux/sql/ch21_02.htm
 
# Attend x secondes la maj base de donnée.
sleep 15 ;
 
# Paramètres base MySql ;
my $mysqlpwfile = "mysql.txt" ;
open(MYSQLPWFILE, $mysqlpwfile) || die "Erreur ouverture fichier $mysqlpwfile : $!\n";
my @mysqlpw = <MYSQLPWFILE> ;
close(MYSQLPWFILE) ;
chomp($mysqlpw[0]) ;	# Supprime 'saut de ligne'.
my $db = "meteo";
my $SQL_Driver = "mysql";
my $SQL_User = "root";
my $SQL_Passw = $mysqlpw[0] ;
my $database = DBI->connect("DBI:$SQL_Driver:$db", $SQL_User, $SQL_Passw) or die "La connexion n'a pu être établie: $DBI::errstr\n";
 
my $query= $database->prepare("SELECT max(timestamp) FROM ws2300") ;
$query -> execute() ;
my @result = $query->fetchrow_array ;
my $maxtimestamp=$result[0] ;
##printf("Max TIMESTAMP = $maxtimestamp\n") ;
$query->finish ;	
my $query= $database->prepare("SELECT * FROM ws2300 WHERE timestamp=$maxtimestamp") ;
$query -> execute() ;
@result = $query->fetchrow_array ;
 
my $datereleve  = $result[1] ;
my $heurereleve = $result[2] ;
my ($annee_releve, $mois_releve, $jour_releve) = split(/-/, $datereleve) ;
my ($heure_releve, $minute_releve, $secondes_releve) = split(/:/, $heurereleve) ;
my $secondescourantes = time() ;
my $secondesreleves = timelocal($secondes_releve, $minute_releve, $heure_releve, $jour_releve, $mois_releve - 1, $annee_releve);
#print("$secondescourantes $secondesreleves\n") ;
my $diffsecondes = $secondescourantes - $secondesreleves ;
#print("$diffsecondes \n") ;
 
# Si vitesse vent à 0, angle vent mis à "nan"
if ( $result[8] == 0 )
{
	$result[9] = "nan"
}
 
if ( $diffsecondes < 600 )
{
	my $wsrrdfile = "/home/dan/bin/ws2300/rrd/ws2300.rrd" ;
	my $rrdparam = "update " . $wsrrdfile . " N:" . $result[3] . ":" . $result[4] . ":" . $result[5] . ":" . 
							$result[6] . ":" . $result[7] . ":" . $result[8] . ":" . 
							$result[9] . ":" . $result[11] . ":" . $result[12] . ":" .
							$result[13] . ":" . $result[14] . ":" . $result[15] ;
	#printf("$rrdparam \n") ;
	system("/usr/bin/rrdtool $rrdparam") == 0 or die "Echec commande rrdtool: $?\n";
}
else 
{
	if ( $diffsecondes < 1800 )	# N'affiche plus de message aprés 1/2 heure de retard.
	{
		print("Données Ws2300 plus à jour ($diffsecondes s) ! \n") ;
	}
	exit 1
}
 
$query->finish;	
$database->disconnect ;


Génération des graphes

Génère les fichiers graphes dans un répertoire du site Web.
Voir exemple de graphes en page Releves station meteo WS2300 (Les scripts ont évolués depuis ces graphes).

Le graphe "30 heures" est généré en dynamyque dans la page php:

<?
exec("ws2300/rrd/rrd-graph30h-ws2300.sh",$out,$retour);
?>

Les autres graphes (semaine/mois/année) sont générés en crontab:

2 0 * * * ~/bin/ws2300/rrd/rrd-graph168h-ws2300.sh > /dev/null
3 0 * * 0 ~/bin/ws2300/rrd/rrd-graph840h-ws2300.sh > /dev/null
4 0 1 * * ~/bin/ws2300/rrd/rrd-graph8760h-ws2300.sh > /dev/null


Graphes sur 30 heures (~un jour)


Températures sur 30 heures


#!/bin/bash
# fichier rrd
wsrrdfile="ws2300.rrd"
# Repertoire images
wshtmldir="graph"
 
rrdpath="/usr/bin"
date=`date '+%d/%m/%Y %H.%M' -r $wsrrdfile`
 
widthgif=390
heightpng=180
 
i=30
 
# temp_inout ----------------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/temp_inout-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	--title="WS2300 Temperature int./ext." \
	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
	-v "Degre Celsius" \
	DEF:temp1=$wsrrdfile:temp_in:AVERAGE \
	DEF:temp2=$wsrrdfile:temp_out:AVERAGE \
	LINE1:temp1#ff0000:"Int." \
	LINE1:20#a00000  \
	GPRINT:temp1:LAST:"Actuel\: %.1lf" \
	GPRINT:temp1:MIN:"Mini\: %.1lf" \
	GPRINT:temp1:MAX:"Maxi\: %.1lf"\
	GPRINT:temp1:AVERAGE:"Moyen\: %.1lf" \
	LINE1:temp2#ff8000:"Ext." \
	LINE1:0#0000a0  \
	GPRINT:temp2:LAST:"Actuel\: %.1lf" \
	GPRINT:temp2:MIN:"Mini\: %.1lf" \
	GPRINT:temp2:MAX:"Maxi\: %.1lf"\
	GPRINT:temp2:AVERAGE:"Moyen\: %.1lf" \
	COMMENT:"Dernier releve le $date"
 
# temp_in ----------------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/temp_in-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	--title="WS2300 Temperature interieure" \
	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
	-v "Degree Celsius" \
	DEF:temp1=$wsrrdfile:temp_in:AVERAGE \
	LINE1:temp1#ff0000:"Int." \
	LINE1:20#a00000  \
	GPRINT:temp1:LAST:"Actuel\: %.1lf" \
	GPRINT:temp1:MIN:"Mini\: %.1lf" \
	GPRINT:temp1:MAX:"Maxi\: %.1lf"\
	GPRINT:temp1:AVERAGE:"Moyen\: %.1lf" \
	COMMENT:"Dernier releve le $date"
 
# temp_out ---------------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/temp_out-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	--title="WS2300 Temperature exterieure" \
	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
	-v "Degree Celsius" \
	DEF:temp=$wsrrdfile:temp_out:AVERAGE \
	LINE1:temp#ff0000:"Ext." \
	LINE1:0#0000a0  \
	GPRINT:temp:LAST:"Actuel\: %.1lf" \
	GPRINT:temp:MIN:"Mini\: %.1lf" \
	GPRINT:temp:MAX:"Maxi\: %.1lf"\
	GPRINT:temp:AVERAGE:"Moyen\: %.1lf" \
	COMMENT:"Dernier releve le $date" 
 
# rel_hum_out / rel_hum_in ---------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/rel_hum_inout-$i.png  \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	-l 10 -u 100 -r \
	--title="WS2300 - Hygrometrie int./ext." \
	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
	-v "0-100%" \
	DEF:hum1=$wsrrdfile:rel_hum_in:AVERAGE  \
	DEF:hum2=$wsrrdfile:rel_hum_out:AVERAGE \
	LINE1:hum1#1199FF:"Int" \
	LINE1:50#0000A0  \
	GPRINT:hum1:LAST:"Actuel\: %.1lf -" \
	GPRINT:hum1:MIN:"Mini\: %.1lf -" \
	GPRINT:hum1:MAX:"Maxi\: %.1lf -"\
	GPRINT:hum1:AVERAGE:"Moyen\: %.1lf\n" \
	LINE1:hum2#660099:"Ext" \
	GPRINT:hum2:LAST:"Actuel\: %.1lf -" \
	GPRINT:hum2:MIN:"Mini\: %.1lf -" \
	GPRINT:hum2:MAX:"Maxi\: %.1lf -"\
	GPRINT:hum2:AVERAGE:"Moyen\: %.1lf" \
	COMMENT:"Dernier releve le $date" 
 
# rel_pressure -------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/rel_pressure-$i.png \
	-s -$nbsecond \
	-w $(($widthgif - 6)) --height $heightpng \
	-l 970 -u 1040 \
	-r \
	-v "WS2300" \
	--alt-y-grid \
	--title="WS2300 Pression relative"\
	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
	--units-exponent 0 \
	DEF:press=$wsrrdfile:rel_pressure:AVERAGE \
	LINE1:press#00ff00:"hPa"  \
	LINE1:1013#0000FF  \
	GPRINT:press:LAST:"Actuel\: %.0lf" \
	GPRINT:press:MIN:"Mini\: %.0lf" \
	GPRINT:press:MAX:"Maxi\: %.0lf" \
	GPRINT:press:AVERAGE:"Moyen\: %.0lf\n" \
	COMMENT:" \n" \
	COMMENT:" \n" \
	COMMENT:"Dernier releve le $date"
 
# windspeed ----------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/windspeed-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	-X 0 \
	--title="WS2300 - Vitesse du vent" \
	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
	-v 'km/h' \
	--alt-y-grid \
	DEF:ms=$wsrrdfile:windspeed:AVERAGE \
	CDEF:kmh="ms,3.6,*" \
	AREA:kmh#FF9900:"km/h" \
	GPRINT:kmh:LAST:"Actuel\: %.1lf -" \
	GPRINT:kmh:MIN:"Mini\: %.1lf -" \
	GPRINT:kmh:MAX:"Maxi\: %.1lf -"\
	GPRINT:kmh:AVERAGE:"Moyen\: %.1lf" \
	COMMENT:"Dernier releve le $date"
 
# wind_angle ----------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/wind_angle-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	--alt-autoscale-max \
	--title="WS2300 - Direction du vent"  \
	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
	-v 'Angle en degre' \
	DEF:wangl=$wsrrdfile:wind_angle:AVERAGE \
	CDEF:est=wangl,45,134,LIMIT \
	CDEF:sud=wangl,135,224,LIMIT \
	CDEF:ouest=wangl,225,314,LIMIT \
	GPRINT:wangl:LAST:"Actuel\: %.1lf   - " \
	AREA:wangl#0000FF:"Nord" \
	AREA:est#00FF00:"Est" \
	AREA:sud#FF0000:"Sud" \
	AREA:ouest#FFFF00:"Ouest" \
	COMMENT:"Dernier releve le $date"
 
# LINE1:wangl#FF9900:"Dg" \
# CDEF:nord=wangl,45,LT,wangl,0,IF
# en RPN se lira: prendre wangl, prendre 45, wangl inférieur à 45 ?, si oui, retourner wangl, sinon retourner 0.
# CDEF:a=alpha,0,100,LIMIT
# will return unknown if alpha is lower than 0 or if it is higher than 100.
 
# rain_1h/24h ------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/rain_1h24h-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	--alt-autoscale-max \
	--title="WS2300 Pluie sur 1h/24h" \
	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
	-v 'mm - (l/m2)' \
	DEF:pluie1h=$wsrrdfile:rain_1h:AVERAGE \
	DEF:pluie24h=$wsrrdfile:rain_24h:AVERAGE \
	DEF:pluiett=$wsrrdfile:rain_total:AVERAGE \
	AREA:pluie24h#6699FF:"24h" \
	GPRINT:pluie24h:LAST:"Actuel\: %.1lf" \
	GPRINT:pluie24h:MIN:"Mini\: %.1lf" \
	GPRINT:pluie24h:MAX:"Maxi\: %.1lf"\
	GPRINT:pluie24h:AVERAGE:"Moyen\: %.1lf\n" \
	AREA:pluie1h#66CCFF:"1h " \
	GPRINT:pluie1h:LAST:"Actuel\: %.1lf" \
	GPRINT:pluie1h:MIN:"Mini\: %.1lf" \
	GPRINT:pluie1h:MAX:"Maxi\: %.1lf"\
	GPRINT:pluie1h:AVERAGE:"Moyen\: %.1lf\n" \
	GPRINT:pluiett:LAST:"Precipitations sur l'annee\: %.1lfmm\n" \
	COMMENT:"Dernier releve le $date"
 
# rain_total ----------------------------------------------------------------
#let nbsecond=3600*$i
#$rrdpath/rrdtool graph $wshtmldir/rain_total-$i.png \
#	-s -$nbsecond \
#	-w $widthgif -l 0 --height $heightpng \
#	--alt-autoscale-max \
#	--title="WS2300 Pluie cumulee" \
#	-x 'HOUR:1:HOUR:4:HOUR:4:0:%H:00' \
#	-v 'WS2300' \
#	DEF:pluiett=$wsrrdfile:rain_total:AVERAGE \
#	AREA:pluiett#6666FF:"mm" \
#	GPRINT:pluiett:LAST:"Actuel\: %.1lf" \
#	GPRINT:pluiett:MIN:"Mini\: %.1lf" \
#	GPRINT:pluiett:MAX:"Maxi\: %.1lf" \
#	GPRINT:pluiett:AVERAGE:"Moyen\: %.1lf\n" \
#	COMMENT:" \n" \
#	COMMENT:"Dernier releve le $date"
 
exit 0


Graphes sur 168 heures (~1 semaine)


Températures sur 1 semaine


#!/bin/bash
 
# fichier rrd
wsrrdfile="ws2300.rrd"
# Repertoire images
wshtmldir="graph"
 
rrdpath="/usr/bin"
date=`date '+%d/%m/%Y %H.%M' -r $wsrrdfile`
 
widthgif=390
heightpng=180
 
i=168
 
# temp_inout ----------------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/temp_inout-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	--title="WS2300 Temperature int./ext." \
	-x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
	-v "Degre Celsius" \
	DEF:temp1=$wsrrdfile:temp_in:AVERAGE \
	DEF:temp2=$wsrrdfile:temp_out:AVERAGE \
	LINE1:temp1#ff0000:"Int." \
	LINE1:20#a00000  \
	GPRINT:temp1:LAST:"Actuel\: %.1lf" \
	GPRINT:temp1:MIN:"Mini\: %.1lf" \
	GPRINT:temp1:MAX:"Maxi\: %.1lf"\
	GPRINT:temp1:AVERAGE:"Moyen\: %.1lf" \
	LINE1:temp2#ff8000:"Ext." \
	LINE1:0#0000a0  \
	GPRINT:temp2:LAST:"Actuel\: %.1lf" \
	GPRINT:temp2:MIN:"Mini\: %.1lf" \
	GPRINT:temp2:MAX:"Maxi\: %.1lf"\
	GPRINT:temp2:AVERAGE:"Moyen\: %.1lf" \
	COMMENT:"Dernier releve le $date"
 
# temp_in ----------------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/temp_in-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	  --title="Temperature interieure $date" -v "WS2300" \
	  -x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
         DEF:temp1=$wsrrdfile:temp_in:AVERAGE \
          LINE1:temp1#ff0000:"Température (Degree Celsius)" \
	  LINE1:20#a00000  
# 86400 = nb secondes dans un jour => Position du texte.
 
# temp_out ---------------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/temp_out-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	  --title="Temperature exterieure $date" -v "WS2300" \
	  -x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
	  DEF:temp=$wsrrdfile:temp_out:AVERAGE \
          LINE1:temp#ff0000:"Température (Degree Celsius)" \
	  LINE1:0#0000a0  
 
# rel_hum_out / rel_hum_in ---------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rel_hum_inout-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	-l 10 -u 90 \
	-r \
	  --title="Hygrometrie int./ext. $date" -v "WS2300" \
	  -x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
          DEF:hum1=$wsrrdfile:rel_hum_in:AVERAGE  \
          DEF:hum2=$wsrrdfile:rel_hum_out:AVERAGE \
          LINE1:hum1#1199FF:"Hygrometrie intérieure" \
	  LINE1:50#0000A0  \
          LINE1:hum2#660099:"extérieure (%)" \
	COMMENT:"Dernier releve le $date"
 
 
# rel_pressure -------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rel_pressure-$i.png \
	-w $widthgif --height $heightpng \
	-s -$nbsecond \
	-l 970 -u 1040 \
	-r  \
	  -v "WS2300" \
	  -x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
	  --alt-y-grid \
	  --title="Pression relative $date"\
          --units-exponent 0 \
          DEF:press=$wsrrdfile:rel_pressure:AVERAGE \
          LINE1:press#00ff00:"Pression (hPa)"  \
          LINE1:1015#0000FF   \
	COMMENT:"Dernier releve le $date"
 
# windspeed ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/windspeed-$i.png \
	-s -$nbsecond \
	-X 0 \
	-w $widthgif --height $heightpng \
	  --title="Vitesse du vent $date"  -v 'WS2300' \
	  -x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
	  --alt-y-grid \
          DEF:ms=$wsrrdfile:windspeed:AVERAGE \
	  CDEF:kmh="ms,3.6,*" \
          AREA:kmh#FF9900:"Vent (km/h)" \
	COMMENT:"Dernier releve le $date"
 
 
# wind_angle ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/wind_angle-$i.png  \
	-s -$nbsecond \
	--alt-autoscale-max \
	-w $widthgif --height $heightpng \
	  --title="Direction du vent $date"  -v 'WS2300' \
	  -x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
          DEF:wangl=$wsrrdfile:wind_angle:AVERAGE \
	  CDEF:est=wangl,45,135,LIMIT \
	  CDEF:sud=wangl,135,225,LIMIT \
	  CDEF:ouest=wangl,225,315,LIMIT \
	  AREA:wangl#0000FF:"Nord" \
	  AREA:est#00FF00:"Est" \
	  AREA:sud#FF0000:"Sud" \
	  AREA:ouest#FFFF00:"Ouest" \
	COMMENT:"Dernier releve le $date"
 
#          LINE1:wangl#FF9900:"Dg" \
# CDEF:nord=wangl,45,LT,wangl,0,IF
# en RPN se lira: prendre wangl, prendre 45, wangl inférieur à 45 ?, si oui, retourner wangl, sinon retourner 0.
# CDEF:a=alpha,0,100,LIMIT
# will return unknown if alpha is lower than 0 or if it is higher than 100.
 
# rain_1h/24h ------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rain_1h24h-$i.png \
	-s -$nbsecond \
	--alt-autoscale-max \
	-w $widthgif --height $heightpng \
	  --title="Pluie sur 1h/24h - $date" -v 'WS2300' \
	  -x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
          DEF:pluie1h=$wsrrdfile:rain_1h:AVERAGE \
          DEF:pluie24h=$wsrrdfile:rain_24h:AVERAGE \
	  AREA:pluie24h#6699FF:"Pluie sur 24h (mm - l/m2) " \
	  AREA:pluie1h#66CCFF:"sur 1h (mm - l/m2)" \
	COMMENT:"Dernier releve le $date"
 
# rain_total ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rain_total-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	  -l 0 --alt-autoscale-max \
	  -x 'HOUR:6:DAY:1:DAY:1:86400:%a %d' \
	  --title="Pluie cumulee $date" \
	  -v 'WS2300' \
          DEF:pluiett=$wsrrdfile:rain_total:AVERAGE \
          AREA:pluiett#6666FF:"Pluie sur l'année (mm - l/m2)"  \
	COMMENT:"Dernier releve le $date"
 
exit 0


Graphes sur 840 heures (~1 mois)


Températures sur 1 mois


#!/bin/bash
 
# fichier rrd
wsrrdfile="ws2300.rrd"
# Repertoire images
wshtmldir="graph"
 
rrdpath="/usr/bin"
date=`date '+%d/%m/%Y %H.%M' -r $wsrrdfile`
 
widthgif=390
heightpng=180
 
i=840
 
# temp_inout ----------------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/temp_inout-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	--title="WS2300 Temperature int./ext." \
	-v "Degre Celsius" \
	DEF:temp1=$wsrrdfile:temp_in:AVERAGE \
	DEF:temp2=$wsrrdfile:temp_out:AVERAGE \
	LINE1:temp1#ff0000:"Int." \
	LINE1:20#a00000  \
	GPRINT:temp1:LAST:"Actuel\: %.1lf" \
	GPRINT:temp1:MIN:"Mini\: %.1lf" \
	GPRINT:temp1:MAX:"Maxi\: %.1lf"\
	GPRINT:temp1:AVERAGE:"Moyen\: %.1lf" \
	LINE1:temp2#ff8000:"Ext." \
	LINE1:0#0000a0  \
	GPRINT:temp2:LAST:"Actuel\: %.1lf" \
	GPRINT:temp2:MIN:"Mini\: %.1lf" \
	GPRINT:temp2:MAX:"Maxi\: %.1lf"\
	GPRINT:temp2:AVERAGE:"Moyen\: %.1lf" \
	COMMENT:"Dernier releve le $date"
 
# temp_in ----------------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/temp_in-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	  --title="Temperature interieure $date" -v "WS2300" \
          DEF:temp1=$wsrrdfile:temp_in:AVERAGE \
          LINE1:temp1#ff0000:"Température (Degree Celsius)" \
	  LINE1:20#a00000  
 
# temp_out ---------------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/temp_out-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	  --title="Temperature exterieure $date" -v "WS2300" \
	  DEF:temp=$wsrrdfile:temp_out:AVERAGE \
          LINE1:temp#ff0000:"Température (Degree Celsius)" \
	  LINE1:0#0000a0  
 
# rel_hum_out / rel_hum_in ---------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rel_hum_inout-$i.png \
	-s -$nbsecond \
	-l 10 -u 90 \
	-r \
	-w $widthgif --height $heightpng \
	  --title="Hygrometrie int./ext. $date" -v "WS2300" \
          DEF:hum1=$wsrrdfile:rel_hum_in:AVERAGE  \
          DEF:hum2=$wsrrdfile:rel_hum_out:AVERAGE \
          LINE1:hum1#1199FF:"Hygrometrie intérieure" \
	  LINE1:50#0000A0  \
          LINE1:hum2#660099:"extérieure (%)" 
 
# rel_pressure -------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rel_pressure-$i.png -s \
	-$nbsecond \
	-l 970 -u 1040 \
	-r  \
	-w $widthgif --height $heightpng \
	  -v "WS2300" \
	  --alt-y-grid \
	  --title="Pression relative $date"\
          --units-exponent 0 \
          DEF:press=$wsrrdfile:rel_pressure:AVERAGE \
          LINE1:press#00ff00:"Pression (hPa)"  \
          LINE1:1015#0000FF  \
	  COMMENT:" "
 
# windspeed ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/windspeed-$i.png \
	-s -$nbsecond \
	-X 0 \
	-w $widthgif --height $heightpng \
	  --title="Vitesse du vent $date"  -v 'WS2300' \
	  --alt-y-grid \
          DEF:ms=$wsrrdfile:windspeed:AVERAGE \
	  CDEF:kmh="ms,3.6,*" \
          AREA:kmh#FF9900:"Vent (km/h)" 
 
# wind_angle ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/wind_angle-$i.png \
	-s -$nbsecond \
	--alt-autoscale-max \
	-w $widthgif --height $heightpng \
	  --title="Direction du vent $date"  -v 'WS2300' \
          DEF:wangl=$wsrrdfile:wind_angle:AVERAGE \
	  CDEF:est=wangl,45,135,LIMIT \
	  CDEF:sud=wangl,135,225,LIMIT \
	  CDEF:ouest=wangl,225,315,LIMIT \
	  AREA:wangl#0000FF:"Nord" \
	  AREA:est#00FF00:"Est" \
	  AREA:sud#FF0000:"Sud" \
	  AREA:ouest#FFFF00:"Ouest"
#          LINE1:wangl#FF9900:"Dg" \
# CDEF:nord=wangl,45,LT,wangl,0,IF
# en RPN se lira: prendre wangl, prendre 45, wangl inférieur à 45 ?, si oui, retourner wangl, sinon retourner 0.
# CDEF:a=alpha,0,100,LIMIT
# will return unknown if alpha is lower than 0 or if it is higher than 100.
 
# rain_1h/24h ------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rain_1h24h-$i.png \
	-s -$nbsecond \
	--alt-autoscale-max \
	-w $widthgif --height $heightpng \
	  --title="Pluie sur 1h/24h - $date" -v 'WS2300' \
          DEF:pluie1h=$wsrrdfile:rain_1h:AVERAGE \
          DEF:pluie24h=$wsrrdfile:rain_24h:AVERAGE \
	  AREA:pluie24h#6699FF:"Pluie sur 24h (mm - l/m2) " \
	  AREA:pluie1h#66CCFF:"sur 1h (mm - l/m2)" 
#	  COMMENT:"Dernier relevé $wsdate"
 
# rain_total ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rain_total-$i.png \
	-w $widthgif --height $heightpng \
	-s -$nbsecond \
	  -l 0 --alt-autoscale-max \
	  --title="Pluie cumulee $date" \
	  -v 'WS2300' \
          DEF:pluiett=$wsrrdfile:rain_total:AVERAGE \
          AREA:pluiett#6666FF:"Pluie sur l'année (mm - l/m2)" \
	  COMMENT:" "
 
exit 0


Graphes sur 8760 heures (~1 an)


Températures sur 1 an


#!/bin/bash
 
# fichier rrd
wsrrdfile="ws2300.rrd"
# Repertoire images
wshtmldir="graph"
 
rrdpath="/usr/bin"
date=`date '+%d/%m/%Y %H.%M' -r $wsrrdfile`
 
widthgif=390
heightpng=180
i=8760
 
# temp_inout ----------------------------------------------------------------------
let nbsecond=3600*$i
$rrdpath/rrdtool graph $wshtmldir/temp_inout-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	--title="WS2300 Temperature int./ext." \
	-v "Degre Celsius" \
	DEF:temp1=$wsrrdfile:temp_in:AVERAGE \
	DEF:temp2=$wsrrdfile:temp_out:AVERAGE \
	LINE1:temp1#ff0000:"Int." \
	LINE1:20#a00000  \
	GPRINT:temp1:LAST:"Actuel\: %.1lf" \
	GPRINT:temp1:MIN:"Mini\: %.1lf" \
	GPRINT:temp1:MAX:"Maxi\: %.1lf"\
	GPRINT:temp1:AVERAGE:"Moyen\: %.1lf" \
	LINE1:temp2#ff8000:"Ext." \
	LINE1:0#0000a0  \
	GPRINT:temp2:LAST:"Actuel\: %.1lf" \
	GPRINT:temp2:MIN:"Mini\: %.1lf" \
	GPRINT:temp2:MAX:"Maxi\: %.1lf"\
	GPRINT:temp2:AVERAGE:"Moyen\: %.1lf" \
	COMMENT:"Dernier releve le $date"
 
# temp_in ----------------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/temp_in-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	  --title="Temperature interieure $date" -v "WS2300" \
          DEF:temp1=$wsrrdfile:temp_in:AVERAGE \
          LINE1:temp1#ff0000:"Température (Degree Celsius)" \
	  LINE1:20#a00000  
 
# temp_out ---------------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/temp_out-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	  --title="Temperature exterieure $date" -v "WS2300" \
	  DEF:temp=$wsrrdfile:temp_out:AVERAGE \
          LINE1:temp#ff0000:"Température (Degree Celsius)" \
	  LINE1:0#0000a0 \
	COMMENT:"Dernier releve le $date"  
 
# rel_hum_out / rel_hum_in ---------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rel_hum_inout-$i.png \
	-s -$nbsecond \
	-l 10 -u 90 \
	-r \
	-w $widthgif --height $heightpng \
	  --title="Hygrometrie int./ext. $date" -v "WS2300" \
          DEF:hum1=$wsrrdfile:rel_hum_in:AVERAGE  \
          DEF:hum2=$wsrrdfile:rel_hum_out:AVERAGE \
          LINE1:hum1#1199FF:"Hygrometrie intérieure" \
	  LINE1:50#0000A0  \
          LINE1:hum2#660099:"extérieure (%)" \
	COMMENT:"Dernier releve le $date" 
 
# rel_pressure -------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rel_pressure-$i.png \
	-s -$nbsecond \
	-l 980 -u 1040 \
	-r  \
	-w $widthgif --height $heightpng \
	  -v "WS2300" \
	  --alt-y-grid \
	  --title="Pression relative $date"\
          --units-exponent 0 \
          DEF:press=$wsrrdfile:rel_pressure:AVERAGE \
          LINE1:press#00ff00:"Pression (hPa)"  \
          LINE1:1015#0000FF \
	COMMENT:"Dernier releve le $date"
 
# windspeed ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/windspeed-$i.png \
	-s -$nbsecond \
	-X 0 \
	-w $widthgif --height $heightpng \
	  --title="Vitesse du vent $date"  -v 'WS2300' \
	  --alt-y-grid \
          DEF:ms=$wsrrdfile:windspeed:AVERAGE \
	  CDEF:kmh="ms,3.6,*" \
          AREA:kmh#FF9900:"Vent (km/h)" \
	COMMENT:"Dernier releve le $date" 
 
# wind_angle ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/wind_angle-$i.png \
	-s -$nbsecond \
	--alt-autoscale-max \
	-w $widthgif --height $heightpng \
	  --title="Direction du vent $date"  -v 'WS2300' \
          DEF:wangl=$wsrrdfile:wind_angle:AVERAGE \
	  CDEF:est=wangl,45,135,LIMIT \
	  CDEF:sud=wangl,135,225,LIMIT \
	  CDEF:ouest=wangl,225,315,LIMIT \
	  AREA:wangl#0000FF:"Nord" \
	  AREA:est#00FF00:"Est" \
	  AREA:sud#FF0000:"Sud" \
	  AREA:ouest#FFFF00:"Ouest" \
	COMMENT:"Dernier releve le $date"
#          LINE1:wangl#FF9900:"Dg" \
# CDEF:nord=wangl,45,LT,wangl,0,IF
# en RPN se lira: prendre wangl, prendre 45, wangl inférieur à 45 ?, si oui, retourner wangl, sinon retourner 0.
# CDEF:a=alpha,0,100,LIMIT
# will return unknown if alpha is lower than 0 or if it is higher than 100.
 
# rain_1h/24h ------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rain_1h24h-$i.png \
	-s -$nbsecond \
	--alt-autoscale-max \
	-w $widthgif --height $heightpng \
	  --title="Pluie sur 1h/24h - $date" -v 'WS2300' \
          DEF:pluie1h=$wsrrdfile:rain_1h:AVERAGE \
          DEF:pluie24h=$wsrrdfile:rain_24h:AVERAGE \
	  AREA:pluie24h#6699FF:"Pluie sur 24h (mm - l/m2) " \
	  AREA:pluie1h#66CCFF:"sur 1h (mm - l/m2)"  \
	COMMENT:"Dernier releve le $date"
 
# rain_total ----------------------------------------------------------------
	let nbsecond=3600*$i
	$rrdpath/rrdtool graph $wshtmldir/rain_total-$i.png \
	-s -$nbsecond \
	-w $widthgif --height $heightpng \
	  -l 0 --alt-autoscale-max \
	  --title="Pluie cumulee $date" \
	  -v 'WS2300' \
          DEF:pluiett=$wsrrdfile:rain_total:AVERAGE \
          AREA:pluiett#6666FF:"Pluie sur l'année (mm - l/m2)" \
	COMMENT:"Dernier releve le $date"
 
exit 0