Projects‎ > ‎

iBeacon for Desktop

iBeacon is a technology introduced by Apple, which is based on Bluetooth 4.0. It uses GATT profiles to create a network of mobile/low energy devices that work in a producer/consumer fashion. An iBeacon is a transmitter which sends its UUID encoded in an advertisement message. That UUID may be associated with a product, place, item, food, anything... so, as the message reaches the receiver device, a host app installed on it may then search for that UUID on a remote server and interpret that information as a specific event.

This technology is mobile driven, so almost all players are focused on create solutions for iOS, Android, Windows Mobile, and other mobile OSs. It's simple and powerful, but we could use it for other purposes than mobility, don't you think? Well, here it is an example. Let's suppose I have an authorization process that runs on several places. Each place has its own rules and different prices for the same items. So if I authorize an item without knowing where it is, maybe I'll be losing money. That way, iBeacons can help us. It is a low cost solution and easy to implement/integrate. I can fix an iBeacon on a given point of the place I want to certificate and use a Bluetooth 4.0 USB Dongle in each of the desktop, used by the attendants. The application running on each Desktop will then look for a given iBeacon UUID, which must be associated with that place. Voilá! We've implemented a physical place certification mechanism.

In order to make a Bluetooth 4.0 dongle detects an iBeacon we need 3 elements: dongle driver, a Bluetooth 4.0 Stack and the final application. The harder part is to find a Stack. Windows 8 has a native BT4.0 Stack, iBeacon ready. However, if your desktop stations use an older version of Windows, here start the problems. The BT4.0 Stack is a piece of code that fits above the driver, it is used to manipulate the BT profiles, provided by the hardware/driver. Windows XP and Windows 7 32/64 don't have a native Stack for BT4.0. So I've decided to use BTStack to create my own solution. The application which controls the authorization process is written in Java. So, I've created a library using JNI. It contains only three operations.
  • startScanning: do the basic hardware configurations and set the BT device on to listen events
  • eventHandler: called every time a new advertisement is detected.
  • stopScanning: to finish the main loop and set the BT down
Generic dongle BT 4.0

Both startScanning are native (JNI) methods and eventHandler is an abstract method, called internally by the library after each event. Here it is an example of how to use the iBeacon scanner class:

public class iBeaconDemo extends iBeaconScanner {
    public void eventHandler( iBeaconEvent event ) {
      if ( event.getData( ).length( ) > 50 ) {
        String data = event.getData( );
        String uuid = data.substring( 18, 26 ) + "." + data.substring( 26, 30 ) + "." + data.substring( 30, 34 ) + "." + data.substring( 34, 38 ) + "." + data.substring( 38, 50 );
        System.out.println( "UUID: " + uuid );
      } // if
    } // if
    public static void main( String[] args ) throws Exception {
      iBeaconDemo iBeacon = new iBeaconDemo( );
      iBeacon.startScanning( );
      // captura iBeacons por 20 segundos
      Thread.sleep( 20000 );
      iBeacon.stopScanning( );

I've uplodaded here two files, the source code I've created using BTStack and libusb to implement the project and iBeacon.jar, which contains the binary libraries for Windows 32/64 and Linux 64, besides the Java Native class and a demo class.

To use this solution, do not use the factory dongle driver. Please, install Zadig for Windows XP (5.1 MB) or  Zadig for Windows Vista or later (4.9 MB). It will prepare you environment with the correct driver for BTStack.

after that, just execute:

java -jar iBeacon.jar 20

It will start the main method of the class util.iBeaconDemo and will stay capturing advertisement events for 20 seconds. Its output will be something like that:

RSSI: 191 Type: 2 Event type: 0 Flags: (4) [false;false;true;false;false] Company ID: 4C00 Beacon Proto: 02 Beacon Length: 15 UUID: B7E833FD.49D1.49AD.8B23.8C9C5D5B67DE Major: 0001 Minor: 1364 Power: 90 Distance: 8.91250938133746E-6

That's it, use it in your project as you wish! :)