【问题标题】:Raspberry Pi 3 B+ BLE Scanning Fails After Upgrade (Using Stretch)Raspberry Pi 3 B+ BLE 升级后扫描失败(使用 Stretch)
【发布时间】:2019-01-12 23:11:03
【问题描述】:

在执行 apt-get 更新/升级后,使用已知工作 Python 示例的 BLE 扫描在全新的 Raspberry Pi 3 B+(金属罐 CPU)上失败。要重新创建,使用 NOOBS 2.8.2,设置 Pi 并执行 apt-get update 和 upgrade,接受所有建议的更改。然后使用this sample code 扫描BLE 设备。作为诊断的一部分,命令:

hcitool lescan

用于查看是否可以打开 hci0 设备。这导致了错误:

hcitool lescan Set scan parameters failed: Input/output error

此解决方法成功解决了该错误:

hciconfig hci0 down
hciconfig hci0 up
hcitool lescan

但只有在 'hcitool lescan' 开始成功运行之后。目前尚不清楚我们是否必须实际捕获白名单中的扫描设备才能成功(过快而无法捕获和停止)

示例代码在这些新系统版本上失败:

ii  bluez                           5.43-2+rpt2+deb9u2           armhf        Bluetooth tools and daemons
ii  bluez-firmware                  1.2-3+rpt6                   all          Firmware for Bluetooth devices
ii  bluez-hcidump                   5.43-2+rpt2+deb9u2           armhf        Analyses Bluetooth HCI packets
ii  libbluetooth-dev                5.43-2+rpt2+deb9u2           armhf        Development files for using the BlueZ Linux Bluetooth library
ii  libbluetooth3:armhf             5.43-2+rpt2+deb9u2           armhf        Library to use the BlueZ Linux Bluetooth stack
ii  pi-bluetooth                    0.1.8                        all          Raspberry Pi 3 bluetooth
ii  python-bluez                    0.22-1                       armhf        Python wrappers around BlueZ for rapid bluetooth development

但是在这个系统上工作,一次升级回来:

ii  bluez                           5.43-2+rpt2+deb9u2           armhf        Bluetooth tools and daemons
ii  bluez-firmware                  1.2-3+rpt5                   all          Firmware for Bluetooth devices
ii  libbluetooth-dev                5.43-2+rpt2+deb9u2           armhf        Development files for using the BlueZ Linux Bluetooth library
ii  libbluetooth3:armhf             5.43-2+rpt2+deb9u2           armhf        Library to use the BlueZ Linux Bluetooth stack
ii  pi-bluetooth                    0.1.7                        all          Raspberry Pi 3 bluetooth
ii  python-bluez                    0.22-1                       armhf        Python wrappers around BlueZ for rapid bluetooth development

编辑:btmon 命令的输出(新的非工作单元):

Bluetooth monitor ver 5.43
= Note: Linux version 4.14.52-v7+ (armv7l)                                                                                         0.695265
= Note: Bluetooth subsystem version 2.22                                                                                           0.695276
= New Index: B8:27:EB:A0:39:EC (Primary,UART,hci0)                                                                          [hci0] 0.695279
= Open Index: B8:27:EB:A0:39:EC                                                                                             [hci0] 0.695281
= Index Info: B8:27:EB:A0:39:EC (Broadcom Corporation)                                                                      [hci0] 0.695284
@ RAW Open: python (privileged) version 2.22                                                                       {0x0003} [hci0] 0.695289
@ RAW Open: hcitool (privileged) version 2.22                                                                      {0x0002} [hci0] 0.695291
@ MGMT Open: bluetoothd (privileged) version 1.14                                                                         {0x0001} 0.695294
@ MGMT Open: btmon (privileged) version 1.14                                                                              {0x0004} 0.695367
> HCI Event: LE Meta Event (0x3e) plen 40                                                                                   [hci0] 2.692582
      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Scannable undirected - ADV_SCAN_IND (0x02)
        Address type: Random (0x01)
        Address: 51:46:AD:CA:4C:2F (Resolvable)
        Data length: 28
        16-bit Service UUIDs (complete): 1 entry
          Google (0xfe9f)
        Service Data (UUID 0xfe9f): 0000000000000000000000000000000000000000
        RSSI: -84 dBm (0xac)

