Data is gathered using
Digitemp sensors; these are inserted into a
MySQL database by a perl script which runs from cron every 5 minutes.
This works fine as long as the database is up, and mails an error message
otherwise.
Once the data is in, there are two pages that access it. The
first shows the
last measured temperature readings, and the
second generates a graph using
gnuplot. Both pages use the MySQL functions of PHP to access rows in the
database.
The database's structure is simple. It uses one table ('temps') with three fields.
The first ('time') is of type DATETIME, and stores the time the measurement is taken.
The other two ('temp0' and 'temp1') are of type FLOAT(4,2), and store the temperature measurements
in Fahrenheit.
You'll (maybe) notice that the second page generates a random number between
0 and 999999; it uses this to append to files that it's writing to disk, to
keep different users from stepping on each other's results. Everything
is cleaned up as the script exits except for the resulting .gif image; these
are deleted by a cron job that runs once every 24 hours. (Deleting them
in the script didn't allow enough time for the browser to get them.)
The grapher.php3 script outputs a data file for the temperature sensor
requested, and generates a gnuplot command to perform the plotting.
Gnuplot outputs a .pbm file, which is converted to a .gif with the
'convert' utility from the
ImageMagick package.
Machias, WA is located about 30
miles northeast of Seattle.
The "Outside" sensor is run through a wall right near the server,
and attached to the underside of the exterior frame of a west-facing window.
All this is running on a Linux AMD K6-2/333 with 64 megs of RAM, using Apache, PHP, and MySQL. It originally ran on a 486-66 withou
t any problems, except that the graphing was a bit slow.
People are welcome to make use of the source they find here for personal or
commercial use, but not to sell it. All source is Copyright 1999 by
JMR Technology Corp.
Want us to build you a similar solution?
Contact us.