» Do it. Now.

Setting up a small weather monitoring station

Idea: Using 1wire protocol sensors to measure, log and display weather information.

Future: Using a relais card, I'll be able to toggle on of every device I feel like for any time from few ms to several hours.


Step 1: Installing the needed packages and compiling owfs

All steps should be done beeing root.

comp# apt-get install apache2 mysql-server automake make autoconf autotools-dev gcc g++ libtool libusb-dev fuse-utils libfuse-dev swig python2.6-dev php5-dev phplib-jpgraph

after that download the sources from http://owfs.org/index.php?page=download and unpack them to for example /usr/src/owfs/

comp# cd owfs 
comp# ./bootstrap 
comp# ./configure 
comp# sudo make && make install

watch out and make sure USB and OWFS are enabled after the ./configure part.

Create the directory you want the sensors to be mounted into, I'm using /var/ow/.

/opt/owfs/bin/owfs –allow_other -F -u /var/ow
will get you started.

Step 1a: Some facts on 1wire and owfs in special

You will find quite some stuff in /var/ow/ once you got it mounted. The main thing to understand is that every chip on the 1wire net is listet as one directory. They are named after the Chip itself, thats a two character key, and the unique id of the chip.
If you are using a hub you'll find 1F.ID directories that represent a hub branch each, they are split into main and aux branches. Once you navigated into those branches they will behave as if you werent using a hub at all.
The sensorboards, i.e. the directories contain files named after the sensor data they messure. Just read their caption and you are done meassuring.

Step 2: logging information

The rest was done by Jan, thx a lot!

We simply use batch to throw the sensor data into a mysql db.

echo "INSERT INTO data1. 
    VALUES ( 
    `cat /var/ow/1F.DE6705000000/main/10.ID/temperature`, 
    `cat /var/ow/1F.DE6705000000/main/10.ID/temperature`, 
    `cat /var/ow/1F.DE6705000000/main/26.ID/B1-R1-A/pressure`, 
    `cat /var/ow/1F.DE6705000000/main/26.ID/humidity` 
    )"| mysql -uuser -psecret dbname 

The db table consits of a id, a timestamp and fey decimal fields for the sensordata. The script is run by a cronjob as often as I want it to be.

Step 3: Displaying the infomation in a JPGraph


// include JPGraph Library 
include ("/usr/share/jpgraph/jpgraph.php"); 
include ("/usr/share/jpgraph/jpgraph_line.php"); 
include ("/usr/share/jpgraph/jpgraph_date.php"); 

// The callback that converts timestamp to minutes and seconds 
function TimeCallback($aVal) { 
    return Date('Y.M.d-H:i',$aVal); 

// create new graph 
$graph = new Graph(1300,600,"auto"); 

//get the db ready 

    @mysql_connect("localhost", "user", "secret") OR die(mysql_error()); 
    mysql_select_db('db') OR die(mysql_error()); 

            ORDER BY ID;"; 
    $result = mysql_query($sql) OR die(mysql_error()); 

//push the data into $data array to get it plotted 

while ($array=mysql_fetch_array($result)) { 
        $datum[$i]= strtotime($array[0]); 

// define graph 

$lineplot3=new LinePlot($humidity, $datum); 

$lineplot=new LinePlot($temp1, $datum); 

$lineplot1=new LinePlot($temp2, $datum); 



$lineplot_g2=new LinePlot($pressure, $datum); 
$lineplot_g2->SetLegend('air pressure'); 

// display graph 


Will give you a PNG Image containig the graph. Its pretty fast so no problem rendering it live.

Thats it1

howto/setting-up-a-small-wheather-monitoring-station-using-1wire.txt · Last modified: 2019/05/26 15:04 (external edit)