The recommended way was to use the default passkey-agent. But it seems not to work anymore.
Finaly I was able to pair may device using sample agent found in bluez sources test/simple-agent which is configurable. I have modified the source slightly to pair using constant PIN. When started the code bellow will respond with constant PIN to every pairing request. The constant PIN is 1243.
Usage: store the following code into a file. Change attributes of the file to be runnable (
chmod a+x filename
). Then run the script. Then you will be able to pair devices using the default PIN 1243. #!/usr/bin/python
import gobject
import sys
import dbus
import dbus.service
import dbus.mainloop.glib
class Rejected(dbus.DBusException):
_dbus_error_name = "org.bluez.Error.Rejected"
class Agent(dbus.service.Object):
exit_on_release = True
def set_exit_on_release(self, exit_on_release):
self.exit_on_release = exit_on_release
@dbus.service.method("org.bluez.Agent",
in_signature="", out_signature="")
def Release(self):
print "Release"
if self.exit_on_release:
mainloop.quit()
@dbus.service.method("org.bluez.Agent",
in_signature="os", out_signature="")
def Authorize(self, device, uuid):
print "Authorize"
return
@dbus.service.method("org.bluez.Agent",
in_signature="o", out_signature="s")
def RequestPinCode(self, device):
print "RequestPinCode"
return "1243"
@dbus.service.method("org.bluez.Agent",
in_signature="o", out_signature="u")
def RequestPasskey(self, device):
print "RequestPasskey"
return dbus.UInt32("1243")
@dbus.service.method("org.bluez.Agent",
in_signature="ou", out_signature="")
def DisplayPasskey(self, device, passkey):
print "DisplayPasskey"
return
@dbus.service.method("org.bluez.Agent",
in_signature="ou", out_signature="")
def RequestConfirmation(self, device, passkey):
print "RequestConfirmation"
return
@dbus.service.method("org.bluez.Agent",
in_signature="s", out_signature="")
def ConfirmModeChange(self, mode):
print "ConfirmModeChange (%s)" % (mode)
@dbus.service.method("org.bluez.Agent",
in_signature="", out_signature="")
def Cancel(self):
print "Cancel"
def create_device_reply(device):
print "New device (%s)" % (device)
mainloop.quit()
def create_device_error(error):
print "Creating device failed: %s" % (error)
mainloop.quit()
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
print "Step 1"
bus = dbus.SystemBus()
print "System bus acquired"
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
"org.bluez.Manager")
print "manager acquired"
path = manager.DefaultAdapter()
print "Manager path acquired"
adapter = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Adapter")
print "adapter acquired"
path = "/my/agent"
agent = Agent(bus, path)
print "Agent object created"
mainloop = gobject.MainLoop()
print "Main loop created"
adapter.RegisterAgent(path, "NoInputNoOutput")
print "Agent registered"
print "Starting loop"
mainloop.run()
#adapter.UnregisterAgent(path)
#print "Agent unregistered"