蓝牙模块discover_devices无法正常工作

时间:2019-07-23 22:59:37

标签: python bluetooth raspberry-pi

我正在尝试为树莓提供一种方法来扫描我家附近的设备,以查看我家周围的流量。我遇到的问题是,我在github上为pybluez找到的脚本可以工作,但是找不到设备。

因此,我立即跳到命令行并进行了蓝牙扫描。命令行中的扫描有效,但脚本不断告诉我未发现任何设备。我还尝试下载多个支持pybluez的蓝牙库,但仍然无法正常工作。

这是我从中获得的脚本。


```print "performing inquiry..."

```nearby_devices = discover_devices(lookup_names = True)

```print "found %d devices" % len(nearby_devices)

```for name, addr in nearby_devices:
         print " %s - %s" % (addr, name)



This is what I get when I run this script.

```found 0 devices

2 个答案:

答案 0 :(得分:0)

我是新用户...此脚本对我有用:

# file: inquiry.py
# auth: Albert Huang <albert@csail.mit.edu>
# desc: performs a simple device inquiry followed by a remote name request of
#       each discovered device
# $Id: inquiry.py 401 2006-05-05 19:07:48Z albert $
#

import bluetooth

print("performing inquiry...")

nearby_devices = bluetooth.discover_devices(
    duration=8, lookup_names=True, flush_cache=True, lookup_class=False)

print("found %d device(s)" % len(nearby_devices))

for addr, name in nearby_devices:
    try:
        print("  %s - %s" % (addr, name))
    except UnicodeEncodeError:
        print("  %s - %s" % (addr, name.encode('utf-8', 'replace')))

该脚本找到了我的蓝牙鼠标... MAC地址被部分隐藏了:

performing inquiry...
found 1 device(s)
98:xx:xx:xx:xx:xx - HP Bluetooth Mouse X4000b
[Finished in 10.575s]

答案 1 :(得分:0)

也许您已经解决了问题。在我的情况下,这是硬件(raspberry pi 3b)的方向。我认为蓝牙检测范围会因方向而异。