I wanted to try some simple Bluetooth programming on Linux, but since the modern way to do this in Linux is through D-Bus, I had to learn about that as well. D-Bus is a high-level way of communicating between processes. The D-Bus protocol is not fixed to a certain programming language, and there exists implementations or bindings for several languages. I did my experiments using Python and its dbus-python module. Even though it is said that the module is obsolete, it still works, and its GitHub repository is still being updated.
D-feet is a nice GUI program can that be used to browse the D-Bus service hierarchy and call methods of objects. In D-Bus a program can offer services, and a service can export objects (that can themselves form a hierarcy), and the objects can implement interfaces, which can have callable methods and emittable signals. All these can be easily explored with D-feet. What is hard with D-feet, however, is answering questions like: which services offer objects with a certain interface. For example, which objects implement the ObjectManager interface. Finding out this using D-feet would mean clicking through all services and objects, and check which interfaces they implement. So, it is not really doable in D-feet.
I have made a Python script than can answer queries like these. Here’s how to make this query with my script:
./query.py --interface org.freedesktop.DBus.ObjectManager
The output shows all services with a well-known name (that is, names that don’t start with a colon) and the respective objects on the system bus that implement this interface.
org.freedesktop.ModemManager1 /org/freedesktop/ModemManager1 org.freedesktop.DBus.ObjectManager org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager org.bluez / org.freedesktop.DBus.ObjectManager org.freedesktop.UDisks2 /org/freedesktop/UDisks2 org.freedesktop.DBus.ObjectManager
In the above output the toplevel strings are the services, on the next level are the objects, and the interfaces are at the lowest level. There a several options for the query.py program, see the README file in my repository. The next example queries all objects belonging to the service org.bluez that implement the Bluetooth low energy generic attribute profile characteristic interface:
./query.py --service org.bluez --interface org.bluez.GattCharacteristic1
In that repository there are two other trivial DBus scripts that serve as examples of dbus-python programming.
So far, dbus-python library has worked for me well, but a more modern and maintained Python module could be dasbus. I haven’t tried it yet myself.