I have been using copy, paste, and magic to register a Bluetooth agent via Python DBUs which works great for hci0, but I cannot for the life of me see how I can get this agent to work for other Bluetooth controllers, i.e hci1. I have tried selecting the controller and setting it as default in bluetoothctl and other side channels.
Can someone please show me where the agent is associated with the controller. This is all too magical. I am also unable to find the agent or anything on it with D-Feet - How should or could I find it please?
A dumb toy example is as:
import dbus
import dbus.service
AGENT_PATH = "/org/bluez/anAgent"
class Agent(dbus.service.Object):
@dbus.service.method(AGENT_INTERFACE,
in_signature="os", out_signature="")
def AuthorizeService(self, device, uuid):
print("Some stuff and things")
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
capability = "DisplayYesNo"
agent = Agent(bus, AGENT_PATH)
obj = bus.get_object("org.bluez", "/org/bluez")
# Create the agent manager
manager = dbus.Interface(obj, "org.bluez.AgentManager1")
manager.RegisterAgent(AGENT_PATH, capability)
manager.RequestDefaultAgent(AGENT_PATH)
When Bluetooth needs an agent it looks at the
org.bluez.AgentManager1interface at the/org/bluezD-Bus object path for the location of the agent that has been registered. It then calls the relevant method on theorg.bluez.Agent1interface at that registered object path (/org/bluez/anAgentin your example). The methods that need to be implemented for theorg.bluez.Agent1interface are documented at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/agent-api.txtThere is only one agent irrespective of how many adapters there are on your system.
Could the issue be that the device being paired is associated with the "wrong" adapter?
The Device API has an
Adapterproperty which tracks the object path of the adapter the device belongs to.To find the agent that you have created it can be useful to use
busctl. Usingbusctl listwill list all the availableSystemBusservices. As you are not claiming a bus name for the agent it will be anonymous so in the format of:x.xxx. This can be a long list sobusctl list | grep pythonis what I usually do to narrow the list down.To introspect what was there you would do something like:
To test the agent service that has been published:
This service will need to be asynchronous so you will need to start the
MainLoopevent loop.Below is a full example of creating an Agent using
pydbusD-Bus bindings.The only place that the adapter is mentioned is the instruction to start discovery. If you had another device trying to discover your device with the agent, then it will depend on which adapter is discoverable and/or the other device tries to connect to.