【问题标题】:BLE gatttool cannot connect even though device is discoverable with hcitool lescan即使可以使用 hcitool lescan 发现设备,BLE gatttool 也无法连接
【发布时间】:2014-09-11 06:42:33
【问题描述】:

我正在使用 USB 蓝牙加密狗运行 RPi。当我使用 hcitool 时,我可以发现 SmartTag 设备。但是当我使用 gatttool 时,我无法连接。它显示“主机已关闭 (112)”。这是我的命令:

$ sudo hcitool lescan
LE Scan ...
BC:6A:29:AB:DE:2B (unknown)
BC:6A:29:AB:DE:2B SensorTag

检查我的 RPi 上的蓝牙适配器我得到:

$ hcitool dev
Devices:
        hci0    5C:F3:70:60:E6:1B

然后,当我像这样使用 gatttool 时,我得到:

$ sudo gatttool -i hci0 -b BC:6A:29:AB:DE:2B -I
[   ][BC:6A:29:AB:DE:2B][LE]>

当我输入 connect 时,我得到了这个:

[   ][BC:6A:29:AB:DE:2B][LE]> connect
Connecting... connect error: Host is down (112)
[   ][BC:6A:29:AB:DE:2B][LE]>

我在网上找到一些信息说“主机已关闭”意味着蓝牙传感器未处于可发现模式。但就 SmartTag 而言,这是不正确的,因为我按下了传感器上的一个按钮(侧面按钮),TI 表示要推动它以使其可被发现。 hcitool lescan 使用相同的设备来查找设备。还有一个在手机上运行的 android 应用程序,当按下相同的按钮时,它会扫描、连接和读取 SmartTag 传感器。

有谁知道可能是什么问题? 提前致谢

【问题讨论】:

    标签: raspberry-pi bluetooth-lowenergy sensors hci gatt


    【解决方案1】:

    我遇到了同样的问题,这个方法对我有用:

    移除USB模块并重启RPi:

    sudo shutdown -r now
    

    ( 编辑: 您可能需要编辑 /etc/apt/sources.list 以成功安装下面列出的库。

    nano /etc/apt/sources.list
    
    deb http://archive.raspbian.org/raspbian wheezy main contrib non-free
    deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free
    

    否则,您可能会遇到以下错误

    checking for GLIB... no
    configure: error: GLib >= 2.28 is required
    

    不要忘记更新,以便更改生效。

    sudo apt-get update
    

    )

    删除 Bluez 安装并执行更新:

    sudo apt-get --purge remove bluez
    sudo apt-get update
    

    您可以编辑/etc/apt/sources.list 以确保您能够安装必要的库:

    确保你有必要的库:

    sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev
    

    下载并解压最新的 Bluez 版本(当时是 5.21):

    sudo wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.21.tar.xz
    sudo tar xvf bluez-5.21.tar.xz
    

    进入 Bluez 文件夹,配置并安装(sudo make 行需要一些时间来处理):

    cd bluez-5.21
    sudo ./configure --disable-systemd
    sudo make
    sudo make install
    

    关闭 RPi,这样您就可以插入蓝牙加密狗,然后再次打开它

    sudo shutdown -h now
    

    您可能需要启动 USB 加密狗:

    sudo hciconfig hci0 up
    

    那你可以再试试LESCAN:

    sudo hcitool lescan
    

    假设它工作正常,您将可以连接:

    sudo hcitool lecc BC:6A:29:AB:DE:2B
    sudo gatttool -b BC:6A:29:AB:DE:2B --interactive
    
    [   ][BC:6A:29:AB:DE:2B][LE]> connect
    [CON][BC:6A:29:AB:DE:2B][LE]>
    

    如果显示连接的“[CON]”行需要很长时间,请尝试按下传感器标签上的侧边按钮使其再次可见。


    这是来自这两个链接的信息的混合:

    http://mike.saunby.net/2013/04/raspberry-pi-and-ti-cc2541-sensortag.html https://learn.adafruit.com/pibeacon-ibeacon-with-a-raspberry-pi/setting-up-the-pi

    【讨论】:

    • 感谢您的出色回答。在我的 RPi 上进行安装并重新启动后,它缺少 gatttool,所以我不得不做 sudo cp attrib/gatttool /usr/bin/ 现在它连接了!
    • 赞成,谢谢。在发表此评论时,bluez-5.30 已经存在。只有 'apt-get ...' 和 'make install' 需要 sudo。 'gatttool ...'、'wget ...'、'tar ...'、'configure ...'和'make'不需要root。
    猜你喜欢
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2014-05-03
    • 2016-06-24
    • 1970-01-01
    • 2018-04-26
    相关资源
    最近更新 更多