Software
This project uses free open source software (FOSS). The operating system is Linux, which usually includes Apache Web Server and Perl. The graphs are generated with the Perl module GD::Graph.
Linux distrubutions that have been tested are:
- Lubuntu (lightweight Ubuntu)
- Slackware 13.0
Talking to the scale is straight forward. Usually send a short character string to the scale and listen for a reply. For the Adam Equipment:
echo "G\r\n" > /dev/ttyS0
read -t 1 SCALE < /dev/ttyS0
To use the Cisco Linksys WRT160NL wireless router to talk to the My Weigh HD300 scale, first detach a process that sleeps for a second and sends a carriage return. Then read the data. The detached bit sleeps for a second,
allowing the read to get latched onto the serial port, and then sends the command, which promptly returns data.
'sleep 1;echo -e "\r" > /dev/ttyUSB0' &
read -t 3 SCALE /dev/ttyUSB0.
Talking to the temperature sensors and decoding the data is a little more complex. Fortunately someone has done the work and made it available for us at http://perfec.to/ut60e/.
#/bin/bash
# get the date and time in YYYY/MM/DD HH:MM format and
# store it in the variable DATE
DATE=`date +"%Y/%m/%d %H:%M"`
# send a "G" to the scale plugged into ttyS0 (COM1) and
# read the result into variable SCALE
echo "G\r\n" > /dev/ttyS0
read SCALE < /dev/ttyS0
# read the two temperature meters
# parse-ut60e -f /dev/ttyS1 reads the meter on ttyS1 (COM2)
# it is run with the timeout command with the timeout set to 1 second
TEMP=`timeout 1 /home/hivetool/parse-ut60e -f /dev/ttyS1`
AMBIENT=`timeout 1 /home/hivetool/parse-ut60e -f /dev/ttyS2`
# write (append) it all to the log file
echo $DATE $SCALE $TEMP $AMBIENT >> /home/hivetool/hive.log
# run the graphing program to create index.html and hive_graph.gif
/var/www/htdocs/graph_hive.pl
# replace spaces and other characters so
# they can be sent with a http GET request
DATE=${DATE// /%20}
SCALE=${SCALE// /%20}
SCALE=${SCALE//+/%2b}
TEMP=${TEMP// /}
AMBIENT=${AMBIENT// /}
# send the data to a real website to back it up off site but
# mainly so I can get the hive's WAN IP
RESULT=`curl http://YOUR-WEB-SITE.COM/log_hive.pl?date=$DATE
\&weight=$SCALE\&temp=$TEMP\&ambient=$AMBIENT`
|
bash shell script
This script is called by cron every five minutes. It uses several programs that come with linux, in the core utilities:
date - Display or change the date & time
echo - Display message on screen
timeout - Run a command with a time limit
read - Read a line from standard input
curl - transfer a URL
In addition, there is the program that formats the temperature outputs:
parse-ut60e
And two perl scripts, one that creates the graphs on the hive computer, and one that logs the data on a public web server and provides a link to the hive:
graph_hive.pl
log_hive.pl
|
|