Home automation

1-wire Temperature monitoring

Hardware

NSLU2 DS9490R DS18S20


Network

Telephony cabling with RJ11 (MOD64) connectors and 4-wire cable is used for network wiring.

The connector pinout is not standard. Here is the pinout and color coding that I'm using. The idea is to use middle 4 pins of the MOD6 connector. The pinout is not the same as in DS9490R adapter and an adapter cable is required. In DS9490R, RJ12 (MOD66) connector is used having Vdd in pin 1. In RJ11 (MOD64), left- and rightmost pins are not connected, thus pinout needs to be changed in order to use cheaper 4-wire system for cabling.

RJ11 colors

Pin Signal Description Color
1 NC Not connected
2 GND Power Ground Black
3 VDD +5VDC Red
4 OW 1-wire Data Green
5 OW_GND 1-wire return Yellow
6 NC Not connected

Standard passive RJ11 components like hubs, splitters and extenders are used to span the 1-wire network.

If RJ45/CAT5 cabling is used, the pinout of RJ45 connector is as follows. Ethernet 10/100BaseT(X) uses 4 wires out of the total 8. Thus it is possible to drive Ethernet and 1-wire signals in the same CAT5 cable.

Pin Signal Description Color
1 NC Ethernet TX+
2 NC Ethernet TX-
3 NC Ethernet RX+
4 OW_GND 1-wire return Yellow
5 OW 1-wire data Green
6 NC Ethernet RX-
7 VDD +5VDC Power Red
8 GND Power Ground Black

Software

Screenshot of web user interface:

Debian

OWFS

Temperature readings are available at /mnt/1wire directory.

Gnuplot

Gnuplot 4.4 or higher is needed for graphics generation. If that version is not available from package repository, is has to be build manually. Gnuplot sources are available from SourceForge:

http://sourceforge.net/projects/gnuplot/files/

Libgd is required for graphics file format support. It is available in debian armel packages:

# apt-get install libgd2-xpm libgd2-xpm-dev

Then build it in the usual manner:

./configure
make 
make install

Version 4.4 or higher is available in repository, simply install it:

# apt-get install gnuplot 

Lighttp

Install lightweight http-server lighttp

# apt-get install lighttp

Scripts (out-of-date) *

Enable Server Side Include (SSI), with following changes to /etc/lighttpd/lighttpd.conf file:

server.modules  = (
          "mod_access",
          "mod_alias",
          "mod_accesslog",
          "mod_ssi",
          "mod_compress",

ssi.extension                   = ( ".shtml" )

index-file.names           = ( "index.php", "index.html", "index.shtml",

Now restart http server to make changes effective

# /etc/init.d/lighttpd restart

I have created subdirectories /var/www/temperature and /var/www/temperature/script

Under temperature folder, a simple shell script executed daily be crond creates sub-directories for each day:

/var/www/temperature/<year>/<month>/<day>/

Another shell script collects temperature data once every minute and stores it to data.txt file in day-folder defined above.

Finally gnuplot renders a graph one an hour on stores it in day-folder.

The three script files are:

create_dir.sh

#!/bin/bash

PATH=/var/www/temperature
YEAR=`/bin/date +%Y`
MONTH=`/bin/date +%m`
DAY=`/bin/date +%d`

if [ ! -e $PATH/$YEAR ] 
  then
    /bin/mkdir $PATH/$YEAR
fi

if [ ! -e $PATH/$YEAR/$MONTH ] 
  then
    /bin/mkdir $PATH/$YEAR/$MONTH
fi

if [ ! -e $PATH/$YEAR/$MONTH/$DAY ]
  then
    /bin/mkdir $PATH/$YEAR/$MONTH/$DAY
fi

exit 0

log.sh

#!/bin/bash

DAY=`date +%Y/%m/%d`
LOGFILE=/var/www/temperature/$DAY/data.txt

echo -n `date +%Y-%m-%d_%H:%M` >> $LOGFILE
cat /mnt/1wire/uncached/10.7F0939010800/temperature >> $LOGFILE
echo "" >> $LOGFILE

exit 0

gnuplot.conf

set terminal png
set xdata time
set timefmt "%Y-%m-%d_%H:%M"
set output "/var/www/temperature/`date +%Y/%m/%d`/temperature.png"
set xrange ["`date +%Y-%m-%d`_00:00":"`date +%Y-%m-%d`_23:59"]
set yrange [0:30]
set grid
set xlabel "Time"
set ylabel "Temperature [C]"
set title "`date +%Y-%m-%d` updated `date +%H:%M`"
set key left box
plot "/var/www/temperature/`date +%Y/%m/%d`/data.txt" using 1:2 index 0 title "Livingroom" with lines

Crond is configured as follows, with crontab -e command, to execute abowe scripts.

# m h  dom mon dow   command
* * * * *       /var/www/temperature/script/log.sh
59 23 * * *     /var/www/temperature/script/create_dir.sh
59 * * * *      gnuplot /var/www/temperature/script/gnuplot.conf
1-wire.txt · Last modified: 2011/02/20 19:59 by jap
Recent changes RSS feed CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki