Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

raspberry pi - BLE gatttool cannot connect even though device is discoverable with hcitool lescan

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

Checking for bluetooth adapters on my RPi I get:

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

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]>

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]>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Remove the USB module and restart the RPi:

sudo shutdown -r now

( Edit: 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

)

Remove the Bluez installation and perform an update:

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

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

Make sure you have the necessary libs:

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

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

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

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

sudo shutdown -h now

You might have to power up the USB dongle:

sudo hciconfig hci0 up

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]>

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...