Sunday, 15 December 2013

Bluetooth 4.0 LE Beacons on the Raspberry Pi

To make a Raspberry Pi act like an iBeacon, there are two great pages to read here and here. TL;DR: build bluez-5.11 or greater from source, plug in your USB dongle, then type some command line incantations into the Bluetooth subsystem (see below).

Attached is a picture of the four BLE USB dongles that I discovered that have a compatible chip in them, the Broadcom BCM20702A0:


The IOGear one (used in the linked articles above) is hard to track down here in the UK. However, the Trust and Belkin are available in the UK high street at PC World. The Plugable [sic!] also seems easy to get, by mail order.

You may need to tell the Bluetooth driver module to start and to recognise the device, like this:

modprobe btusb
echo 0a5c 21e8 >> /sys/bus/usb/drivers/btusb/new_id

The Belkin is the odd one out, having different Vendor/Product IDs. This requires the following incantation to get the btusb driver attached:

modprobe btusb
echo 050d 065a >> /sys/bus/usb/drivers/btusb/new_id

If you type usb-devices and look for the device, you'll see the Broadcomm BCM20702A0 entry and those two codes up there. It may say Driver=(none)until you do one of the above commands, when it'll turn into Driver=btusb.

The magical incantations I mentioned are:

hciconfig hci0 up

hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 00 00 00 00 00 00 00 00 00 00 00 00 00

hciconfig hci0 leadv 3

It probably goes without saying that plugging the dongle directly into the R-Pi will bring it down, due to the power surge, but I found that it rebooted eventually and carried on fine. Or just use a hub.

If, like me, you want to do this four or six times, you'll need the UUID or major/minor fields in the long string above to differ. See the linked articles above for details.

Check your beacons are working using this great Android app. It has a distance-to-beacon mode in big monochrome fonts that look impressive as you wander the house, waving your phone around.

No comments:

Post a Comment