Running BLE Advertising Example Code on Raspbian Stretch

Update (Feb 26, 2018):
If your BlueZ version is 5.48 or higher, you can skip Step 1 since the Advertising Manager is marked as stable In BlueZ 5.48. (To update BlueZ, please see this post. )


The purpose of this post is to run an example code of Bluetooth Low Energy Advertisement from BlueZ source code (i.e. “example-advertisement“) on Raspberry Pi running Raspbian Stretch.

Here are the contents of this post.

– Assumptions
– Steps
1. Enable Experimental Flag for BlueZ
2. Download Example Code
3. Execute Example Code
4. Verify
– Troubleshoot
– Summary

Here are some assumptions before start. Please refer this in case it’s not ready.


1. Enable Experimental Flag for BlueZ
The example code uses LEAdvertisingManager1 interface which is still experimental in BlueZ 5.43 (pre-installed version in Raspbian Stretch (2017-09-07)). So, the experimental flag for BlueZ needs to be enabled.

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 (Line 9 in the example below). Then save and close the file.

1-3. Reboot the system to enable the change.


2. Download Example Code
2-1. Download BlueZ 5.43.

2-2. Extract the file.

The advertising example code “example-advertisement” is in “test” directory.


3. Install Requisite

3-1. Update package list

3-2. Install dbus and gobject


4. Execute Example Code
4-1. Execute BLE advertising example code.

4-2. Check the output. If everything is fine, it should be like this:

In case you get the error below, see Troubleshoot section.


5. Verify
You can use smartphone apps to verify if it’s really advertising. The image below is a screen capture of “LightBlue” app running on iPhone.

“stretch0907” is my Raspberry Pi’s host name. Advertisement data can be configured by modifying the example code.



The error above occurs most likely because the experimental flag for bluez is not enabled. You can check it using “ps” command by typing:

If it’s enabled, you can see the flag (i.e. “–experimental”) after the process path like this.

In case the flag is not there (like below), please go back to step 1 and enable the flag.


Now, Raspberry Pi is acting as BLE advertiser by running the BlueZ example code. Also, it can be easily a BLE beacon such as Apple’s iBeacon by modifying the code. Please refer this post to create iBeacon with BlueZ.



Sponsor Link

Leave a Reply

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