I'm trying to connect my Raspberry Pi 3B+ over BLE GATT Server using the Bluez5.6 library. I have successfully tested the BLE server application. Able to connect & communicate over the GATT services on the BLE client application over android.
I would like to apply the authentication pin while the connecting client application(Android App) to the BLE GATT server. I have tried to apply the different capabilities to the BLE agent.
like... DisplayOnly DisplayYesNo KeyboardOnly NoInputNoOutput KeyboardDisplay
Here is the source code for the main function.
def main():
# global mainloop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
adapter = find_adapter(bus)
if not adapter:
logger.error('main : BLE adapter not found')
return
#discovery functionality
bus.add_signal_receiver(dis_interfaces_added, dbus_interface = "org.freedesktop.DBus.ObjectManager", signal_name = "InterfacesAdded")
bus.add_signal_receiver(dis_properties_changed, dbus_interface = "org.freedesktop.DBus.Properties", signal_name = "PropertiesChanged", arg0 = "org.bluez.Device1", path_keyword = "path")
om = dbus.Interface(bus.get_object("org.bluez", "/"), "org.freedesktop.DBus.ObjectManager")
objects = om.GetManagedObjects()
for path, interfaces in objects.items():
if "org.bluez.Device1" in interfaces:
devices[path] = interfaces["org.bluez.Device1"]
capability = "NoInputNoOutput"
logger.info('main : capability : (%s)' % capability)
agent_path = "/test/agent"
agent = Agent(bus, agent_path)
service_manager = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter), GATT_MANAGER_IFACE)
ad_manager = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter), LE_ADVERTISING_MANAGER_IFACE)
app = ConfigBluetoothServiceApplication(bus)
adv = ConfigBluetoothServiceAdvertisement(bus, 0)
mainloop = GLib.MainLoop()
agent_manager = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, "/org/bluez"), GATT_AGENT_IFACE)
agent_manager.RegisterAgent(agent_path, capability)
logger.info('main : main : Agent registered')
agent_manager.RequestDefaultAgent(agent_path)
service_manager.RegisterApplication(app.get_path(), {}, reply_handler=register_app_cb, error_handler=register_app_error_cb)
ad_manager.RegisterAdvertisement(adv.get_path(), {}, reply_handler=register_ad_cb, error_handler=register_ad_error_cb)
try:
mainloop.run()
except KeyboardInterrupt:
adv.Release()
mainloop.quit()
if __name__ == '__main__':
main()
Will you please help me to know, What are the required configurations that have to be done to add the authentication for the BLE GATT Server?