We just had the hybris customer and partner days in Munich, a full week of hybris labs duty and we ended the week with an open spaces un-conference with our partners. This is also the reason why it did become a bit quiter on this blog over the last few weeks and christmas. Nevertheless, we’re back. During the open spaces conference I had the pleasure to join a iBeacons/electronics/BLE/all cool stuff conversation and among the guests was Alex Sbardella from Red Ant. He mentioned that one could build an iBeacon using a Raspberry Pi and a BLE dongle and was kind enough to follow up with the link to the original article this was mentioned in from Adafruit. I was able to install this on one of our PIs here and as I had a few minor issues which I was able to solve in the end I thought this makes an excellent blog post for the techblog. Here we go, self-made iBeacons with Raspberry PI.
For the following, I assume you have the Raspberry Pi setup with Raspbian, the default OS of the Pi. Also, you will need a BLE dongle and as Alex noted, there seem to be differences. I was ordering this BLE dongle here that works for me. One should maybe note at this point, that the total price of all components included in this setup will be higher than a single Estimote beacon. But this is for dev and the value herein is the flexibility to define the iBeacon the way you want it.
So let’s start with installing some libraries that will be required. And just to make sure, you should update the package list and upgrade the apt system, too:
sudo apt-get update sudo apt-get upgrade sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev
Next, we create a new directory for the bluez bluetooth utility that will later be our coomand line tool for the bluetooth dongle. Download the bluez build 5.11 or feel free to explore a more recent version if you like.
sudo mkdir bluez cd bluez/ sudo wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.11.tar.gz sudo tar xvf bluez-5.11.tar.gz cd bluez-5.11/
Before we can get the bluetooth dongle up and running, we need to build the software from scratch. This will take a while, so grab a cup of coffee in between:
sudo ./configure --disable-systemd sudo make sudo make install
At this point the bluez bluetooth software should be compiled and installed on your PI. Shut down the Pi and add the bluetooth dongle that you bought, then fire up again.
The hciconfig tool should be available, as it is part of bluez. If you just type hciconfig, you will see the basic information of the bluetooth dongle that hopefully was detected. We will now perform three steps: enable the dongle, turn on advertisements and then turn off the scanning for devices (as it can interfere with the advertising).
sudo hciconfig hciO up sudo hciconfig hci0 leadv 3 sudo hciconfig hci0 noscan
If this all completed successfully, we are now able to overwrite the Manufacturer Specific Data (MSD) for the advertising packet that is sent out. Adadruit did a great job explaining the parts of the MSD which I will not repeat here as they’ve done an excellent job.
sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00 00 00 00 C8 00
At this point, the BLE dongle should be advertising and you should be able to scan for the iBeacon. There are Apple iOS apps available to scan for beacons, but Android from 4.3 on is also able to run iBeacon scanners. I am using the iBeacon Locate app from Radius Networks – they btw also have an excellent Android library for scanning iBeacons.
The fun comes in, when you realize that you can change the MSD, meaning you can tweak the data in the advertisement packets. For example, you might want to increase the minor field, which is typically used to differentiate nodes within one location (e.g. the major field is used to differentiate the store location, the minor the location within a specific store). This can easily achieved by changing the minor version fields to this for example:
sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00 00 00 01 C8 00
If you have the iBeacon scanner app open and active, you’ll see how first a new beacon joins the list and then after some seconds the old beacon that is now no longer advertised is removed. Pretty cool!
It would be great to hear your stories around iBeacon – let us know what you think in the hybris Technology Google+ group.