Pretty much everyone has a mobile phone. When you are doing ubicomp prototyping it is often difficult to do field tests on large systems because there is normally a shortage of devices you can use in a field trial, and/or it is difficult to get users to carry around and charge a secondary device. Bluetooth is an excellent method of approximating identity and proximity detection for ubicomp systems.

I have developed a really simple, fast, easy to use bluetooth scanning system, that users RSSI (Received Signal Strength Indicators) to determine Nearness/Far-ness, as well as perform Asynchronous name lookups, and find hidden bluetooth devices, for the use in prototyping systems that detect nearby users:


Alright, the title is a little bit grand. In any case, let it be known that I pretty much hate darwinports and fink, as something always seems to go wrong when I try to use them. [Although, they are very necessary for development in OSX — and I am certain I won’t be able to get by without them]

In this tutorial I will briefly explain how to tightly integrate VirtualBox into OSX as an Ubuntu Host. [This would probably work with other Virtual Machines, but I’ll use VirtualBox as my example because it’s free.

  1. First, Download and install VirtualBox from
  2. Second, download and a recent 32-bit ubuntu ISO from
  3. Install Ubuntu under VirtualBox, remember the name of your virtualbox, you will need it later — there are many tutorials around, and for anyone who wants ubuntu running in virtualbox, this should be pretty straight forward
  4. On ubuntu install some key packages:
    apt-get install ssh smbfs
  5. Also create a .ssh directory inside of your home directory (i.e.
    mkdir ~/.ssh


  6. Shut down your Ubuntu VirtualBox
  7. Open up a Terminal (on your OSX box)
    cd /Applications/
  8. Add this script as portfw.rb
    sudo bash # (you'll need to be root to create this script)
    if(ARGV.size < 4)
            print "Ussage: ruby portfw.rb    \n"
    print "Adding Portforwarding from #{ARGV[2]} to #{ARGV[3]} named (#{ARGV[1]} on VBOX:#{ARGV[0]}\n"
    print `./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/HostPort" #{ARGV[2]}`
    print `./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/GuestPort" #{ARGV[3]}`
    print `./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/Protocol" TCP`
  9. We’ll want to forward some of our local ports to VirtualBox for testing
    exit # to become non root again -- so you can see your virtualbox
    # ruby portfw.rb
    ruby portfw.rb ubuntu ssh 2222 22
    # for Rails Testing
    ruby portfw.rb ubuntu rails 3001 3000
    # for HTTP
    ruby portfw.rb ubuntu http 8080 80
  10. You can restart you virtual box now if you want.
  11. Now, let’s make it so we can mount our OSX drive from the virtualbox, without doing anything fancy — yes virtualbox has a virtual-drive, but it is horrible. (or was at the time of this writing). First, let’s add a local IP alias, so we can have a constant pointer to our SMB Share.
    sudo vim /etc/rc.local
    /sbin/ifconfig en0 alias netmask
  12. You can run this file by typing:
    source /etc/rc.local
  13. Now you want to make OSX share Samba — this is somewhat insecure, and you should probably tweak your firewall to prevent non-local connections. [I haven’t looked this up yet].
    1. In OSX, goto the sharing preference pane
    2. Check the box marked File Sharing
    3. Add a share (I share my homedirectory /Users/bcx )
    4. In the left panel make sure your User has Read & Write access to the directory also make sure Everyone has “no Access” and no one else has access besides you
    5. Under the [Options..] tab, check the box “Share files and folders using SMB” and “On” for next to your username
    6. Exit out of sharing.
  14. I ran into a few problems with SAMBA and Subversion. Which were causing some file permissions errors, and completely broke SVN over SAMBA. A combination of adding three configuration options to your /etc/smb.conf on OSX fixed the errors I got. Under globals you will need to add
        force create mode = 0777
        force directory mode = 0777
        delete readonly = yes
        # ....

    Once this is done you need to restart samba:

    sudo service smbd stop
    sudo service nmbd stop
    sudo service smbd start
    sudo service nmbd start
  15. The next step is to make it easy to log into your Ubuntu install. If you don’t already have one create a file called .bash_profile and .bashrc.
    vim ~/.bash_profile
    source ~/.bashrc

    Create an alias for SSHing locally

    vim ~/.bashrc
    alias sshl='ssh -p 2222 localhost'
  16. If you don’t have a public key, or don’t know what they are, you’ll need to generate one
    # type this in the terminal.  Leave the pass phrase empty, and use the default values
  17. Next copy your SSH key to your local virtual box (this one liner will do it)
    cat ~/.ssh/ | sshl "cat - >> ~/.ssh/authorized_keys"
  18. Now typing

    on the command line will ssh into your virtual ubuntu instance. We are almost there.

  19. log into your virtual box. IF for some reason RSA authentication isn’t working take a look at /etc/ssh_config and make sure that
    RSAAuthentication = yes
    PubkeyAuthentication = yes

    are set

  20. You are almost there, next step — setup samba
    mkdir /mnt/smb
    sudo vim /etc/fstab
    # add the line:
    //[osx_username] /mnt/smb smbfs user=[osx_username],uid=[ubuntu_username],password=[osx_password]  0 0
  21. Finally mount your OSX home directory inside of ubuntu
    sudo mount /mnt/smb

    And then make an easy to access symlink to it

    ln -s /mnt/smb ~/osx
  22. That should do it!  Now you can do cool things like edit files inside your home directory using textmate, and run them on ubuntu.

On a Mac change directories to:


vim portfw.rb

if(ARGV.size < 4) 
	print "Ussage: ruby portfw.rb    \n"  
print "Adding Portforwarding from #{ARGV[2]} to #{ARGV[3]} named (#{ARGV[1]} on VBOX:#{ARGV[0]}\n"

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/HostPort" #{ARGV[2]}`

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/GuestPort" #{ARGV[3]}`

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/Protocol" TCP`

This simple script will make it easy to port forward local ports to a NATed virtualbox.

I recommend adding local aliases for ssh and scp


# ~/.bashrc
alias sshl='ssh -p 2222'
alias scpl='scp -p 2222'

so you can just type

sshl localhost

So the IT people told me my harddrive on my macbookpro was dead, I assured them, that the hardrive was fine, and the real problem was that the motherboard had died. However, somewhere in the process I of trying to recover osx I managed to corrupt the partition table.

I tried a variety of tricks to recover the machine including: testdisk (do a google search you’ll find it right away), the OSX Installer Disk (both 10.4 and 10.5), and using the block numbers from testdisk to rewrite the partition table (testdisk won’t write HFS+ / MAC partitians for you).

Finally after fooling around with testdisk and fdisk after mounting the drive in my ubuntu box, I fired up gparted. Gparted could see my partitions just fine, but warned me that something weird was going on.

Somewhere in this process I tried to mount my drive using:

mount -t hfsplus /dev/sda1 /mnt/other

I got a bad superblock, which lead me to believe that I either needed to fsck — (a really bad idea if my partition boundaries were wrong) — or my partition boundaries were wrong, and all I had to do was find the right boundaries).

So I launched parted the command line program that gparted wraps. parted could see my partitions, but fdisk couldn’t. After much fooling around I deleted my partition table using parted (hey it wasn’t working anyway), and then used the parted, rescue command with the partition boundaries that were printed in parted when I typed “print”, but not mountable. In my case I typed

rescue 120M [some big block number]


Parted ran for a little bit, found my partition, and mounted it — no problem!


Key things to remember:
1) Don’t Reformat
2) Don’t run repair disk or check disk, or anything that might mess up your data
3) Every time something gives you a partition boundary (OSX / fdisk / pdisk / testdisk / disk utility) –> WRITE IT DOWN
4) I am pretty sure I burned the EFI partition at the beginning of the disk somewhere in this process, so for me it was essential to have an ubuntu computer to put my drive in, with enough disk space to back everything up. [luckily EFI takes up 120M or so at the beginning of the disk, so overwriting bits and pieces of it here and there weren’t a big deal, if all I was looking for was my main osx partition.

KEY = "asdasdjkdfgjk443534kjsdfs"
class Heart < ActiveResource::Base = "http://localhost:3000/"
    self.element_name = "heart"
Heart.create({:key => KEY})

I just wanted to lay claim to this quote, because right now it’s not coming up in google, and I want credit 🙂

I needed to copy a bunch of zone files over to slicehost, and I really hate doing work I can automate. I wrote a quick script that will import a zone file from a BIND definition into slicehost.

You can find it at:

On another note, ActiveResource is REALLY cool.

It’s been a while since I last posted, but I thought I should update the ‘world’ (i.e. myself) on some of the more recent accomplishments I have made towards the replay and ubicomp testbed systems I am working on.

1) I have successfully created easy methods of getting content from real live data streams and mocked up datastreams using eventheap as my tuplespace of choice.

