Wireless Recycled Reef Controller |
| Home | Recent Edits | Search | Edit this page |
|
Here are some sample shells scripts:
#!/bin/sh
while : # : always evaluates to true, so a forever loop
# My 3 DS18S20's. The ID's I got from doing a
# grep '.' /var/1wire/*/temperature
# This is saying for each one of the following items,
# do the action
for i in /var/1wire/10.F7B64D000800/temperature \
/var/1wire/10.12BD4D000800/temperature \
/var/1wire/10.1FBB4D000800/temperature
do
cat $i ; echo " $i"
done # exit the for loop do
# sleep 2 # uncomment if you want a delay, in seoonds
echo " " # break up each for loop dataset with a blank line
done
Output:
/tmp # ./temp.sh
66.875 /var/1wire/10.F7B64D000800/temperature
67.2125 /var/1wire/10.12BD4D000800/temperature
66.7625 /var/1wire/10.1FBB4D000800/temperature
Defining Names in NVRAM. This is done on the command line of the router, ie telnet to it. Change the values to match your device. As for naming, it is probably a good idea to come up with some standard prefix for later down the road when we get to the WEB? UI. / # nvram set temp_tank=10.12BD4D000800 / # nvram commit / # nvram set temp_sump=10.F7B64D000800 / # nvram commit / # nvram set temp_hood=10.1FBB4D000800 / # nvram commit The script to use the nvram variables
#!/bin/sh
DEVICEPATH="/var/1wire"
while :
do
for i in temp_tank temp_sump temp_hood
do
DEVICEID=`nvram get $i`
cat $DEVICEPATH/$DEVICEID/temperature ; echo " $i"
done
#sleep 2
echo " "
done
- Output:
/tmp # ./temp-nvram.sh
67.1 temp_tank
66.7625 temp_sump
66.65 temp_hood
67.1 temp_tank
66.7625 temp_sump
66.65 temp_hood
Putting some time into the script. With a little bit of work, this can be setup to output to a web directory. A program on the client computer can grab this output and store in a database for historical data.
#!/bin/sh
DEVICEPATH="/var/1wire"
while :
for i in temp_tank temp_sump temp_hood
do
DEVICEID=`nvram get $i`
TIME=`date +%b-%d-%Y-%H:%M:%S`
cat $DEVICEPATH/$DEVICEID/temperature ; echo " $i collected @ $TIME"
done
#sleep 2
echo " "
done
Output: -
/tmp # ./temp-nvram.sh
67.2125 temp_tank collected @ Jan-16-2005-13:40:32
66.875 temp_sump collected @ Jan-16-2005-13:40:33
66.7625 temp_hood collected @ Jan-16-2005-13:40:35
67.2125 temp_tank collected @ Jan-16-2005-13:40:37
66.875 temp_sump collected @ Jan-16-2005-13:40:37
66.7625 temp_hood collected @ Jan-16-2005-13:40:37
I've added sed and awk to busybox now. So from command line you can do something like this using the previous temp-nvram.sh
wrrc1 wrrc-bin $ ./temp-nvram.sh | awk -F @ {'print $2 $1'}
I take the output of "temp-nvram.sh" and pipe it to awk. awk takes -F @, as my field seperator is @ then in the {} is the awk command to print the 2nd column, then the first. This is our first formatting example. I could've taken the output and piped it to sort as well if I wanted to sort by temperature (but the temp-nvram.sh example, since it loops and will never end for sort to work) Output: Jan-01-1970-00:12:14 67.1 temp_tank collected Jan-01-1970-00:12:16 66.65 temp_hood collected Mail Notification Example using nc (netcat) This is a very rough example using nc to send SMTP? commands to a server for notification. wrrc $ cat nc-mail.sh #!/bin/sh -e # # WRRC email notification using netcat # # NVRAM parameters # WC_smtp the smtp host for outbound email # WC_notify email address of person for email notification # # WC_smtp=<SMTP Server IP> # should become an NVRAM variable HOST=wrrc1.mydomain.com # The routers hostname and domain Sender=wrrc@mydomain.com # The from field in an email WC_notify=me@mydomain.com # address to send email to TIME=`date +%Y-%m-%d:%T` # Get the data and time echo "HELO $HOST MAIL From: $Sender RCPT To: $WC_notify DATA Subject: WRRC - $TIME . QUIT" | nc $WC_smtp 25 # now pipe all that to nc to do the magic |