[Blogs] auto_man's Blog - Perl / Php graphing software 1-wire logging

Not open for further replies.

CT Droid

CT Bot
How to log 1-wire temperature data to a mysql database and view via php script on web server.
To start it off you must satisfy the basic requirements to achieve the task:
1. Apache(or equivalent) server
2. PHP installed on server
3. Mysql installed on server
4. Permissions to run a cron(or equivalent) on server
5. Digitemp Software
6. Ds9097 or other digitemp supported 1-wire device
7. Ds18s20 sensors or other digitemp supported 1-wire device

Now time for the software, to sum it up I execute 3 basic steps:
1. A cron runs a perl script to get the data from the 1-wire bus an put into a mysql database
2. A php script is called to build the images for the web page
3. Serve the page via Apache web server

Step one:
Setup digitemp on your webserver. To do this you must follow the README in the digitemp software package. The steps involve creating a config file for digitemp to use on each run. This config file tells what serial port to use in addition to other sensor information.

Step two:
Setup the mysql database to receive digitemp data. This was acutally quite easy thanks to Brian Lane the maker of the digitemp software. If you download the digitemp software there is a Readme in the perl directory as well as an sql setup file(make_mysql.sql). Using these you can create the mysql database. The command is 'mysql digitemp -u root -p < make_mysql.sql'

Step three:
Copy my scripts(attached) to your web server. Once on the server you must change a few things:
my $Output_dir = "/var/www/localhost/htdocs/"; --> web server directory you want the output page to be placed
my $Output_file = "index.html"; --> name of output web page
my $digitemp_config = "/tmp/digi.cfg"; --> path and filename of your digitemp config file
my $digitemp_binary = "/usr/bin/digitemp"; --> path to digitemp binary on your webserver
my $db_name = "digidb"; --> database name
my $db_user = "username"; --> database username
my $db_pass = "password"; --> database password
Find each iteration of thermo/jp.php and thermo/thermometer.php ---> change to match the path on your machine. **These files are attached. I will describe jp.php and thermometer.php in future posts.

Step four:
Test the gettemps.pl script by executing manually. You should get no errors and be able to load your index.html output in your browser. If all looks correct setup the cron.

Step five the Cron:
I run the cron every 5 minutes using the command below:
*/5 * * * * perl /var/www/localhost/htdocs/thermo/gettemps.pl

*********A few things to note. I just discovered tonight my data was incorrectly sorted on one of my graphs. Odd that it is only one as both graphs use the same query. Currently I use the following query to find the last 288 data points(approx 24hrs of data). ""SELECT Fahrenheit FROM digitemp where SerialNumber = "xxx" limit 288 ""
What I have discovered is that although in my test of the query the data showed up correctly now mysql seems to not be sorting it in an unexpected order. The software I have posted here functions correctly except for this, I plan on looking at this in the next day and make another blow post with the update.
Attached File(s) automanfiles.zip ( 3.48K )Number of downloads: 0

This thread is not open. If you wish to respond, please respond using the original blog entry link. View the original blog entry
Not open for further replies.