Jump to content






Photo

Perl / Php graphing software for 1-wire data logging

Posted by auto_man , 28 December 2009 · 2484 views

1-wire
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 order by time desc limit 5""
See updated jp.php attached.

Attached Files






Photo
Dan (electron)
Dec 29 2009 08:40 AM
Very cool, thanks for sharing this!
  • Report

December 2019

S M T W T F S
1234567
8910 11 121314
15161718192021
22232425262728
293031    

Recent Entries

Recent Comments

Latest Visitors

  • Photo
    dlbelter
    21 Apr 2019 - 06:58
  • Photo
    Donut
    21 Jan 2019 - 23:55
  • Photo
    bryan_m
    15 Sep 2015 - 21:19
  • Photo
    Jozza
    18 Feb 2015 - 21:09
  • Photo
    AutomationDetails
    20 Oct 2014 - 00:55