Monday, February 6, 2012

Findings on Bluetooth connectivity between iPhone & Android

I tried to come up with a way to discover iPhones and Android phones via Bluetooth in both directions in the last couple of days. As a tech-savvy, that sounded like a piece of cake: The Bluetooth menus on both devices feature a "discover" and "discoverable" feature, right?

On Android, everything went smooth. Except, you can't set a device to be discoverable for an unlimited timespan.

Then came the iPhone: In brief, it doesn't work. In detail, this is what I tried:
  • Looked for a Bluetooth API. There is none except iOS 5's Bluetooth 4 Low Energy (LE) one, which requires a BT 4 capable hardware - which is only the iPhone 4S currently. On my iPad 2 it doesn't discover anything. Same on my neighbor's iPhone 4S: Obviously, this API can only detect low range BT 4 LE devices. The "dual-mode" (enabling the chipset to run in the otherwise incompatible 2/3 and 4 versions, according to Wikipedia) seems unsupported.
  • Looked for 3rd party frameworks. There are some, but they require a rooted iPhone and/or take any chance of getting the App into the App store.
  • The high-level API called GameKit is only able to connect to other iOS-devices, and there are quite some people who tried to connect somehow - without success.
  • Tried to use the Bonjour low-level API (dns_sd.h) and found two problems with that:
    1. Discovering services via Bluetooth unsurprisingly only seems to work on active Bluetooth connections: I paired and connected my iPad to my Mac (had to initiate the connection from the iPad to the Mac, the other way does not seem to find a usable combination of profiles). After disabling WiFi on the iPad, I ran the BonjourWeb sample on it and
      dns-sd -A
      on the Mac to get provide a Bonjour service to be discovered. Success! The iPad discovered the sample service (Proof: disappeared when stopping the service on the Mac). The bad news: The iPad didn't discover anything as soon as the Bluetooth connection was dropped (without even touching the pairing). Side note: Without an active connection, the Mac doesn't provide a Bluetooth interface that Bonjour can bind to, so even if iOS didn't require an active connection, the other side probably would anyway. Learned assumption: iOS probably accepts Bluetooth GameKit connections (i.e. Bluetooth PAN(U) connections) temporarily without asking the user to provide a link-layer to Bonjour...
    2. I tried to setup Bonjour (zeroconf) via Bluetooth on Android. I used the existing JmDNS for that, which is capable of binding to any device that has an IP. I quickly found that the Android Bluetooth API doesn't support the PAN(U) profile (starting with Android 3.0, the API seems extended though), and even on my rooted Android phone I would have needed to add some kernel modules... Plus, JmDNS also requires an IP address that is only assigned after a connection has been established (that's the behavior on my Linux box at least).
So for now, iPhone apps stay blind when it comes to discovering other "smart" Bluetooth devices: Be it Android-phones, Linux boxes or even Macs...

(post has been updated on Feb 8)