gatttool和bluetoothctl与raspberry pi 3蓝牙的不同连接结果

时间:2016-11-10 02:19:16

标签: bluetooth raspberry-pi bluetooth-lowenergy

当我尝试使用gatttool和bluetoothctl连接到蓝牙设备时,gatttool获得了“Connection refused”,但bluetoothctl已成功连接到它。

bluetoothctl和gatttool有什么区别?

如何使gatttool工作,因为我需要在gatttool中使用char-write-cmd命令?

$ ./gatttool -b 00:13:04:0C:6C:26 -I
[00:13:04:0C:6C:26][LE]> connect
Attempting to connect to 00:13:04:0C:6C:26
Error: connect error: Connection refused (111)
[00:13:04:0C:6C:26][LE]> exit


$ bluetoothctl
[NEW] Controller B8:27:EB:07:26:C8 raspberrypi [default]
[NEW] Device 00:13:04:0C:6C:26 MEDXING-NIBP
[bluetooth]# connect 00:13:04:0C:6C:26
Attempting to connect to 00:13:04:0C:6C:26
[CHG] Device 00:13:04:0C:6C:26 Connected: yes
Connection successful
[bluetooth]# info 00:13:04:0C:6C:26
Device 00:13:04:0C:6C:26
    Name: MEDXING-NIBP
    Alias: MEDXING-NIBP
    Paired: no
    Trusted: no
    Blocked: no
    Connected: yes
    LegacyPairing: no
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Unknown                   (0000ffb0-0000-1000-8000-00805f9b34fb)
[bluetooth]# exit

2 个答案:

答案 0 :(得分:0)

解决方案:只需将-t random添加到gatttool命令行,它就会连接!

答案 1 :(得分:0)

就像@Zibri所说,所需的命令是:

sudo gatttool -b 00:13:04:0C:6C:26 -t random -I

此外,更新Bluez是个好主意,这是https://github.com/getsenic/gatt-python的“从源代码安装BlueZ”部分中的一种好方法。

#First, consulte the Bluez version with 
bluetoothd --version
#If is not the last one indicated on http://www.bluez.org/, continue with the next steps, reeplace <5.50> with the most updated number version. 
sudo systemctl stop bluetooth
sudo apt-get update
sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev libdbus-glib-1-dev unzip
cd
mkdir bluez
cd bluez
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.50.tar.xz
tar xf bluez-5.50.tar.xz
cd bluez-5.50
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-library
make
sudo make install
sudo ln -svf /usr/libexec/bluetooth/bluetoothd /usr/sbin/
sudo install -v -dm755 /etc/bluetooth
sudo install -v -m644 src/main.conf /etc/bluetooth/main.conf
sudo systemctl daemon-reload
sudo systemctl start bluetooth
#Check the new version
bluetoothd --version