diff --git a/controller/current_cost/README b/controller/current_cost/README new file mode 100644 index 0000000..010d0c2 --- /dev/null +++ b/controller/current_cost/README @@ -0,0 +1,5 @@ +Koeln, 16.09.2010 +Weitere Infos unter http://umweltsuen.de +oder bei +Roland Kletzing +devzero@web.de diff --git a/controller/current_cost/create-rrd.sh b/controller/current_cost/create-rrd.sh new file mode 100755 index 0000000..2c4cb5f --- /dev/null +++ b/controller/current_cost/create-rrd.sh @@ -0,0 +1,30 @@ +#!/bin/sh +rrdtool create /path/to/your/powertemp.rrd --step 5 \ +DS:Power1:GAUGE:180:0:10000 \ +DS:Power2:GAUGE:180:0:10000 \ +DS:Power3:GAUGE:180:0:10000 \ +DS:Temp:GAUGE:180:-50:100 \ +RRA:AVERAGE:0.5:1:3200 \ +RRA:AVERAGE:0.5:6:3200 \ +RRA:AVERAGE:0.5:36:3200 \ +RRA:AVERAGE:0.5:144:3200 \ +RRA:AVERAGE:0.5:1008:3200 \ +RRA:AVERAGE:0.5:4320:3200 \ +RRA:AVERAGE:0.5:52560:3200 \ +RRA:AVERAGE:0.5:525600:3200 \ +RRA:MIN:0.5:1:3200 \ +RRA:MIN:0.5:6:3200 \ +RRA:MIN:0.5:36:3200 \ +RRA:MIN:0.5:144:3200 \ +RRA:MIN:0.5:1008:3200 \ +RRA:MIN:0.5:4320:3200 \ +RRA:MIN:0.5:52560:3200 \ +RRA:MIN:0.5:525600:3200 \ +RRA:MAX:0.5:1:3200 \ +RRA:MAX:0.5:6:3200 \ +RRA:MAX:0.5:36:3200 \ +RRA:MAX:0.5:144:3200 \ +RRA:MAX:0.5:1008:3200 \ +RRA:MAX:0.5:4320:3200 \ +RRA:MAX:0.5:52560:3200 \ +RRA:MAX:0.5:525600:3200 diff --git a/controller/current_cost/crontab.example b/controller/current_cost/crontab.example new file mode 100644 index 0000000..aafd7ec --- /dev/null +++ b/controller/current_cost/crontab.example @@ -0,0 +1,14 @@ +# Add these to your /etc/crontab. This is just an example. Change it to fit your needs +# make 15 minute graphs every minute +* * * * * root (touch /root/currentcost/15m.do) +# make hour graphs every 10 minutes +*/10 * * * * root (touch /root/currentcost/1h.do) +# make 12h graphs every half hour +*/30 * * * * root (touch /root/currentcost/12h.do) +# make day and week graph every full hour +0 * * * * root (touch /root/currentcost/1d.do) +0 * * * * root (touch /root/currentcost/1w.do) +# make month, quarter and year graphs once a day +0 0 * * * root (touch /root/currentcost/1m.do) +0 0 * * * root (touch /root/currentcost/3m.do) +0 0 * * * root (touch /root/currentcost/1y.do) diff --git a/controller/current_cost/doall.sh b/controller/current_cost/doall.sh new file mode 100755 index 0000000..400914b --- /dev/null +++ b/controller/current_cost/doall.sh @@ -0,0 +1,2 @@ +#!/bin/bash +touch 15m.do 1h.do 12h.do 1d.do 1w.do 1m.do 3m.do 1y.do diff --git a/controller/current_cost/fetchdata.pl b/controller/current_cost/fetchdata.pl new file mode 100755 index 0000000..b32306d --- /dev/null +++ b/controller/current_cost/fetchdata.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl -w +# This program reads data from a Current Cost device via serial port and puts it into an RRD database (also prints on console) + +#Avoid Line buffering for stdout. Avoids problems when sending the script output to a pipe +local $| = 1; + +use strict; +use Device::SerialPort qw( :PARAM :STAT 0.07 ); + +#USB (change into /dev/ttyS0 for Serial port) +my $PORT = "/dev/ttyUSB0"; + +my $ob = Device::SerialPort->new($PORT); + +# change into appropriate baudrate. Envi classic needs $ob->baudrate(57600); +$ob->baudrate(57600); +$ob->write_settings; + +open(SERIAL, "+>$PORT"); +while (my $line = ) { + +# Envi White old +# if ($line =~ m!0*(\d+).*0*(\d+).*0*(\d+) *([\-\d.]+)!) { + +#Envi Black >CC128-v0.12 + if ($line =~ m! *([\-\d.]+).*0*(\d+).*0*(\d+).*0*(\d+)!) { + my $watts1 = $2; + my $watts2 = $3; + my $watts3 = $4; + my $temp = $1; + print "$watts1, $watts2, $watts3, $temp\n"; + system("rrdupdate","/path/to/your/powertemp.rrd","N:$watts1:$watts2:$watts3:$temp"); + } +} diff --git a/controller/current_cost/makegraphs.sh b/controller/current_cost/makegraphs.sh new file mode 100755 index 0000000..a5592db --- /dev/null +++ b/controller/current_cost/makegraphs.sh @@ -0,0 +1,60 @@ +#!/bin/bash +set -x + +export LC_ALL=de_DE.UTF-8 + +export param1='--end now --width 880 --height 300 --slope-mode --vertical-label VoltAmpere --lower-limit 0 --alt-autoscale-max' + +export param2='DEF:Power1=powertemp.rrd:Power1:AVERAGE + DEF:Power2=powertemp.rrd:Power2:AVERAGE + DEF:Power3=powertemp.rrd:Power3:AVERAGE + CDEF:Ln1=Power1,Power1,UNKN,IF + CDEF:Ln2=Power1,Power1,Power2,+,UNKN,IF + CDEF:Ln3=Power3,Power1,Power2,Power3,+,+,UNKN,IF + AREA:Power1#A0A0FF:Phase1 + AREA:Power2#A0FFA0:Phase2:STACK + AREA:Power3#FFA0A0:Phase3\j:STACK + LINE1:Ln3#AA0000 + LINE1:Ln2#00AA00 + LINE1:Ln1#0000AA' + +export param3='GPRINT:Power1:LAST:%2.1lf%sVA + GPRINT:Power2:LAST:%2.1lf%sVA + GPRINT:Power3:LAST:%2.1lf%sVA\j' + +export basepath='/path/to/your/webserver/htdocs/asubdir' + +get-ts () { + export ts=`date +"Graph vom %A, %d.%m.%Y um %H:%M Uhr"` +} + +mvimg () { + rm $basepath/$1 + mv $basepath/tmp.png $basepath/$1 +} + +mkimg () { + if [ -e "$1.do" ];then + rm $1.do + get-ts + title="Energieverbrauch $2 - $ts" + if [ $1 == "15m" ];then + rrdtool graph $basepath/tmp.png --title "$title" --start end-$1 $param1 $param2 $param3 + else + rrdtool graph $basepath/tmp.png --title "$title" --start end-$1 $param1 $param2 + fi + mvimg power-$1.png + fi +} + +while true;do + mkimg 15m "letzte 15 Minuten" + mkimg 1h "letzte Stunde" + mkimg 12h "letzte 12 Stunden" + mkimg 1d "letzter Tag" + mkimg 1w "letzte Woche" + mkimg 1m "letzter Monat" + mkimg 3m "letztes Quartal" + mkimg 1y "letztes Jahr" +sleep 10; +done