2
votes

When I tried to use gatttool and bluetoothctl to connect to a bluetooth device, gatttool got "Connection refused" but bluetoothctl connected to it successfully.

What's the difference between bluetoothctl and gatttool?

How to make gatttool work because I need to use char-write-cmd command in gatttool?

$ ./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
You may get some info from this link: stackoverflow.com/questions/34271217/…aksonlyaks
I have the same problem on linux UBUNTU 17.04 no problems with bluetoothctl but gattool does not connectZibri

2 Answers

0
votes

Solution: just add -t random to gatttool command line and it will connect!

0
votes

Like @Zibri said the required command is:

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.

#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