2) I successfully built a bunch of ‘middle-ware’ so that my python code can talk to jython code and which in turn talks to the EventHeap over it’s native binary protocol. I am confident I could write a Python wrapper, but for the time-being this works fine, and also sufficiently abstracts publishing sensor information from the platform where sensor data is to be published.

3) I have been playing a lot with Pyro ( ) as a really simple replacement for XMLRPC. It solves a few problems I had using XMLRPC for example provides a name-server system so that services can ‘just run’ and you don’t have to worry about matching up ports to service names, and using ‘connections’ with a binary protocol reducing the overhead of parsing XML and using HTTP to manage connections.  It also created new problems, like requiring all exported objects to inherit from a common base-class, and not being as compatible with other RPC mechanisms in other languages, Pyro is still unstable for Jython.

And I think with that I’ll call it a night, there’s a lot of interesting discoveries to share.  I’ve leave you with this.  If your running the latest Jython or even 2.5a3 you better be running the latest java JRE, I had a problem where my jython RPC server took a few minutes to load ate up 100% CPU and timed out responding to connections.  I tried a variety of approaches to solve this problem, and finally just installed the lasted JDK and JRE (I was using the built in Sun distributed ubuntu java packages..)  — Note to others — Just get the JDK off of sun’s website, trying to debug something because the JRE is buggy is not the problem you want to run into.

