Turning Your Raspberry Pi 3B+ into an iBeacon Signal Transmitter (DIY)

Batuhan Koyuncu
4 min readFeb 24, 2019

--

This publication will show you how to transmit iBeacon signals via using your Raspberry Pi 3B+.

Instructions will be covered for model 3B+ since it has it’s own Bluetooth 4.0 device embedded. Else, you may need to provide an external bluetooth USB device.

1.1 Libraries

First, we get the required libraries. There are open source libraries below(which is pretty useful):

sudo apt-get install libusb-dev
sudo apt-get install libdbus-1-dev
sudo apt-get install libglib2.0-dev — fix-missing
sudo apt-get install libudev-dev
sudo apt-get install libical-dev
sudo apt-get install libreadline-dev
sudo apt-get install libdbus-glib-1-dev

Each of these libraries permits us to modify and make changes in Raspberry.

1.2 Configuring Bluetooth Settings

In this part, we then configure our Bluetooth drivers. You can check the current version of your BlueZ with:

bluetoothd -v

If there is a newer version exists, first we delete the older version:

sudo apt-get — purge remove bluez

After we removed the older version of the BlueZ, We then remove the older packages too:

sudo apt autoremove

For the installation, pick a directory to download the (usually) zipped version of BlueZ. (you can check the most recent variant on its website, too.) We will download, make and install the prerequisities,such as libraries, in order to support the core Bluetooth layers and protocols:

pi@hoa:~ $ mkdir bluez
pi@hoa:~/bluez $ wget www.kernel.org/pub/linux/bluetooth/bluez-X.XX.tar.xz

After the installation, then unzip it:

pi@hoa: ~/bluez $ tar xvf bluez-X.XX.tar.xz
pi@hoa: ~/bluez $ cd bluez-X.XX
pi@hoa: ~/bluez/bluez-X.XX $ sudo .configure — disable-systemd
pi@hoa: ~/bluez/bluez-X.XX $ sudo make
pi@hoa: ~/bluez/bluez-X.XX $ sudo make install

Then we need to reboot. X.XX was an arbitrarily chosen variable that represents the most current version of Bluez, displayed in the link below:
www.kernel.org/pub/linux/bluetooth

Now, your Raspberry is successfully configured and ready to transmit iBeacon signals.

1.3 Up and Running

Now, we dive into the directory that we created in the beginning. We need to do some last configurations :

pi@hoa: ~/bluez/bluez-X.XX/tools $ sudo hciconfig hci0 up
pi@hoa: ~/bluez/bluez-X.XX/tools $ sudo hciconfig hci0 leadv 3
pi@hoa: ~/bluez/bluez-X.XX/tools $ sudo hciconfig hci0 noscan

Now we assign a UUID which is arbitrarily chosen. You can get a random UUID on OS X by typing:

sudo uuidgen

or in Raspberry Pi device :

python -c ’import sys,uuid;sys.stdout.write(uuid.uuid4().hex)’|pbcopy && pbpaste && echo

For now, I shall pick :

0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 63 6F 3F 8F 64 91 4B EE 95 F7 D8 CC 64 A8 63 B5 00 00 00 00 C8 00

as my UUID. In order the system to work, write:

sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 63 6F 3F 8F 64 91 4B EE 95 F7 D8 CC 64 A8 63 B5 00 00 00 00 C8 00

Here we are done. Now your RaspberryPi is transmitting an iBeacon signal. You can detect it with any app designed for it. (There are several apps either in Google Play or in AppStore )

1.4 Understanding UUID

  1. For UUID section: 63 6F 3F 8F 64 91 4B EE 95 F7 D8 CC 64 A8 63 B5 part determines your visible proximity UUID. Whenever you determine a specific UUID for yourself, replace in with the bold part. This data should appear on your receiver.
  2. In 00 00 00 00 C8 00 part, the doubled zero-pairs from the left represent your Major and Minor values respectively. Those are specific variables assigned arbitrarily in order to maintain your devices’ uniqueness. And the last C8 00 part is related with RSSI power and Tx Power.
  3. For the LE (Low Energy) Controller Commands, the OGF (Op-code Group Field ) is defined as 0x08 so that OCF (Op-code Command Field) is 0x0008 (Source: Bluetooth Specification Version 4.0 [Vol.2], page 1114) so you put them on front as given.
  4. In 1E 02 01 1A 1A FF 4C 00 02 15 part, 4C 00 02 15 pairs represent the brand of your device and the FF pair before 4C 00 02 15 represents the manifacturer specific data AD type. Since we transmit Apple’s iBeacon-like waves, we better use their identifier in order to introduce our device to receivers. You can find more info and other brands’ identifiers on below: https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers
  5. In 1E 02 01 1A part, the 2 nd and the 3 rd bytes stand for flags (e.g LE and BR/EDR flag), wheras the 1st and 4th ones stand for data lengths represented in hexadecimal form

1.5 Sources

You can check each of the protocols and packages that we downloaded on the section 1 at :https://packages.debian.org
e.g: https://packages.debian.org/sid/libusb-dev

--

--