Search code examples
linuxpython-2.7raspberry-pidbusbluez

LEAdvertisingManager1 missing from DBus.ObjectManager.GetManagedObjects


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.


Solution

  • 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.

    sudo apt-get update 
    sudo apt-get upgrade 
    mkdir bluez 
    cd bluez 
    wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.43.tar.xz 
    tar xvf bluez-5.43.tar.xz 
    cd bluez-5.43/ 
    sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev 
    ./configure 
    sudo make 
    sudo make install
    

    Then, enable experimental mode. This may not be required with Bluez v5.23 but I did it anyway.

    cd
    sudo nano /lib/systemd/system/bluetooth.service
    

    Add --experimental after the line "ExecStart=/usr/local/libexec/bluetooth/bluetoothd" So it should look like

    ExecStart=/usr/local/libexec/bluetooth/bluetoothd --experimental
    

    Then to get bluetooth running with this new configuration

    sudo systemctl daemon-reload 
    sudo systemctl restart bluetooth
    

    If you want to run a test advertisement you can just use the following:

    sudo hciconfig hci0 up
    sudo hciconfig hcio leadv 0
    

    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

    dbus-send --system --dest=org.bluez --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects
    

    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.

    cd bluez/bluez-5.43/tests
    

    Before running, you'll want to install dbus-python via the following:

    sudo apt-get install python-dev libdbus-1-dev libdbus-glib-1-dev 
    sudo apt-get install python-pip 
    sudo apt-get install --reinstall python-gi
    sudo python2.7 -m pip install dbus-python
    

    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

    import gobject
    

    to

    from gi.repository import GObject as gobject
    

    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.

    sudo systemctl daemon-reload 
    sudo systemctl restart bluetooth
    

    Best of luck!