Build a DIY iBeacon with a Raspberry Pi

Christian Cawley 01-09-2015

Advertisements targeted to a particular user walking through a metropolitan center are the stuff of dystopian futures, demonstrated notably by the Tom Cruise movie Minority Report. But that isn’t a dystopian future: the technology is already here. Although it doesn’t rely on rapid identification using your retina, it does use Bluetooth. Developed by Apple, iBeacon was developed to provide location-based information to iOS users How Bluetooth 4.0 Is Shaping the Future of Mobile Connectivity Bluetooth is the forgotten star on the device specifications sheet. Read More , using a device’s proximity to trigger a personalized advertisement or track a user’s movements. Google also created their own versatile Beacons specification, although support for that is limited at present as developers get to grips with it.



Unsurprisingly, you can use a Raspberry Pi as an iBeacon, by adding a Bluetooth low energy (BLE) USB module. More interestingly, we can co-opt this technology and abandon the futuristic advertising methods in favor of uses around the home.

How iBeacon Works

Building a low energy Bluetooth transmitter that smart devices apps can detect is straightforward, but how does an iBeacon work?


BLE is designed specifically for transmitting over short distances, but with lower power requirements (a single coin cell battery should last three years). Small packets of data, known as “advertisements” (not in the marketing sense), are broadcast by the beacon and used to trigger actions in smartphone apps, perhaps display a commercial message, or prompt the reader to perform an action.


Beyond marketing, iBeacons are typically used to push location states to an app, such as displaying information about an exhibit while you’re walking around a museum.

Build Your Own iBeacon with a Raspberry Pi and a Bluetooth Dongle

To use your Raspberry Pi as an iBeacon, you’ll need a Bluetooth USB adapter. However you can’t just attach any old Bluetooth USB device. Instead, you’ll need to use a BLE (Bluetooth low-energy) device, which can be purchased relatively cheaply from Amazon or Adafruit. You can run this project on a standard Raspbian installation Optimize The Power Of Your Raspberry Pi With Raspbian As befits a man with too much tech on his hands, I’ve been playing with my Raspberry Pi recently, configuring the device so that it works to its fullest potential. It continues to run as... Read More , either installed the usual way How to Install an Operating System on a Raspberry Pi Here's how to install an OS on your Raspberry Pi and how to clone your perfect setup for quick disaster recovery. Read More or via NOOBS How NOOBS For Raspberry Pi Can Help First Time Users There is something about the Raspberry Pi that might just put people off: until now, setting it up has not been particularly user friendly. NOOBS aims to change that! Read More .

(If you want a shortcut to all of this, the PiBeacon image is your best bet, from RadiusNetworks. Simply download, write to SD card and boot.)

Before attaching the BLE, however, it’s time to install some libraries:

sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev

Now this is done, you’ll need to install Bluez, the Bluetooth stack for Linux.

sudo mkdir bluez
cd bluez
sudo wget


Once downloaded, Bluez must be built.

sudo unxz bluez-5.11.tar.xz

sudo tar xvf bluez-5.11.tar

cd bluez-5.11

sudo ./configure --disable-systemd

sudo make

(This step can take some time. Go and make a cup of tea. Or bake a raspberry pie.)

sudo make install

You’re almost ready to go. Issue a shutdown command, and then when the Pi is powered down, connect the BLE.

sudo shutdown -h now

Broadcast the PiBeacon

To configure the PiBeacon for broadcasting, check first that the BLE module has been detected


You’ll notice that if the module is detected, its status is currently DOWN.

To resolve this, configure the device:

sudo tools/hciconfig hci0 up

sudo tools/hciconfig hci0 leadv 3

sudo tools/hciconfig hci0 noscanc

(Note that the final line disables Bluetooth scanning, as this can cause issues.)

Repeat the earlier command to run hciconfig:


You’ll now see the device status is UP RUNNING.

How Do You Advertise with the PiBeacon?


So you’ve got a working iBeacon, powered by a Raspberry Pi. But how do you use it to identify itself to nearby Bluetooth devices? As explained by Adafruit, the beacon needs advertising data to be entered. They advise the following string be entered with the hcitool command:

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

What’s in the Data Packet?

Yes, that is a long string of numbers and letters. It’s written in hexadecimal, and although we can’t see it, the string is split up in to sections. For instance, the mark FF indicates that manufacturer-specific data will follow, in this case the 4C 00 which is Apple’s ID. This string can be changed as appropriate.

Let’s break it up:


As you can see, the string means little until you can see what each segment of data is for. Note that the ID will always be the same, to identify the packet type, and that the Data Length needs converting to decimal in order to appreciate the actual length of the packet.

With the FF mark we see the 128-bit ID as explained above, followed by the Major data and the Minor data. These identify locations or notes in a hierarchical manner (major first, minor second). Finally, the TX Power helps to estimate distance.

The PiBeacon, like an iBeacon, has three ranges: immediate (localised to a few centimeters), near (a few meters) and far (around 10 meters). Any measured distance is only approximate as the BLE signal is weakened by furniture, and doors and walls.

If you plan on using the iBeacon technology, having a unique ID for your app is important. You might use something like or if you use a Mac, the command line uuidgen utility will generate a unique ID.

PiBeacon is Live!

With this entered, the PiBeacon is now advertising. All you need to do now is find a suitable iBeacon app on the iOS store such as Beacon Toolkit [No Longer Available] to detect it, selecting Listen. The string above is provided as a UUID in the Beacon Toolkit app. Other UUIDs can be used, but these will not work with that app: use the slightly more expensive Beacon Toolbox ($4.99), which should be able to identify most all iBeacons within range.

Unhappy about dedicating a Raspberry Pi to this single task? Don’t worry – you can build an Arduino iBeacon instead, as long as you have a BLE shield (which may be available in your Arduino starter kit What's in Your Arduino Starter Kit? [Arduino Beginners] Faced with a box full of electronic components, it's easy to be overwhelmed. Here's a guide to exactly what you'll find in your kit. Read More ). Here’s a demo:

Feeling even more adventurous? $10 worth of electronics and some soldering skills Learn How to Solder, with These Simple Tips and Projects Are you a little intimidated by the thought of a hot iron and molten metal? If you want to start working with electronics, you're going to need to learn to solder. Let us help. Read More will also net you a DIY iBeacon [Broken URL Removed].

Questions or comments? Leave them below.

Related topics: Bluetooth, Raspberry Pi.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Anonymous
    September 8, 2015 at 4:12 pm

    With regard to the DIY link, using the solar cells and batteries from inexpensive solar garden lights would be excellent for something like this. The batteries/solar cells can be wired in series and a weatherproof case used. However, keeping the existing 1.2v rechargeable batteries and utilizing a solar cell would be great also. My point I guess is that you can use a semi self sustaining power, not having to worry about changing batteries for longer periods of time.