简体   繁体   English

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

[英]different connection result in gatttool and bluetoothctl with raspberry pi 3 bluetooth

When I tried to use gatttool and bluetoothctl to connect to a bluetooth device, gatttool got "Connection refused" but bluetoothctl connected to it successfully. 当我尝试使用gatttool和bluetoothctl连接到蓝牙设备时,gatttool得到了“连接被拒绝”,但是bluetoothctl成功连接到它。

What's the difference between bluetoothctl and gatttool? bluetoothctl和gatttool有什么区别?

How to make gatttool work because I need to use char-write-cmd command in 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

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

Like @Zibri said the required command is: 就像@Zibri所说的那样必需的命令是:

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

Also, it is a good idea to update Bluez, here is a good way to do it from "Installing BlueZ from sources" section of https://github.com/getsenic/gatt-python . 此外,更新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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM