Thursday, December 20, 2007

Bluetooth Presence for Work and Play

Imagine your environment being aware of your presence. The environment comforts, conforms, and contextualizes. The environment also informs you of upcoming meetings, teammate requests, or refreshes your context on work you would like to re-engage. In a cafe, patterns of patrons form a familiar scene: sipping, reading, talking captured in an abstract rendering of presence.

Bluetooth Tracking

But how do you make this happen? One answer is through bluetooth tracking. Another way is with a Wireless Key Lock. Bluetooth tracking is popular because many phones, gps devices, pdas, and laptops already support bluetooth. Bluetooth devices will emit their device name, MAC address, and services without any requirement of authentication or connection request. In addition, this information is enough to provide an unique identification of a user. Bluetooth's radio range can effectively detect presence within 32 feet (10 meters). However, it can be as extensive as 328 feet (100 meters).

Bluetooth Software Development

Despite the ubiquitousness of bluetooth technology, information regarding bluetooth programming on the desktop is sparse. The common case is to develop bluetooth in the context of mobile devices, or J2ME midlets. On the desktop, once a bluetooth device has been connected you can communicate through COM serial ports or through sockets as a HID device. However, if you want to access to the radio to do device discovery, then you need to access the Bluetooth Stack APIs.

Bluetooth Stacks

Two common Stack SDKs are the Microsoft Stack for XP SP2 and Vista, and the Broadcom (Formerly WIDCOMM) Stack. Blue Soleil provides a commercial stack with good HID support. Unlike the Java bluetooth API, there isn't a good abstract layer over these different vendor stacks.

Microsoft Stack

The best example I found for performing discovery with the Microsoft Stack was described in this article. In this code example, they wrap the Win32 API Bluetooth calls and demonstrate how to call these in C# managed code. As it turns out, my Thinkpad uses the WIDCOMM driver, so this does not work for me.

WIDCOMM Stack

João Paulo has provided an excellent wrapper abstracting the Microsoft Stack and WIDCOMM Stack for C#. The problem is that this was written for the Microsoft Compact Framework for mobile devices.

C# Discovery Demo

Based on João's work, I was able to port a subset of his code create a simple C# demo for performing bluetooth discovery with a WIDCOMM Stack. Check it out [download].