I have written a bash script that will allow a Linux server to get the temperature readings from 1 Wire temperature probes running off a HA7Net 1 Wire Bus Master. The script uses lynx to get the readings from the Bus Master, parses the html code for the reading, converts the reading to Fahrenheit and then stores the result in a file. (FYI: the linux I am running is RedHat 7.1. The script runs every 10 minutes as a cron job.)
Here is the shell script:
#!/bin/sh
#============================================================
#
# Script name: readHA7nettemps.sh
# Purpose: To read the temperature from the one wire
# temperature probes as html documents, parse
# the document to extract the temperature
# in centigrade, convert it to fahrenheit and
# store the result in a file on the server.
# Comparison is also made with the last high
# and low temperatures and updates their
# respective files.
#
# Files in use:
#
# outsidet.txt Holds the last reading taken from the
# outdoor sensor.
# outsidetmin.txt Holds the lowest reading since midnite
# for the outdoor sensor.
# outsidetmax.txt Holds the highest reading since midnite
# for the outdoor sensor.
# ght.txt Holds the last reading taken from the
# greenhouse sensor.
# ghtmin.txt Holds the lowest reading since midnite
# for the greenhouse sensor.
# ghtmax.txt Holds the highest reading since midnite
# for the greenhouse sensor.
#
#
# Change the string ipaddress to reflect the ip address of your HA7Net bus master.
#
ipaddress="192.168.0.5"
#============================================================
# Static string initialization area.
#
bccmd="/usr/bin/bc"
folder="/var/log/heyu"
htmlgetcmd="/usr/bin/lynx -source -preparsed"
tempsurl="http://$ipaddress/1Wire/ReadTemperature.html?Address_Array="
#
#============================================================
# The probecount integer contains the number of one wire temperature
# probes that are to be addressed.
#
probecount=2
#
# The tprobe array contains the one wire addresses of the temperature
# probes and is automatically sized to match the probecount integer.
#
# Probes:
# Address D8000000A8B91526 is located in the greenhouse,
# and address 9900080124F69D10 is the outdoor temperature
# sensor. You can get the address of your probes by running
# the web interface to the HA7Net and recording the probe(s) addresses.
#
declare tprobe[$probecount]
tprobe[0]="D8000000A8B91526"
tprobe[1]="9900080124F69D10"
#
# The lowfile array contains the names of the low temperature files.
#
declare lowfile[$probecount]
lowfile[0]="$folder/ghtmin.txt"
lowfile[1]="$folder/outsidetmin.txt"
#
# The highfile array contains the names of the high temperature files.
#
declare highfile[$probecount]
highfile[0]="$folder/ghtmax.txt"
highfile[1]="$folder/outsidetmax.txt"
#
#
# The outfile array is the target for the script to write the
# current temperature.
#
declare outfile[$probecount]
outfile[0]="$folder/ght.txt"
outfile[1]="$folder/outsidet.txt"
#
#============================================================
#
for (( j=0; j < $probecount ; j++ ))
do
temp1string=`$htmlgetcmd $tempsurl${tprobe[$j]}`
temp2string=`echo $temp1string | awk 'BEGIN { FS="VALUE" } { print $5 }'`
temp3string=`echo $temp2string | awk 'BEGIN { FS="=" } { print $2 }'`
temp4string=`echo $temp3string | awk 'BEGIN { FS="><" } { print $1 }'`
ctemp=`echo $temp4string | sed '/"/s// /g'`
#
# This next line does the Centigrade to Fahrenheit conversion.
#
ftemp=`echo "scale=0; ((($ctemp*9)/5)+32)" | $bccmd -l`
#
# Note: bc is a general purpose calculator. The scale is the number
# of decimals to be displayed in the answer. If you set scale to 1, the
# the value of ftemp will be to 1 decimal.
# The -l argument tells bc to use the standard math library.
#
# Now let's output the temperature to its storage file.
#
echo $ftemp > ${outfile[$j]}
#
# Now, let's compare the temperature to the last lowest and
# highest temperatures and overwrite the file(s) with the current
# temperature if it is higher or lower than the last recorded ones.
#
lastlowtemp=`cat ${lowfile[$j]}`
lasthightemp=`cat ${highfile[$j]}`
if [ $ftemp -gt $lasthightemp ]
then
echo $ftemp > ${highfile[$j]}
fi
if [ $ftemp -lt $lastlowtemp ]
then
echo $ftemp > ${lowfile[$j]}
fi
#
done
exit 0
After you have cut and pasted the above text, be sure to modify it for your site. You will
need to change the ipaddress, probecount and the tprobe array to suit your needs.
If you have any questions, post them to this topic and I will attempt to answer them.
Ed
Here is the shell script:
#!/bin/sh
#============================================================
#
# Script name: readHA7nettemps.sh
# Purpose: To read the temperature from the one wire
# temperature probes as html documents, parse
# the document to extract the temperature
# in centigrade, convert it to fahrenheit and
# store the result in a file on the server.
# Comparison is also made with the last high
# and low temperatures and updates their
# respective files.
#
# Files in use:
#
# outsidet.txt Holds the last reading taken from the
# outdoor sensor.
# outsidetmin.txt Holds the lowest reading since midnite
# for the outdoor sensor.
# outsidetmax.txt Holds the highest reading since midnite
# for the outdoor sensor.
# ght.txt Holds the last reading taken from the
# greenhouse sensor.
# ghtmin.txt Holds the lowest reading since midnite
# for the greenhouse sensor.
# ghtmax.txt Holds the highest reading since midnite
# for the greenhouse sensor.
#
#
# Change the string ipaddress to reflect the ip address of your HA7Net bus master.
#
ipaddress="192.168.0.5"
#============================================================
# Static string initialization area.
#
bccmd="/usr/bin/bc"
folder="/var/log/heyu"
htmlgetcmd="/usr/bin/lynx -source -preparsed"
tempsurl="http://$ipaddress/1Wire/ReadTemperature.html?Address_Array="
#
#============================================================
# The probecount integer contains the number of one wire temperature
# probes that are to be addressed.
#
probecount=2
#
# The tprobe array contains the one wire addresses of the temperature
# probes and is automatically sized to match the probecount integer.
#
# Probes:
# Address D8000000A8B91526 is located in the greenhouse,
# and address 9900080124F69D10 is the outdoor temperature
# sensor. You can get the address of your probes by running
# the web interface to the HA7Net and recording the probe(s) addresses.
#
declare tprobe[$probecount]
tprobe[0]="D8000000A8B91526"
tprobe[1]="9900080124F69D10"
#
# The lowfile array contains the names of the low temperature files.
#
declare lowfile[$probecount]
lowfile[0]="$folder/ghtmin.txt"
lowfile[1]="$folder/outsidetmin.txt"
#
# The highfile array contains the names of the high temperature files.
#
declare highfile[$probecount]
highfile[0]="$folder/ghtmax.txt"
highfile[1]="$folder/outsidetmax.txt"
#
#
# The outfile array is the target for the script to write the
# current temperature.
#
declare outfile[$probecount]
outfile[0]="$folder/ght.txt"
outfile[1]="$folder/outsidet.txt"
#
#============================================================
#
for (( j=0; j < $probecount ; j++ ))
do
temp1string=`$htmlgetcmd $tempsurl${tprobe[$j]}`
temp2string=`echo $temp1string | awk 'BEGIN { FS="VALUE" } { print $5 }'`
temp3string=`echo $temp2string | awk 'BEGIN { FS="=" } { print $2 }'`
temp4string=`echo $temp3string | awk 'BEGIN { FS="><" } { print $1 }'`
ctemp=`echo $temp4string | sed '/"/s// /g'`
#
# This next line does the Centigrade to Fahrenheit conversion.
#
ftemp=`echo "scale=0; ((($ctemp*9)/5)+32)" | $bccmd -l`
#
# Note: bc is a general purpose calculator. The scale is the number
# of decimals to be displayed in the answer. If you set scale to 1, the
# the value of ftemp will be to 1 decimal.
# The -l argument tells bc to use the standard math library.
#
# Now let's output the temperature to its storage file.
#
echo $ftemp > ${outfile[$j]}
#
# Now, let's compare the temperature to the last lowest and
# highest temperatures and overwrite the file(s) with the current
# temperature if it is higher or lower than the last recorded ones.
#
lastlowtemp=`cat ${lowfile[$j]}`
lasthightemp=`cat ${highfile[$j]}`
if [ $ftemp -gt $lasthightemp ]
then
echo $ftemp > ${highfile[$j]}
fi
if [ $ftemp -lt $lastlowtemp ]
then
echo $ftemp > ${lowfile[$j]}
fi
#
done
exit 0
After you have cut and pasted the above text, be sure to modify it for your site. You will
need to change the ipaddress, probecount and the tprobe array to suit your needs.
If you have any questions, post them to this topic and I will attempt to answer them.
Ed