Bluetooth 无法连接到Raspberry Pi上的BLE设备
我正试图连接到一个BLE设备(心率传感器,Polar H7),在树莓皮2上。我使用的是bluez(5.35)的最新版本,可以在这里找到: 但是,当我试图使用Bluetooth 无法连接到Raspberry Pi上的BLE设备,bluetooth,raspberry-pi,bluetooth-lowenergy,bluez,Bluetooth,Raspberry Pi,Bluetooth Lowenergy,Bluez,我正试图连接到一个BLE设备(心率传感器,Polar H7),在树莓皮2上。我使用的是bluez(5.35)的最新版本,可以在这里找到: 但是,当我试图使用gatttool进行连接时,总是出现“连接被拒绝”错误 以下是我的工作: pi@raspberrypi ~ $ sudo su root@raspberrypi:/home/pi# hciconfig dev hci0: Type: BR/EDR Bus: USB BD Address: 5C:F3:70:69:54:3
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]>
我试着关注这个话题:
但是它对我不起作用。我不得不禁用
/etc/bluetooth/main.conf
->中的插件pnat
。我读到它不稳定,但我对这个插件了解不多。你可以尝试使用gatttool-b00:22:D0:6D:E0:E6-I
然后连接,在发现MAC之后,没有连接之前使用hcitool-lecc 00:22:D0:6D:E0:E6
默认情况下,GATT是不启用的。将以下行添加到/etc/bluetooth/main.conf
EnableLE = true // Enable Low Energy support. Default is false.
AttributeServer = true // Enable the GATT attribute server. Default is false.
在使用-t random
参数将LE地址类型设置为random
后,我可以使用gatttool
通过Bluetooth
从Raspberry
连接到我的Android
设备,即:
sudo gatttool -t random -b DD:9D:0B:43:A1:77 -I
connect
从gatttool
如果你仍然想知道为什么随机的工作。我已经通过了代码,这就是我发现的
随机或静态地址是48位随机生成的地址,应满足以下要求
要求:
•静态地址的两个最高有效位应等于“1”
•静态地址随机部分的所有位不得等于“1”
•静态地址随机部分的所有位不应等于“0”
()通过apt get更新/安装BlueZ,修复了运行raspbian buster的raspberry pi 3B中的连接被拒绝(111)问题
>sudo-apt-get-install——无安装建议使用蓝牙
然后重新运行
我用以下工具运行它:
btmgmt le on
如果你有Bluez,为什么不直接使用bluetoothctl呢?我浏览并编辑了你的文章。搜索和阅读不在图像中的文本要容易得多。同样,在这个问题上,我们不会编辑解决方案。相反,我们将其作为答案发布,以便原始提问者(您)可以选中该答案回答您问题的框。作为对我答案的评论的链接比创建新答案更合适。
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
-t (Addr:Type: Set LE Address Type)
Public | random
Default: Public
btmgmt le on