来自较旧的工作单位:

Bluetooth monitor ver 5.43
= Note: Linux version 4.14.34-v7+ (armv7l)                                                                                         0.396738
= Note: Bluetooth subsystem version 2.22                                                                                           0.396744
= New Index: B8:27:EB:31:E6:62 (Primary,UART,hci0)                                                                          [hci0] 0.396746
= Open Index: B8:27:EB:31:E6:62                                                                                             [hci0] 0.396748
= Index Info: B8:27:EB:31:E6:62 (Broadcom Corporation)                                                                      [hci0] 0.396749
@ RAW Open: python (privileged) version 2.22                                                                       {0x0002} [hci0] 0.396752
@ MGMT Open: bluetoothd (privileged) version 1.14                                                                         {0x0001} 0.396753
@ MGMT Open: btmon (privileged) version 1.14                                                                              {0x0003} 0.396800
> HCI Event: LE Meta Event (0x3e) plen 42                                                                                   [hci0] 0.534168
      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
        Address type: Public (0x00)
        Address: 0C:F3:EE:B3:B8:53 (EM Microelectronic)
        Data length: 30
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        Company: Apple, Inc. (76)
          Type: iBeacon (2)
          UUID: a6ffa91b-91f4-f2ad-0f4a-6dcf5444232f
          Version: 0.256
          TX power: -76 dB
        RSSI: -70 dBm (0xba)

【问题讨论】:

  • 您能否澄清一下“我们是否必须实际捕获白名单中的扫描设备才能使扫描成功(过快而无法捕获和停止)”是什么意思?跨度>
  • 请在尝试扫描时发布“sudo btmon”的输出。
  • @davidgyoung 抱歉混淆了这个问题。忘记“过得太快的部分”。现在需要加入白名单吗?
  • @emil 添加了包含第一个扫描数据包的 btmon 输出。

标签: python bluetooth-lowenergy raspberry-pi3 ibeacon


【解决方案1】:

所以您的扫描似乎已经处于活动状态(因为它传递了一个广告数据包)? lescan 命令首先设置扫描参数,然后开始扫描。如果已经有正在进行的扫描,HCI 将禁止设置扫描参数命令。

【讨论】:

  • 所以当你说正在进行扫描时,是不是来自非工作单元的这一行:@ RAW Open: hcitool (privileged) version 2.22
  • 我猜扫描是在 btmon 启动之前开始的,因为 btmon 没有捕获“LE Set Scan Enable”命令,但它肯定会运行,因为 HCI 传递广告事件。尝试关闭蓝牙(如果那是正在扫描的那个)。
  • 关闭蓝牙不会改变行为。继续尝试了解配置和启动时间。重新启动几次后,它可以工作。比赛条件?
  • 您可以尝试将“btmon > /tmp/btlog”添加到一些启动脚本中,以确保您捕获所有内容。然后您应该会看到扫描开始的时间。
  • 好主意,将尝试报告结果。
【解决方案2】:
  1. 创建一个新文件 (0755),例如 /home/pi/scripts 中的 lescan.sh,代码如下:
#!/bin/sh
sudo hciconfig hci0 down
sudo hciconfig hci0 up
sudo timeout -s INT 1s hcitool lescan
cd /
cd home/pi/proPi/
sudo timeout -s INT 1s python *detectAll.py* (replace with your Phyton script name)
cd /
  1. sudo crontab -e 并添加以下内容:@reboot sleep 60 && sh /home/pi/scripts/lescan.sh

【讨论】:

    【解决方案3】:

    目前我修复通过在使用 python 扫描器之前调用脚本(找到 here)来解决此问题。

    我用 1 秒的时间调用这个脚本:

    bash lescan.sh 1s /dev/null
    

    【讨论】:

    • 脚本无法访问。
    猜你喜欢
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 2016-11-11
    相关资源
    最近更新 更多