Teleinfo - scripts RRDTool
De MicElectroLinGenMet.
Version du 30 juin 2009 à 10:11 par Dan (discuter | contributions)
Sommaire |
Scripts Shell pour générer des graphiques Téléinfo. avec RRDTool
Voir la Téléinfo. en page: Demodulateur teleinformation EDF
Création de la base RRD
Script à lancer 1 seul fois.
#!/bin/bash # rrd-create-teleinfo.sh # fichier rrd rrdfile="~/bin/teleinfo/rrd/teleinfo.rrd" rrdtool create $rrdfile \ --step 60 \ DS:HCHC:COUNTER:120:U:U \ DS:HCHP:COUNTER:120:U:U \ DS:PTEC:GAUGE:120:U:U \ DS:IINST1:GAUGE:120:U:U \ DS:IINST2:GAUGE:120:U:U \ DS:IINST3:GAUGE:120:U:U \ DS:PAPP:GAUGE:120:U:U \ RRA:AVERAGE:0.5:1:1920 \ RRA:AVERAGE:0.5:6:1920 \ RRA:AVERAGE:0.5:24:1920 \ RRA:AVERAGE:0.5:288:1920
Mise à jour de la base RRD
A lancer toutes le 5 mn en crontab:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * ~/bin/teleinfo/rrd/rrd-update-teleinfo.sh
- A partir d'un fichier LOG
#!/bin/bash # rrd-update-teleinfo.sh # fichier rrd rrdfile="~/bin/teleinfo/rrd/teleinfo.rrd" tail -1 ~/tmp/teleinfo.log | while read DATE TIME HCHC HCHP PTEC IINST1 IINST2 IINST3 PAPP do if [ "$PTEC" = "HP" ] then PTEC=1 else PTEC=0 fi /usr/bin/rrdtool update $rrdfile N:$HCHC:$HCHP:$PTEC:$IINST1:$IINST2:$IINST3:$PAPP done
- A partir d'une base MySql
#!/bin/bash # rrd-update-teleinfo.sh # fichier rrd rrdfile="~/bin/teleinfo/rrd/teleinfo.rrd" DATE=$(date '+%s') DATA=$(mysql -s -u root -p$(cat /chemin/mysqlpw.txt) -D maison << ! SELECT timestamp, hchc, hchp, ptec, iinst1, iinst2, iinst3, papp FROM teleinfo ORDER BY timestamp DESC LIMIT 1 ; ! ) if [ $? -ne 0 ] then echo "Erreur accés base MySql maison !" exit 1 fi echo $DATA | while read TIMESTAMP HCHC HCHP PTEC IINST1 IINST2 IINST3 PAPP do DIFFSECONDES=$(( $DATE - $TIMESTAMP )) #echo $DIFFSECONDES if [ $DIFFSECONDES -gt 300 ] then echo "Données plus à jour !" exit 1 fi if [ "$PTEC" = "HP" ] then PTEC=1 else PTEC=0 fi /usr/bin/rrdtool update $rrdfile N:$HCHC:$HCHP:$PTEC:$IINST1:$IINST2:$IINST3:$PAPP done
Génération des graphes
A lancer à la demande. Génère les fichiers graphes dans un répertoire du site Apache.
Voir les graphes en page Demodulateur teleinformation - Scripts RRDTool.
#!/bin/bash # rrd-graph-teleinfo.sh # fichiers rrd rrdfile="~/bin/teleinfo/rrd/teleinfo.rrd" # Repertoire images htmldir="/var/www/teleinfo/graph" rrdpath="/usr/bin" date=`date '+%d/%m/%Y %H:%M'` widthgif=700 hightgif=300 # --- PAPP -------------------------------------------------- let nbsecond=3600*30 $rrdpath/rrdtool graph $htmldir/teleinfo-30-PAPP.png \ -s -$nbsecond \ -x 'HOUR:1:HOUR:3:HOUR:3:0:%H:00' \ --imgformat PNG \ --width $widthgif --height $hightgif \ --title="Puissance instantannée $date" \ -v "Watts" \ -X 0 \ --color CANVAS#000000 \ --color BACK#101010 \ --color FONT#C0C0C0 \ --color MGRID#80C080 \ --color GRID#808020 \ --color FRAME#808080 \ --color ARROW#FFFFFF \ --color SHADEA#404040 \ --color SHADEB#404040 \ DEF:papp=$rrdfile:PAPP:AVERAGE \ DEF:ptec=$rrdfile:PTEC:AVERAGE \ CDEF:papphp=ptec,0,GT,papp,0,IF \ CDEF:papphc=ptec,0,GT,0,papp,IF \ AREA:papphp#FF0000:"PAPP HP" \ AREA:papphc#00FF00:"PAPP HC\n" \ GPRINT:papp:LAST:"Actuel\: %.1lfWh" \ GPRINT:papp:MIN:"Mini\: %.1lfWh" \ GPRINT:papp:MAX:"Maxi\: %.1lfWh" \ GPRINT:papp:AVERAGE:"Moyen\: %.1lfWh" # --- IINST -------------------------------------------------- let nbsecond=3600*30 $rrdpath/rrdtool graph $htmldir/teleinfo-30-IINST.png \ -s -$nbsecond \ -x 'HOUR:1:HOUR:3:HOUR:3:0:%H:00' \ --imgformat PNG \ --width $widthgif --height $hightgif \ --title="Instensité instantannée $date" \ -v "Ampères" \ --color CANVAS#000000 \ --color BACK#101010 \ --color FONT#C0C0C0 \ --color MGRID#80C080 \ --color GRID#808020 \ --color FRAME#808080 \ --color ARROW#FFFFFF \ --color SHADEA#404040 \ --color SHADEB#404040 \ DEF:iinst1=$rrdfile:IINST1:AVERAGE \ DEF:iinst2=$rrdfile:IINST2:AVERAGE \ CDEF:iinst2d="iinst2,10,+" \ DEF:iinst3=$rrdfile:IINST3:AVERAGE \ CDEF:iinst3d="iinst3,20,+" \ LINE2:iinst3d#FF0000:"IINST3:" \ GPRINT:iinst3:LAST:"Actuel\: %.1lfA" \ GPRINT:iinst3:MIN:"Mini\: %.1lfA" \ GPRINT:iinst3:MAX:"Maxi\: %.1lfA" \ GPRINT:iinst3:AVERAGE:"Moyen\: %.1lfA\n" \ LINE2:iinst2d#0000FF:"IINST2:" \ GPRINT:iinst2:LAST:"Actuel\: %.1lfA" \ GPRINT:iinst2:MIN:"Mini\: %.1lfA" \ GPRINT:iinst2:MAX:"Maxi\: %.1lfA" \ GPRINT:iinst2:AVERAGE:"Moyen\: %.1lfA\n" \ LINE2:iinst1#00FF00:"IINST1:" \ GPRINT:iinst1:LAST:"Actuel\: %.1lfA" \ GPRINT:iinst1:MIN:"Mini\: %.1lfA" \ GPRINT:iinst1:MAX:"Maxi\: %.1lfA" \ GPRINT:iinst1:AVERAGE:"Moyen\: %.1lfA\n" \ COMMENT:"Les 3 phases sont décalées de 10A sur le graphe."