For the life of me I could not get Jython to recognize my mysql driver using JDBC. I literally spent hours trying to get it to work. Fooling with my classpath, my version of the mysql-connector and my version of Jython. Finally I gave up and wrote a really simple wrapper class.

This is the Error:

#the following line is “print sys.path”
[‘./mysql-connector-java-5.1.6-bin.jar’, ‘/Volumes/UserHome/bcx/work/istuff/iros/jar’, ‘/Volumes/UserHome/bcx/jython2.5a3/Lib’, ‘__classpath__’, ‘/Volumes/UserHome/bcx/jython2.5a3/Lib/site-packages’]
Traceback (most recent call last):
File “”, line 12, in
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(

java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: com/mysql/jdbc/Driver

So I dealt with various version of that error for a while. Finally I gave up and wrote a wrapper class, which didn’t work until I downloaded and installed jython 2.5a3, previously I was using the latest stable, 2.2.1.

Here is my quick wrapper class:

import java.sql.*;

public class Connect
public static Connection getConnection(String url, String usr, String pass) throws Exception{
Class.forName (“com.mysql.jdbc.Driver”).newInstance ();
return DriverManager.getConnection(url, usr, pass);

Here is how I used it in my Jython code.

import Connect
import sys

url = “jdbc:mysql://localhost/replay”
con = Connect.getConnection(url,”root”,””) #this line uses my wrapper

stmt = con.createStatement()

In other news I implemented a mDNS enabled mysql-based indexed logger for EventHeap. The next step is to build a simple interface for replaying marked logs. I really wish I could write this interface using a language other than Jython or Java, so the next step will be fooling around with my various options. I am not sure if I am feeling adventurous enough to try out JRuby, but Ruby on Rails would be a nice way to build a really quick web front end. I am leaning towards some sort of Jython based EventHeap RPC server, that has “jobs” which can be started / stopped/ monitored/ and modified over REST or XMLRPC. This shouldn’t be that bad, but I “really” would prefer to do the network code using twisted, although I think the “goal” of this stage, is to pretty much hack this thing together asap.

I’ve recently been playing with Stanford’s EventHeap and IStuff package for some of the work we are doing here.  I am a little to spent to go into a lot of details, but the first task I tackled was trying to write some wrappers to make it easier to work with EventHeap using mDNS.  This was far harder than I thought it would be.  I kept running into a problem where I would get a serviceAdded event, but the event would not have enough information for me to actually connect to the service.

I am using the jmdns.jar package:

Here is the scenario I was trying to address:

  1. Server registers it’s self using mdns using service _eheap.
  2. Sometime after this, a client application listens for services on _eheap.
  3. Client connects to server.

Unfortunately when I worked in this order I ran into the problem that the event object that mdns passes to serviceAdded did not have enough information to make a connect to the remote host.

I didn’t see any good example of how to do this.  I am sure I am probably doing something wrong.

If I did everything in this order it worked fine:

  1. A client application listens for services on _eheap.
  2. Server registers it’s self using mdns using service _eheap.
  3. Client connects to server.

However, for my purposes, I absolutely need the server to be able to start before the clients that are listening for that service.

I also just wanted to be able to write very simple code to lookup a device using mdns.  I.e. I wanted to be able to write small quick scripts, that were not event driven to connect to a service advertising itself on mDNS.

After tracing through the jmDNS code I found out that the objects actually had all the information I was trying to get, but were not providing an easy interface to it.  (There may be easier interfaces, but there is literally no documentation on jmdns that I could find)

To this end I have written a very simple Jython wrapper for mDNS which provides a few VERY simple interfaces to mDNS / ZeroConf/ Avahi / Bonjour, with the specific goal to provide authors writing very simple scripts, methods to connect to a service that is advertising itself using mDNS.

I have posted this Jython file at:

DISCLAIMER: This is the first application I have ever written in Jython, and I have only been playing with mDNS for about 2 days.  Thus, this may be completely wasted effort; however, it seems to work well for my purposes.

The interface: 0.1

    Ben Congleton,

    Jymdns is a simple jython interface to the mdns library.



  I could not for the life of me figure out how to use the JAVA mdns library, when I was trying
  to listen for hosts that were created before the mdns listener.  There is probably a way around this.

  This is really just a hack to use the local mDNS cache to find out information about services that
  are not responding to the event.getInfo() command.  With a few nice interfaces for writing really
  quick scripts in jython that need a simple way of finding a host on a network.


    from jymdns import SimplemDNS

    simp = SimplemDNS("_eheap")
    simp.register("foo33", 1234)

    # do all the real stuff

    simp.stop()   # stop the mDNS broadcaster

  FINDING A MDNS HOST for a service (ignoring the name):

    from jymdns import SimplemDNS
    res = SimplemDNS.get_service("_eheap")

      (host, port) = res


    from jymdns import SimplemDNS
    res = simp.wait_for(None)

      (host, port) = res


    java -jar jython.jar


document.onkeydown = function(e) {
  var a = document.getElementById("test");
  a.innerHTML = a.innerHTML + String.fromCharCode(e.which);

  var a = document.getElementById("test2");
  a.innerHTML = a.innerHTML + e.which + " " ;    

  return false;

<div id="test"></div>
<div id="test2"></div>

SmartButton TM –>

So I got my hands on a smartbutton from sourceforge while at today’s SOCHI/SCSI event.

I was curious how it worked, so I wrote a very simple javascript to capture all keyboard input into the browser window and print it to the display.

Interestingly the SmartButtonTM acts just like a keyboard, and sends the following keycodes to the active window, or OS:

224 82 87 87 87 190 83 79 85 82 67 69 70 79 82 71 69 190 78 69 84 13

Which is essentially APPLE_CMD+R + [enter] was a very useful and very interesting read.