I'm running tests with my home computer running Ubuntu and Python 2.7 in the hopes of having Raspberry Pi 3 advertise using BLE with custom services and characteristics. I've installed Bluez Version 5.42 (using the recommended method) on both devices as well as dbus-python. My computer and Raspberry Pi both are able to advertise using the hci0 lescan 0
command, but I'd like to advertise with the bluez example scripts, example-gatt-client.py and example-advertisement.py found here, as I want to use my own custom characteristics.
Home Computer - Kernel version 4.4.0-31 generic
I'm able to create custom characteristics and advertise by running example-gatt-server.py and example-advertise.py with no issues on my home computer. The one snag I had was I needed to enable Bluez experimental mode by adding --experimental
to the bluetooth.service file located in /lib/systemd/system/bluetooth.service
. Also installing the dbus-python library was a bit of a pain, as I had to build and install it myself for Python2.
The advertise.py script looks for a specific advertising interface called "org.bluez.LEAdvertisingManager1". The gatt-server.py script looks for "org.bluez.GattManager1". I can check if that interface exists by running the following command:
dbus-send --system --dest=org.bluez --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects
These interfaces are found and work fine on my home computer. The scripts run without issue.
Raspberry Pi - Kernel version 4.4.38-v7+
With the same bluez version and the experimental features enabled, I run into this error when trying to run advertise.py:
LEAdvertisingManager1 interface not found.
And when I execute the command "systemctl status bluetooth" it shows the experimental flag is enabled, but I don't see LEAdvertistingManager1 when running.
dbus-send --system --dest=org.bluez --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects
I can however run the gatt-server.py script without issue which means "org.bluez.GattManager1" is found and working properly. What am I missing here?
I've searched this issue, but the only suggestions were to enable experimental features and ensure my kernel is >= 4.1.
I've solved my issue! After a lot of debugging and looking through the bluez error logs, I realized that I did not install bluez correctly on my Pi. Here are the steps for properly installing bluez from a fresh install of raspbian.
Then, enable experimental mode. This may not be required with Bluez v5.23 but I did it anyway.
Add --experimental after the line "ExecStart=/usr/local/libexec/bluetooth/bluetoothd" So it should look like
Then to get bluetooth running with this new configuration
If you want to run a test advertisement you can just use the following:
Your Pi3 should advertise as "raspberrypi" and if you try to connect to it using your favorite BLE app (I use LiteBlue on iOS) it should have a few default characteristics.
In order to check if 'LEAdvertisingManager1' exists, we need to run
Finally, don't try to run the scripts from the link in my original post. They're so incredibly out of date. Instead, run the example scripts located in the directory you made.
Before running, you'll want to install dbus-python via the following:
If you want to run the example-advertise script using python2.7 (which I did), you'll have to change the line in example-advertise from
to
If you want to add your own custom characteristics, you'll need to concurrently run example-gatt-server which should run without modifications.
I also had a small issue where my iPhone was stuck interrogating the Pi3 and would not connect. This was solved by simply resetting the bluetooth.
Best of luck!