Creating AltBeacon with Raspberry Pi using BlueZ Example Code

A previous post showed the steps to make an iBeacon transmitter with Raspberry Pi using BlueZ example code (i.e. “example-advertisement). This post shows the steps for AltBeacon [1] in the same manner.

 

Here are the contents of this post.

Contents
– Prerequisites
– Steps
1. Enable experimental flag
2. Download BlueZ
3. Modify BLE Advertisement Example Code
4. Test
– Summary
– Reference

 

Prerequisites
Here are some prerequisites before start.

  • Raspberry Pi 3 or Raspberry Pi Zero W
    Or any other model with Bluetooth adapter (e.g. Plugable BLE Adapter, Panda Bluetooth 4.0 Adapter)
  • Raspbian Stretch (March 2018)
    I would suggest to use Desktop version of Stretch because I got “DBus.Error.AccessDenied” for some reason when I ran “example-advertisement” on Raspbian Lite. It seems it’s similar to this but couldn’t figure out the cause/workaround.
  • Internet access
    It’s required to download BlueZ example code. Here is a Wi-Fi Setup steps. If you already have the code, you can work offline.

 

Steps
1. Enable experimental flag
Skip to Step 2 if you are using BlueZ 5.48 or higher. (update BlueZ to 5.48)

If not, follow the steps below.

Bluetooth service needs to be executed with experimental flag since ‘LEAdvertisingManager1’ interface is an experimental feature until BlueZ 5.48 release.

1-1. Open the configuration file for Bluetooth service.

1-2. Find a line starting with “ExecStart” and add “–experimental” at the end of the line. After modification, the line should look like this:

1-3. Reload the configuration file and restart Bluetooth service.

1-4. Check the status of Bluetooth service. [Optional]

You should see the experimental flag. (Line 9 in the example below)

 

2. Download BlueZ
2-1. Download BlueZ source code.

2-2. Extract the archive file.

2-3. Run the sample code and make sure that it works. [Optional]

Output should be like this:

* Press Ctrl + C to stop the script.

 

3. Modify BLE Advertisement Example Code
3-1. Copy the example code.

3-2. Open the file and look for TestAdvertisement class.

3-3. Replace ‘__init__’ method:

with:

 

4. Test
4-1. Run the code. The console output should be same as Step 2-3.

4-2. Find your Raspberry Pi using a beacon scanner app. If everything goes well, the Raspberry Pi should be broadcasting AltBeacon message and it can be detected by app. Below are examples of apps.

‘nRF Connect’ for Android

 

‘Locate Beacon’ for iPhone

 

Summary
AltBeacon is an open source version of Apple’s iBeacon. It has the same functionality as iBeacon, and the two have similar data structure as below.

*2 : Bluetooth 4.0 Core Specification, Volume 3, Part C, Appendix C, 18.1 Flags
*4 Manufacture dependent value
*5 Application dependent value
*6 Device dependent value

 

References
[1] AltBeacon

 

 

Leave a Reply

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