【问题标题】:Cannot connect to BLE device on Raspberry Pi无法连接到 Raspberry Pi 上的 BLE 设备
【发布时间】:2016-01-02 01:30:24
【问题描述】:

我正在尝试连接到 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 但它对我不起作用。

【问题讨论】:

  • 如果你有 Bluez,为什么不直接使用 bluetoothctl?
  • 我浏览并编辑了您的帖子。搜索和阅读不在图像中的文本要容易得多。此外,在 SO 上,我们不会将解决方案编辑到问题中。相反,我们将其作为答案发布,以便最初的提问者(您)可以选中该框以回答您的问题。

标签: bluetooth raspberry-pi bluetooth-lowenergy bluez


【解决方案1】:

我让它运行了:

btmgmt le on

【讨论】:

    【解决方案2】:

    在使用LE address type 设置random-t random 参数后,我能够使用gatttool 通过BluetoothRaspberry 连接到我的Android 设备,即:

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

    来自gatttoolman

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

    【讨论】:

      【解决方案3】:

      通过 apt-get 更新/安装 BlueZ 修复了运行 raspbian buster 的树莓派 3B 中的连接被拒绝 (111) 问题

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

      然后重新运行

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:

          如果您仍然想知道为什么随机有效。我已经浏览了代码,这就是我发现的。

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

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

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

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

          • 静态地址随机部分的所有位不得等于“0”

          (Source)

          【讨论】:

          • 将链接作为对我的答案的评论比创建新答案更合适。
          【解决方案6】:

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

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

          【讨论】:

            【解决方案7】:

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

            【讨论】:

              猜你喜欢
              • 2017-06-02
              • 2016-04-30
              • 2020-07-09
              • 2021-05-11
              • 1970-01-01
              • 1970-01-01
              • 2014-02-10
              • 1970-01-01
              • 2023-03-13
              相关资源
              最近更新 更多