Thursday, September 01, 2011

one wire network

The HomeAutomation web application I am using has the capability to monitor room temperatures via a 1-wire network.

1-wire is a microlan which only uses 3 wires (5v, gnd, & data), and usefully can run over cat5 cabling, making it very easy to bolt onto an existing network. There are various sensors available, mostly in a TO92 transistor style package. Currently I have mostly temperature sensors (DS8120 variants).

If you only need a few sensors, then it's worth checking out the Maxim site as they offer samples for most of their sensors.

You also need an interface from the computer to the 1-wire network. This used to be via RS232, and there are simple circuits on the web, but as most computers now don't have RS232, USB is the next easiest and cheapest.

I chose the ibutton LinkUSBi available in the Uk from Homechip which has a RJ45 for plugging to a Cat5 network.

Here is the linkusbi complete with a 1-wire temp sensor connected to Cat5 via a connector block for testing.



To get the 1-wire network up and running, we need to install OWFS on the server. OWFS is a 1-wire file system which presents the information from the 1-wire network as a filesystem, which makes it extremely easy to poll the information at regular intervals

Compiling and installing owfs on a Pogoplug running Debian

First install the required modules

apt-get install automake autoconf autotools-dev gcc g++ libtool fuse-utils libfuse-dev swig python2.5-dev tcl8.4-dev php5-dev

add the following lines to /etc/modprobe.f/blacklist
blacklist ds9490r
blacklist ds2490
blacklist wire
download, extract, and the compile current versions of libusb and owfs from sourceforge
cd /usr/src/libusb
./configure --without-x
make
make install
cd owfs
./configure --enable-debian
make
make install
You then need to create /etc/udev/rules.d/56-owfs.rules and add the following lines to it.
SUBSYSTEM!="usb_device", ACTION!="add", GOTO="owfs_rules_end"
# DS2490 1-Wire adapter
SYSFS{idVendor}=="04fa", SYSFS{idProduct}=="2490", MODE="0666", GROUP="owfs"

LABEL="owfs_rules_end"
You then need to add a group, a user, and create a mountpoint for OWFS
add group owfs usermod -a -G owfs owfsuser mkdir /lwire
Connect devices by plugging in the 1-wire devices to the linkusbi and then plugging that into a spare USB port on the computer, then load the filesystem driver and start owfs
modprobe fuse
start owfs
/opt/owfs/bin/owfs -d /dev/ttyUSB0 /lwire --allow_other
You should then be able to walk the 1-wire filesystem, and list the directories.
Each device will be displayed as a separate directory named after the address as below:
ls /lwire
01.4AA873140000 alarm settings statistics system
22.D6331A000000 bus.0 simultaneous structure uncached
If you cd to one of the device directories, then more information is displayed:
/lwire/22.D6331A000000# ls
address errata id r_address temperature temperature12 templow
alias family locator r_id temperature10 temperature9 type
crc8 fasttemp power r_locator temperature11 temphigh
Next job is to get this information into a nice usable form...

No comments: