bohlke
PBITAWA
Warning if you are not a geek (like me) you may find this post a bit boring, proceed at your own risk.
I had to edit some of the syntax to remove the smileys (too many images error message) you may see extra spaces in front of the pH statements in the script.
I have an Aquacontroller Jr and as happy as I am with Aquanotes I wanted a better way to collect statistics in a database. For those of you not familiar with MRTG and RRD tool RRD is the Acronym for Round Robin Database. RRD is a system to store and display time-series data (network bandwidth, machine-room temperature, mysql queries,dns queries). You use it directly via a command line or in a scheduler. It is available for a variety of operating systems however I chose linux.
The first problem I had to solve was how to get the data from the Ac Jr into a variable that I could send to rrdtool. The serial interface to the Ac Jr is pretty easy to use however I had to use a non-grounded power cord to avoid the ground loop problems with the Ac Jr serial interface. I decided that I would poll current status every five minutes instead of using the data logging options. This way I would not have to worry about overlapping data sets. To do this I used minicom which is available for many linux distributions. Minicom supports scripting and can log the output to a file, I figured I was all set. I configured minicom (using minicom -s) to use /dev/ttyS0 and I removed all of the modem init strings. Here is what the sample output from the c command on my Ac Jr looked like:
The only thing that wasnt completely clear was how to exit minicom after the script was complete. I found a solution tough its not perfect, but it was the first solution so I used it Here is my minicom script
I called it aquadata and the output is saved to aqua.log, here are the command line options I used:
now all I had to do was construct a script that I could run to parse the output, using my old school tools (head, tail, and awk) I parsed the data. I am sure there is a better way to do it but this again was the first one that worked
I have to remove the file every time as minicom appends the data to the output log file. So now I have the ability to capture the tank pH and temp at the interval of my choosing, now its time to setup my rrdtool database. To do that we first must create the rrdtool database.
So I built a little script to create the database, I have two dbs right now one for temp and the other for pH
I chose some default values for the dataset sizes, I can keep realtime stats for 2 days and rolled up average, min and max for 100 days:
AVERAGE : 300 seconds * 1 * 1200 = 180000 seconds = 50 hours = 2 days
MIN : 300 seconds * 12 * 2400 = 8640000 seconds = 2400 hours = 100 days
MAX : 300 seconds * 12 * 2400 = 8640000 seconds = 2400 hours = 100 days
AVERAGE : 300 seconds * 12 * 2400 = 8640000 seconds = 2400 hours = 100 days
once I had the database created I added the statements to my script to send the data to the database:
Now all I have to do is run this script every 5 minutes to collect the data. To display the data you use the rrdtool graph function, this builds the png file on demand. You can see some examples of really cool rddtool graphs here. Here is my simple rrdtool graph, I will hopefully have something a bit cooler soon.
So now I have two graphs one for pH and the other for Temp. Since these are created on demand I will need to create a cgi app to build them on the webserver, still not done with that yet. Here are the graphs
Hope this helps anyone else who wants to track and store tank data.
I had to edit some of the syntax to remove the smileys (too many images error message) you may see extra spaces in front of the pH statements in the script.
I have an Aquacontroller Jr and as happy as I am with Aquanotes I wanted a better way to collect statistics in a database. For those of you not familiar with MRTG and RRD tool RRD is the Acronym for Round Robin Database. RRD is a system to store and display time-series data (network bandwidth, machine-room temperature, mysql queries,dns queries). You use it directly via a command line or in a scheduler. It is available for a variety of operating systems however I chose linux.
The first problem I had to solve was how to get the data from the Ac Jr into a variable that I could send to rrdtool. The serial interface to the Ac Jr is pretty easy to use however I had to use a non-grounded power cord to avoid the ground loop problems with the Ac Jr serial interface. I decided that I would poll current status every five minutes instead of using the data logging options. This way I would not have to worry about overlapping data sets. To do this I used minicom which is available for many linux distributions. Minicom supports scripting and can log the output to a file, I figured I was all set. I configured minicom (using minicom -s) to use /dev/ttyS0 and I removed all of the modem init strings. Here is what the sample output from the c command on my Ac Jr looked like:
c
Current Status is:
Dec 28 2008 12:00:48
Temp pH
78.6 8.06
LT1 is OFF Auto
LT2 is ON Auto
LT3 is OFF Auto
LT4 is OFF Auto
LT5 is OFF Auto
HT1 is ON Auto
HT2 is OFF Auto
CO1 is OFF Auto
CO2 is OFF Auto
PO1 is OFF Auto
ALT is OFF Auto
ALP is OFF Auto
The only thing that wasnt completely clear was how to exit minicom after the script was complete. I found a solution tough its not perfect, but it was the first solution so I used it Here is my minicom script
send "c^M"
expect {
"AquaController>"
}
sleep 5
! killall -9 minicom
I called it aquadata and the output is saved to aqua.log, here are the command line options I used:
minicom -o -C aqua.log -S /home/bohlke/rrdfiles/aquadata
now all I had to do was construct a script that I could run to parse the output, using my old school tools (head, tail, and awk) I parsed the data. I am sure there is a better way to do it but this again was the first one that worked
#!/bin/bash
PATH=/usr/bin:/bin:/usr/local/rrdtool-1.3.5/bin
rm -f aqua.log
minicom -o -C aqua.log -S /home/bohlke/rrdfiles/aquadata > /dev/null
TEMP=`head -6 aqua.log | tail -1 | awk '{print $1}'`
PH=`head -6 aqua.log | tail -1 | awk '{print $2}'`
I have to remove the file every time as minicom appends the data to the output log file. So now I have the ability to capture the tank pH and temp at the interval of my choosing, now its time to setup my rrdtool database. To do that we first must create the rrdtool database.
So I built a little script to create the database, I have two dbs right now one for temp and the other for pH
#!/bin/bash
PATH=/usr/bin:/bin:/usr/local/rrdtool-1.3.5/bin
rrdtool create /home/bohlke/rrdfiles/db/tanktemp.rrd DS:temp:GAUGE:600:50:100 RRA:AVERAGE:0.5:1:1200 RRA:MIN:0.5:12:2400 RRA:MAX:0.5:12:2400 RRA:AVERAGE:0.5:12:2400
rrdtool create /home/bohlke/rrdfiles/db/tankph.rrd DS: ph:GAUGE:600:5:9 RRA:AVERAGE:0.5:1:1200 RRA:MIN:0.5:12:2400 RRA:MAX:0.5:12:2400 RRA:AVERAGE:0.5:12:2400
I chose some default values for the dataset sizes, I can keep realtime stats for 2 days and rolled up average, min and max for 100 days:
AVERAGE : 300 seconds * 1 * 1200 = 180000 seconds = 50 hours = 2 days
MIN : 300 seconds * 12 * 2400 = 8640000 seconds = 2400 hours = 100 days
MAX : 300 seconds * 12 * 2400 = 8640000 seconds = 2400 hours = 100 days
AVERAGE : 300 seconds * 12 * 2400 = 8640000 seconds = 2400 hours = 100 days
once I had the database created I added the statements to my script to send the data to the database:
#!/bin/bash
PATH=/usr/bin:/bin:/usr/local/rrdtool-1.3.5/bin
rm -f aqua.log
minicom -o -C aqua.log -S /home/bohlke/rrdfiles/aquadata > /dev/null
TEMP=`head -6 aqua.log | tail -1 | awk '{print $1}'`
PH=`head -6 aqua.log | tail -1 | awk '{print $2}'`
rrdtool update /home/bohlke/rrdfiles/db/tanktemp.rrd N:${TEMP}
rrdtool update /home/bohlke/rrdfiles/db/tankph.rrd N:${PH}
Now all I have to do is run this script every 5 minutes to collect the data. To display the data you use the rrdtool graph function, this builds the png file on demand. You can see some examples of really cool rddtool graphs here. Here is my simple rrdtool graph, I will hopefully have something a bit cooler soon.
#!/bin/bash
PATH=/usr/bin:/bin:/usr/local/rrdtool-1.3.5/bin
rrdtool graph temp.png -s now-24h --title="Temperature" -w 600 -h 200 --alt-autoscale-max --lower-limit -20 --vertical-label "Degrees" DEF:temp=/home/bohlke/rrdfiles/db/tanktemp.rrd:temp:AVERAGE DEFutsidetemp=/home/bohlke/rrdfiles/db/68502/real.rrd:real:AVERAGE DEF
utsidefelt=/home/bohlke/rrdfiles/db/68502/felt.rrd:felt:AVERAGE DEF: ph=/home/bohlke/rrdfiles/db/tankph.rrd: ph:AVERAGE CDEF:negph=ph,-1,* VRULE:1120687200#EE00EE: COMMENT:" Maximum Minimum Average Last\l" GPRINT:temp:MAX:"Temp %6.2lf %s\:" GPRINT:temp:MIN:"%6.2lf %s\:" GPRINT:temp:AVERAGE:"%6.2lf %s\:" GPRINT:temp:LAST:"%6.2lf %s\:\l" AREA:temp#00EE00:"Tank Temp \l" LINE
utsidetemp#EE0000:"Outside Temp\l"
#!/bin/bash
PATH=/usr/bin:/bin:/usr/local/rrdtool-1.3.5/bin
rrdtool graph ph.png -s now-24h --title="Tank pH" -w 600 -h 200 --alt-autoscale-max --lower-limit 7 --vertical-label "pH" DEF:temp=/home/bohlke/rrdfiles/db/tanktemp.rrd:temp:AVERAGE DEFutsidetemp=/home/bohlke/rrdfiles/db/68502/real.rrd:real:AVERAGE DEF
utsidefelt=/home/bohlke/rrdfiles/db/68502/felt.rrd:felt:AVERAGE DEF: ph=/home/bohlke/rrdfiles/db/tankph.rrd: ph:AVERAGE CDEF:negph=ph,-1,* VRULE:1120687200#EE00EE: COMMENT:" Maximum Minimum Average Last\l" GPRINT: ph:MAX:"pH %6.2lf %s\:" GPRINT: ph:MIN:"%6.2lf %s\:" GPRINT: ph:AVERAGE:"%6.2lf %s\:" GPRINT: ph:LAST:"%6.2lf %s\:\l" AREA: ph#00EE00:"Tank pH \l"
So now I have two graphs one for pH and the other for Temp. Since these are created on demand I will need to create a cgi app to build them on the webserver, still not done with that yet. Here are the graphs


Hope this helps anyone else who wants to track and store tank data.