20

I'm trying to connect to a BLE device (Heart rate sensor, Polar H7), on a Raspberry Pi 2. I use the last version of bluez (5.35) found here: http://www.bluez.org/download/ But when I'm trying to connect using gatttool, I always have "connection refused" error.

Here is what I do :

pi@raspberrypi ~ $ sudo su
root@raspberrypi:/home/pi# hciconfig dev
hci0: Type: BR/EDR Bus: USB
 BD Address: 5C:F3:70:69:54:3D ACL MTU: 1021:8 SCO MTU: 64:1
 DOWN
 RX bytes:616 acl:0 sco:0 events:34 errors:0
 TX bytes:380 acl:0 sco:0 commands:34 errors:0
root@raspberrypi:/home/pi# hciconfig dev up
root@raspberrypi:/home/pi# hcitool lescan
LE Scan ...
00:22:D0:6D:E0:E6 (unknown)
00:22:D0:6D:E0:E6 Polar H7 6DE0E61C
^Croot@raspberrypi:/home/pi# hcitool lecc 00:22:D0:6D:E0:E6
Connection handle 64
root@raspberrypi:/home/pi# gatttool -b 00:22:D0:6D:E0:E6 -I
[00:22:D0:6D:E0:E6][LE]> connect
Attempting to connect to 00:22:D0:6D:E0:E6
Error connect: Connection refused (111)
[00:22:D0:6D:E0:E6][LE]> 

I tried to follow this topic: BLE gatttool cannot connect even though device is discoverable with hcitool lescan but it did not work for me.

asked Oct 5, 2015 at 11:43
1
  • If you have Bluez, why not just use bluetoothctl? Commented Oct 27, 2015 at 15:17

7 Answers 7

42

I was able to connect via Bluetooth from Raspberry to my Android device using gatttool after setting the LE address type to random with the -t random argument, i.e. :

sudo gatttool -t random -b DD:9D:0B:43:A1:77 -I
connect

From gatttool man

--t, ---addr-type=[public | random] 
# Set LE address type. Default: public

USAGE gatttool [OPTION...]
 Help Options:
 -h, --help Show help options
 -h, --help Show help options
 --help-all Show all help options
 --help-gatt Show all GATT commands
 --help-params Show all Primary Services/Characteristics
 arguments
 --help-char-read-write Show all Characteristics Value/Descriptor
 Read/Write arguments
 Application Options:
 --i, ---adapter=hciX Specify local adapter interface
 --b, ---device=MAC Specify remote Bluetooth address
 --t, ---addr-type=[public | random] Set LE address type. Default: public
 --m, ---mtu=MTU Specify the MTU size
 --p, ---psm=PSM Specify the PSM for GATT/ATT over BR/EDR
 --l, ---sec-level=[low | medium | high] Set security level. Default: low
 --I, ---interactive Use interactive mode
answered May 27, 2017 at 6:55
Sign up to request clarification or add additional context in comments.

1 Comment

What if someone did all of the things in this post? Turning on BLE, using -t random and the connection is still refused? Asking for a friend.
6

By default GATT is not enable. Add the below lines to /etc/bluetooth/main.conf

EnableLE = true // Enable Low Energy support. Default is false.
AttributeServer = true // Enable the GATT attribute server. Default is false.
Robert
5,31843 gold badges70 silver badges115 bronze badges
answered Nov 25, 2016 at 14:19

Comments

2

I got it running with:

btmgmt le on
Jeremy Caney
7,798115 gold badges58 silver badges87 bronze badges
answered May 28, 2021 at 20:42

Comments

1

I had to disable the plugin pnat in /etc/bluetooth/main.conf -> DisablePlugins=pnat. I read that it's unstable, but I don't know much about this plugin.

1 Comment

Good grief, this is the most underrated answer ever! This solved every problem I had on a Raspbian system, after days of other attempts.
1

Fixed the connection refused (111) issue in my raspberry pi 3B running raspbian buster by Updating/installing BlueZ via apt-get

> sudo apt-get install --no-install-recommends bluetooth

and re running

> sudo gatttool -t random -b E9:1C:89:B7:16:F9 -I

answered Sep 25, 2019 at 22:46

Comments

1

If you are still wondering why the random from @Pedro Lobito's answer worked. I have gone through the code and this what I found.

​-t ​(Addr:Type: Set LE Address Type) 
Public | random 
Default: Public

A random or static address is a 48-bit randomly generated address and shall meet the following requirements:

• The two most significant bits of the static address shall be equal to ‘1’

• All bits of the random part of the static address shall not be equal to ‘1’

• All bits of the random part of the static address shall not be equal to ‘0’

(Source)

icc97
13.1k9 gold badges84 silver badges99 bronze badges
answered Mar 18, 2018 at 23:57

2 Comments

A link as comment on my answer would be more appropriate than creating a new answer.
This also still doesn't explain why random works
-1

You could try to use gatttool -b 00:22:D0:6D:E0:E6 -I and then connect, just after discovering the MAC without connecting before with hcitool lecc 00:22:D0:6D:E0:E6

ascripter
6,31512 gold badges54 silver badges74 bronze badges
answered Oct 11, 2016 at 17:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.