Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to BLE device on Raspberry Pi

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.

like image 903
palador Avatar asked Oct 05 '15 11:10

palador


People also ask

Can ble connect without advertising?

You can't create a connection between two devices without using advertisements. There is an interval after each advertisement in which the device listens for connection requests.

Does Raspberry Pi 4 have Bluetooth?

Raspberry Pi 4 comes with Gigabit Ethernet, along with onboard wireless networking and Bluetooth.

Does Raspberry Pi have Bluetooth?

For the best support for Bluetooth on the Raspberry Pi, we recommend using a Raspberry Pi 3 or newer, or the Pi Zero W. The in-built Bluetooth functionality of these Raspberry Pi's tends to be more reliable than the USB Bluetooth dongles.


1 Answers

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
like image 158
Pedro Lobito Avatar answered Oct 16 '22 19:10

Pedro Lobito