Improved scan script to read 1wire and Atlas devices, although I did this 6 months ago and just pwoered up my development RPi thought I would extract the scan script. The two RS232 serial Atlas interfaces pH & ORP are connected via the Atlas serial mutliplexor. This mutliplexor uses two outputs from the PI to switch between pH and ORP devices. See Atlas site for serial port connector it lets you connect up to 4 devices to 1 serial port. Anyhow the following script uses pin 17 & 18 to switch between ph & orp.
@
macca_75 This is the script we should use for your next build. If you kill the program now it cleans up the "cat" process left behind so it will restart normally. Have also included the ability to bias both the pH and orp readings via a simple text file for each. These txt files simply have an offset value you wish to bias the results by. normally left at 0 however if you know your reading is high you can simply place an offset (i.e. -0.3 ). Of course you should really calibrate the Atlas driver however this is quick and easy.
Code:
#!/bin/bash
#title :AquaPi Read Script
#description :Read sensor data, range test then write data to file
#author :R Conway
#date :July 2013
#version :23
#usage :Start script in background [nohup /var/script/DataScan >/dev/null &]
#notes :if you kill the script you also kill the cat process left behind
#=======================================================================
stty -F /dev/ttyAMA0 raw 38400 cs8 -ignpar -cstopb eol 255 eof 255
OWWRITE="/opt/owfs/bin/owwrite -s 3001"
OWREAD="/opt/owfs/bin/owread -s 3001"
AWK="/usr/bin/awk"
gpio -g mode 17 out
gpio -g mode 18 out
(pkill -x cat)
while true ;do
### Read pH and ORP from Atlas Scientific Devices ###
( cat < /dev/ttyAMA0 > ./serial_in ) &
bkgPID=$!; disown $PID
gpio -g write 17 1
gpio -g write 18 0
sleep 2
printf "\x72\xff\x0D" >/dev/ttyAMA0 ; sleep 1
printf "\x72\xff\x0D" >/dev/ttyAMA0 ; sleep 2
kill $bkgPID >/dev/null
read ReefPH <./serial_in
ReefPH=$(awk -v SENSOR="$ReefPH" '{printf "%4.2f",(SENSOR+$0)}' /var/scripts/ph_cal_factor.txt)
( cat < /dev/ttyAMA0 > ./serial_in ) &
bkgPID=$!; disown $PID
gpio -g write 17 0
gpio -g write 18 1
sleep 2
printf "\x72\xff\x0D" >/dev/ttyAMA0 ; sleep 2
printf "\x72\xff\x0D" >/dev/ttyAMA0 ; sleep 2
kill $bkgPID >/dev/null
read ReefORP <./serial_in
ReefORP=$(awk -v SENSOR="$ReefORP" '{printf "%3.0f",(SENSOR+$0)}' /var/scripts/orp_cal_factor.txt)
### Read Temperatures from 1wire Devices ###
ReefTemp=10 #=$($OWREAD /28.FE6828040000/temperature | $AWK '{printf "%3.1f\n",($0)}')
sleep 1
HeaterTemp=20 #$($OWREAD /28.FB4228040000/temperature | $AWK '{printf "%3.1f\n",($0)}')
sleep 1
RoomTemp=30 #$($OWREAD /28.E1C96F030000/temperature | $AWK '{printf "%3.1f\n",($0)}')
### Out of Range Error trap -Do not log data (U=Undefined data) ###
orptest=`echo $ReefORP |cut -f1 -d'.'`
if [ -z $orptest ] || [ $orptest -gt 500 ] ||[ $orptest -lt 0 ] ; then
echo "`date` Reef Tank ORP reading error $orp" >>/var/scripts/nohup.out
ReefORP="U"
fi
phtest=`echo $ReefPH |cut -f1 -d'.'`
if [ -z $phtest ] || [ $phtest -gt 10 ] ; then
echo "`date` Reef Tank pH Reading Error $ph" >>/var/scripts/nohup.out
ReefPH="U"
fi
T1test=`echo $HeaterTemp |cut -f1 -d'.'`
if [ -z $T1test ] || [ $T1test -gt 75 ]; then
echo "`date` HEATER Temperature reading error $HeaterTemp" >>/var/scripts/nohup.out
HeaterTemp="U"
fi
T2test=`echo $ReefTemp |cut -f1 -d'.'`
if [ -z $T2test ] || [ $T2test -gt 50 ]; then
echo "`date` Reef Tank Temperature reading error $ReefTemp" >>/var/scripts/nohup.out
ReefTemp="U"
fi
T3test=`echo $RoomTemp |cut -f1 -d'.'`
if [ -z $T3test ] || [ $T3test -gt 50 ] ; then
echo "`date` Room Temperature reading error $RoomTemp" >>/var/scripts/nohup.out
RoomTemp="U"
fi
## Used for testing only when starting script manually -normally comment lines out
echo "=================="
echo "pH Reading :"$ReefPH
echo "ORP Reading :"$ReefORP
echo "Reef Temp :"$ReefTemp
echo "Heater Temp :"$HeaterTemp
echo "Room Temp :"$RoomTemp
### Push data into txt file for web gauges ###
#sec=$(/bin/date +%s)
#echo "$sec 0 5 & Acidity pH $ReefPH 8.3 9 7 8.8 8.0 0 0 0 0 1 3 & \
#ORP orp $ReefORP 200 500 0 450 10 0 0 0 0 1 0 & \
#ReefTemp DegC $ReefTemp 29 30 20 29 25 0 0 0 1 1 1 & \
#RoomTemp DegC $RoomTemp 29 40 10 30 0 0 0 0 0 1 0 & \
#Evaporation Litres 0 35 40 0 40 20 0 0 0 0 1 3 &" >/var/www/aqua_tag.txt
### Push Data into Trend File ###
#rrdtool update /var/www/rrd/Marine1.rrd N:$ReefPH:$ReefORP:$ReefTemp:$HeaterTemp:$RoomTemp:0:0:0:0:0
#rrdtool update /var/www/rrd/Marine.rrd N:$ReefPH:$ReefORP:$ReefTemp:$HeaterTemp:$RoomTemp:0:0:0:0:0
sleep 60
done
New interface does not use the date slider. You just choose the gauge then 1,3,5 or 30 days. The best thing about this is you can also see the previous readings for the period which I think is THE most valuable data. As a user looking at the difference between this week and last week can show immediately any problems.
The trend also shows the average value for the time with a solid horizontal line and also the average for the last period with a white dotted line. Thus you imediatly see is the average is higher or lower for the previous period. As you can see below the pH is slightly higher for this period (this week) ver the avg for the last week. I also print this on the lower trend area. The date for the max / min is for the current period however also show max min for the previous week although does not show which date and time.
If you click the previous period box you also get the trend line for the previous period, see below the temperature trend, the white dotted line is the previous week. This does show the last week was higher tank temps than this week although accounted for thur /fri being higher. (Oh just seen on the pic I need to format the temperature scale as its rounding the scale graduations.)
The temperature profile still shows the three variables.
Oh.. This is actually macca's tank data and yes there is lost data on Sunday but that's another story. I think he may of turned the power off for a while :eek