使用 DBUS-Python 的 Bluez BLE 连接监控

Bluez BLE Connections Monitoring using DBUS-Python

我能够通过遵循“example_advertisement" and "example-gatt-server" in Bluez Examples来宣传 BLE 并设置 GATT 服务和特性。我如何使用类似的 DBUS 绑定从 DBUS 知道 BLE 客户端何时连接以及何时断开连接对于 Python?我要查看哪个 DBUS API?

还有一个例子你可以看看:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-discovery

当 BlueZ/DBus 获悉新的远程设备时,将发送 InterfacesAdded 信号。 当远程设备从断开连接变为连接时。然后是设备上的 属性 更改并发送 PropertiesChanged 信号。 这就是为什么上面示例中的代码使用 add_signal_receiver 为两个信号添加回调。

    bus.add_signal_receiver(interfaces_added,
            dbus_interface = "org.freedesktop.DBus.ObjectManager",
            signal_name = "InterfacesAdded")

    bus.add_signal_receiver(properties_changed,
            dbus_interface = "org.freedesktop.DBus.Properties",
            signal_name = "PropertiesChanged",
            arg0 = "org.bluez.Device1",
            path_keyword = "path")

附带说明一下,Buez 示例中使用的 DBus 绑定并不是唯一可用的绑定: https://www.freedesktop.org/wiki/Software/DBusBindings/