无法连接到Raspberry Pi上的BLE设备

问题描述 投票:11回答:5

我正在尝试连接到Raspberry Pi 2上的BLE设备(心率传感器,Polar H7)。我使用的是上一版本的bluez(5.35):http://www.bluez.org/download/但是当我尝试使用gatttool进行连接时,我总是有“拒绝连接”的错误。

这是我做的:

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]> 

我试着按照这个主题:BLE gatttool cannot connect even though device is discoverable with hcitool lescan,但它对我不起作用。

bluetooth raspberry-pi bluetooth-lowenergy bluez
5个回答
0
投票

我不得不在pnat - > /etc/bluetooth/main.conf中禁用插件DisablePlugins=pnat。我读到它不稳定,但我对这个插件了解不多。


22
投票

通过使用Bluetooth参数将Raspberry设置为Android,我能够通过LE address typerandom连接到我的-t random设备,即:

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

来自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

2
投票

默认情况下,GATT未启用。将以下行添加到/etc/bluetooth/main.conf

EnableLE = true           // Enable Low Energy support. Default is false.
AttributeServer = true    // Enable the GATT attribute server. Default is false.

0
投票

如果你仍然想知道为什么随机工作。我已经完成了代码,这就是我找到的。

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

随机或静态地址是48位随机生成的地址,应满足以下要求:

•静态地址的两个最高有效位应等于'1'

•静态地址随机部分的所有位不得等于'1'

•静态地址随机部分的所有位不应等于'0'

(Qazxswpoi)


-1
投票

您可以尝试使用Source然后连接,在发现MAC之前没有连接之前使用gatttool -b 00:22:D0:6D:E0:E6 -I

© www.soinside.com 2019 - 2024. All rights reserved.