即使可以通过hcitool lescan找到设备,BLE gatttool也无法连接 [英] BLE gatttool cannot connect even though device is discoverable with hcitool lescan

查看:440
本文介绍了即使可以通过hcitool lescan找到设备,BLE gatttool也无法连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm running RPi with a USB Bluetooth dongle. When I use hcitool, I can discover the SmartTag device. But when I use gatttool, I cannot connect. It says "Host is down (112)". Here are my commands:

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

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

Checking for bluetooth adapters on my RPi I get:

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

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

Then, when I use the gatttool like this, I get:

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

当我键入connect时,我得到了:

When I type connect, I get this:

[   ][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传感器.

I found some info on the web that said "Host is down" means that the bluetooth sensor is not in discoverable mode. But this is not correct as far as the SmartTag is concerned since I press the one button (side button) on the sensor that TI says to push to make it discoverable. And that same one is used by the hcitool lescan to find the device. There's also an android app that runs off a phone and it scans, connects, and reads the SmartTag sensor just fine when that same button is pressed.

有人知道这个问题可能是什么吗? 预先感谢

Does anyone know what the problem might be? Thanks in advance

推荐答案

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

I had the same problem, this method worked for me:

卸下USB模块并重新启动RPi:

Remove the USB module and restart the RPi:

sudo shutdown -r now

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

( you may want to edit /etc/apt/sources.list in order to successfully install the libs listed hereafter.

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

否则,您可能会发现以下错误

Otherwise, you could stumble upon the following error

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

别忘了更新,使更改生效.

Don't forget to update so the changes can take effect.

sudo apt-get update

)

删除Bluez安装并执行更新:

Remove the Bluez installation and perform an update:

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

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

You may edit the /etc/apt/sources.list to ensure you will be able to install the necessary libraries:

确保您具有必要的库:

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

下载并提取最新的Bluez版本(当时为5.21):

Download and extract the newest Bluez version (at the time it's 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行需要一些时间来处理):

Go to the Bluez folder, configure and install (The sudo make line takes some time to process):

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

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

Turn the RPi off, so you can plug the Bluetooth dongle, than turn it on again

sudo shutdown -h now

您可能必须打开USB加密狗的电源:

You might have to power up the USB dongle:

sudo hciconfig hci0 up

然后您可以再次尝试LESCAN:

Then you can try LESCAN again:

sudo hcitool lescan

并且假设它工作正常,您可能会与以下内容联系起来:

And supposing it worked properly you will be albe to connect with:

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]"行,请尝试按传感器标签上的侧面按钮以使其再次可见.

If it is taking long to show the connected "[CON]" line, try to press the side button on your sensor tag to make it visible again.

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

It was a mix of the information from these two links:

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

这篇关于即使可以通过hcitool lescan找到设备,BLE gatttool也无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