Sunday, 28 November 2010

1-wire using owfs

For my MSc, I wanted to monitor and log temperature and humidity in various parts of my house; one of my lecturers suggested iButtons from Maxim.

On the Maxim site various C and Java APIs are offered, but I've been unable to get these working on the Mac, trying rxtx libusb etc. all in vain. Works in Windows (of course) because they supply a driver which makes the USB-Serial adaptor (DS9490R) act like a COM port. No such driver for Mac.

Eventually I came across owfs (http://owfs.org/), which is a 1-wire file-system plug-in for Fuse. I managed to get it working in Ubuntu Linux (under Parallels), and there seems to have been a fair bit of work done on a Mac port of this, but it's not quite out-of-the-box yet.

After a lot of messing around and Googling, he're how I got it working on MacOS X Snow Leopard 10.6.5; I hope this step-by-step guide saves someone some time...


Installing owfs
tar -zxvf owfs-2.8p3.tar.gz 
cd owfs-2.8p3/
  • Configure the build, disabling stuff that doesn't work (zero and owphp give compile errors, owtcl install error - sorry if you want to use zeroconf, php or tcl!)

./configure --enable-usb --enable-owfs --disable-zero --disable-owphp --disable-owtcl
  • Now hack around with the build config:
(Some of these tips originally from Peter Radcliffe at http://owfs.org/index.php?page=macintosh modified to work for me!)
    • Fix libtool config:
mv libtool libtool.orig
awk '/^# ### END LIBTOOL CONFIG/, /^# Generated from ltmain.m4sh/ {next} \
     {print}' \
   < libtool.orig > libtool

    • Replace VOID_RETURN with NULL (missing include with --disable-zero?):
perl -pi -e 's/VOID_RETURN/NULL/' module/owlib/src/c/ow_avahi_browse.c
    • Edit config.status change libuse to libfuse_ino64 (else get Input/output error when listing owfs filesystem:
perl -pi -e 's/-lusb/-lusb_ino64/' config.status
    • Now Make and Install:
make
sudo make install

Software ends up in /opt/owfs


Using owfs

Now it's time to mount up; put in your USB adaptor and...

mkdir /Volumes/1wire
(make mount point)

/opt/owfs/bin/owfs -u /Volumes/1wire
(mount 1-wire bus)

Now you have access to all the devices, get in there and cat about:

$ cd /Volumes/1wire/
$ ls

21.7ACE26000000 alarm settings statistics system
81.FB9F2D000000 bus.0 simultaneous structure uncached
$ cd 21.7ACE26000000
$ ls
about alarm_state histogram overtemp temperature
address alarm_trigger id pages type
alarm_dow alias locator r_address undertemp
alarm_hour clock log r_id
alarm_minute crc8 memory r_locator
alarm_second family mission set_alarm
$ cat temperature
$ cat temperature 
          19$ 

Now one can start messing around with scripts to harvest the data, and start 'missions' etc. This guy looks like he knows what he's doing: http://owfs.org/index.php?page=garden - RRDTool is available from MacPorts.