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.


7 comments:

  1. Dude,

    Back in November when you wrote this my life hadn't yet gone to crap, and I'm just now finding out what OWFS is for.

    I'm prayin' you got this sucker working on your Mac 'cause I need help.

    Short Form: 3.3Ghz overclocked MacPro1,1 watercooled to a DIY geothermal ground exchange. I've hit a wall pumping about 1000 Watts into the dirt. Can't even begin to guess on my next step to optimize or expand without more data- I need to pound Temperature sensors into the soil & track heat dispersion.

    If you've got the app up & are acquiring & analyzing, I really need to know how you did it, like step-by-step.

    Dammit Jim, I'm a Doctor- Not an Engineer!

    ReplyDelete
  2. Hi drrbc!

    I think pretty much all the instructions for installing the drivers etc. are shown above, since I tried to capture them as I went along; let me know if you get stuck on any of them.

    As for acquiring and analysing, I've actually not done much of that, since my studies have gone in another direction (but may well return), however, a simple shell-script should do the business; basically you just need to cat the files (e.g. temperature as above) into a log-file, regularly, if you want a progression), or parse the data taples...

    If all that sound like a bit too much hassle (it is), and you've got $155 to spare, I'd really think about getting one of these instead:

    http://www.embeddeddatasystems.com/HA7Net--Ethernet-1-Wire-Host-Adapter_p_22.html

    HTML access, and you don't need to install anything on your Mac!!

    ReplyDelete
  3. Not gone, just a busy month.

    So basically tie in 5 DS18S20's to a Cat5 ethernet at 2 foot intervals and plant one end 10' down in the dirt. Take the other end and plug it into the 1-wire hub (with the other 3 similar cables). Plug the hub into the USB adapter, fire up the software, and Bob's my uncle?

    Is it really that easy?

    ReplyDelete
  4. Erm, other way round?

    Connect the (buried) sensors to a 1-wire twisted-pair bus, chaining them if you like (says 100 devices or 1000 ft of cable), connect the other end of the bus to the HA7Net hub using an RJ11 connector, connect the hub to your network router using the ethernet port, and then you can read the sensors from your Mac using HTTP.

    Must get one! :)

    ReplyDelete
  5. OK, moment of seriousness here, 'cause when someone tells me something is "really that easy", it means I'm about to go on a long, painful journey.

    So, go to Radio Shack and buy the DS18S20's. Solder them in and weather proof (soil-proof) them with epoxy or similar, and plug in?

    "Star" topology from HA7Net hub (powered). 3 lines a) 30 feet, b) 45 feet, c) 60 feet. DS18S20's starting at the end coming back @ 2 foot intervals for 10 feet (they'll be buried to 20 feet. only interested in temps from 10 feet to 20 feet).

    Line 1 weight= 30+28+26+24+22+20=150 feet
    Line 2 weight= 45+43+41+39+37+35=240 feet
    Line 3 weight= 60+58+56+54+52+50=330 feet
    Total Weight= 150+240+330= 720 feet (<1000)

    Line 1, Line 2, Line 3 to HA7Net hub. HA7Net hub into MacPro's second Gigabit ethernet port. Launch Safari?

    Don't yank my chain pal. My wife says I have an uncanny ability to cause pain, and I have no problem spreading it around.

    So before I go on this eBay buying spree, is there anything else I need to know?

    ReplyDelete
  6. Sounds like you've got a firm grasp on it to me!!

    However there are a few things you should know:

    1/ I've not done this myself, nor used this piece of equipment.
    2/ I'm some random guy on the internet, who may well be speaking out of his derrière.
    3/ You'll never track me down... ;)

    Best of luck!

    ReplyDelete
  7. (LOL!!)

    Cool. I'll let ya' know!

    ReplyDelete