【问题标题】:Bluez BLE Connections Monitoring using DBUS-PythonBluez BLE 连接监控使用 DBUS-Python
【发布时间】:2020-11-07 08:19:22
【问题描述】:

我能够通过Bluez Examples 中的“example_advertisement”和“example-gatt-server”来宣传 BLE 并设置 GATT 服务和特性。我如何从 DBUS 知道何时连接了 BLE 客户端以及何时断开连接,使用 Python 的类似 DBUS 绑定?我该研究哪个 DBUS API?

【问题讨论】:

    标签: bluetooth-lowenergy bluez


    【解决方案1】:

    还有一个例子你可以看看: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/

    【讨论】:

    • 谢谢你,@ukBaz。 org.bluez.Device1 是我要找的那个。
    • 要监控断开连接,要监控信号“InterfacesRemoved”。
    • InterfacesRemoved 是设备从已知列表中删除的时间。当设备断开连接时,它将是一个PropertiesChanged 信号,Connected 属性在org.bluez.Device1 接口上发生变化
    猜你喜欢
    • 2015-03-08
    • 2021-10-09
    • 2016-08-25
    • 2023-03-22
    • 2021-06-02
    • 1970-01-01
    • 2016-02-02
    • 2016-02-02
    • 2013-04-19
    相关资源
    最近更新 更多