【问题标题】:discover bluetooth devices without devices that already i did paired with those发现没有我已经与之配对的设备的蓝牙设备
【发布时间】:2021-07-03 09:58:44
【问题描述】:

我想发现没有已配对设备的蓝牙设备。但是我的 python 脚本显示了打开的蓝牙设备 + 我已经配对的设备。如何仅过滤开启的设备并忽略 PC 中已配对的设备而不删除它们。

这是我的脚本

import bluetooth
def search():
    devices = bluetooth.discover_devices(duration=1, lookup_names = True)
    return devices

if __name__=="__main__":
    while True:
        results = search()
        if (results!=None):
            for addr, name in results:
                print ("{0}".format(name))
                print ("{0}".format(addr))

【问题讨论】:

    标签: python bluetooth pybluez


    【解决方案1】:

    我不认为你可以通过pybluez API 做到这一点,它甚至还没有在积极的开发中。如果我们查看 API,您可以将 flush_cache 设置为 False,而不是查看以前发现的设备。但它再次显示配对的设备。

    def discover_devices (duration=8, flush_cache=True, lookup_names=False,
                          lookup_class=False, device_id=-1, iac=IAC_GIAC):
    

    但在下面,我看到了:

    try:
        results = _bt.hci_inquiry (sock, duration=duration, flush_cache=True,
                                   lookup_class=lookup_class, device_id=device_id,
                                   iac=iac)
    

    您可能想尝试将其设置为 False 并试一试。

    我不想通过 D-BUS API 发现配对的设备似乎也是不可能的。如果我们查看 adapter-api.txt 有一个 void SetDiscoveryFilter(dict filter) 方法,但它并不能满足您的要求。

    另一种解决方法是使用 DBUS API 来获取设备是否被发现的信息,然后如果它未配对则列出一些列表,然后您将获得一个很好的未配对设备列表。如果您的域是 Linux,您可能需要检查缓存在哪里 kept

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2012-12-25
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多