Linux BlueZ 5.65 hcitool 结合服务 UUID 和制造数据广告

问题描述 投票:0回答:1

我在定制的嵌入式 Linux 5.15 板上运行 BlueZ 5.56。该板载有 Atmel wilc3000 wifi/蓝牙无线电。我已经实现了一个基于 BlueZ 示例的 python GATT 服务器,它在树莓派上运行良好。但是,该示例的广告部分不适用于 wilc3000。因此,我手动使用 hcitool 来启动广告。这些广告有效——但我不知道如何将制造数据与服务 UUID 结合起来。

我在我的 Macbook 上使用 LightBlue 来测试和调试。如果我设置以下两个命令,广告似乎相互竞争,有时我会得到一个或另一个,有时我会收到空广告,什么也没有收到。

如何将两者结合起来,以便同时接收制造和服务 uuid 广告?

# Custom Manufacturing Advertisement
hcitool -i hci0 cmd 0x08 0x0008 11 02 01 06 07 09 61 62 63 64 65 66 05 ff fe 01 00 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00

# Custom Service UUID Advertisement
hcitool -i hci0 cmd 0x08 0x0008 12 11 07 30 44 5a 3e 35 50 0f ab 01 48 fd 25 11 63 a7 f5 00 00 00 00 00 00 00 00 00 00 00 00 00
linux bluetooth bluetooth-lowenergy bluez gatt
1个回答
3
投票

我认为主要问题是你设置了两次广告报告,最有可能发生的是第二个广告报告覆盖了第一个。您只需按如下方式调用 hcitool cmd 一次:-

hcitool -i hci0 cmd 0x08 0x0008 12 02 01 06 05 02 FF 01 FF 02 08 FF 00 11 22 33 44 55 66

广告中的 BLE 数据解码如下(基于 Assigned Numbers Document):-

  • 第一个字节 = 长度(n 个字节)
  • 第二个字节 = 类型
  • n-1 字节 = 实际数据

所以上面的数据被解码为:

12 - 18 (length of full advert report)
02 - Length of next advert report entry (2 bytes)
01 - Type: Flags
06 - 02 && 04 LE General Discoverable && BR/EDR Not supported
05 - Length of the next advert report entry (5 bytes)
02 - Type: Complete list of 16-bit UUIDs
FF 01 FF 02 - The UUIDs 0xFF01 and 0xFF02 will be included in the advert report
08 - Length of the next advert report entry
FF - Type: Manufacturer data
00 11 22 33 44 55 66 - The actual manufacturer data

话虽如此,我建议您避免使用 hcitool 命令,因为它已被弃用,并且与较新的 bluez 命令相比有很多限制。相反,您可以使用 btmgmt 工具(如果您的系统上可用)发送包含 UUID 和制造商数据的广告。为此,您可以使用以下命令:-

sudo btmgmt add-adv -u FF01 -u FF02 -d 02010608FF00112233445566 1
上面的行将 UUID 0xFF01、0xFF02 和制造商数据 00112233445566 添加到广告报告中。 btmgmt add-adv 选项的完整列表是:-

Usage: add-adv [options] <instance_id> Options: -u, --uuid <uuid> Service UUID -d, --adv-data <data> Advertising Data bytes -s, --scan-rsp <data> Scan Response Data bytes -t, --timeout <timeout> Timeout in seconds -D, --duration <duration> Duration in seconds -P, --phy <phy> Phy type, Specify 1M/2M/CODED -c, --connectable "connectable" flag -g, --general-discov "general-discoverable" flag -l, --limited-discov "limited-discoverable" flag -n, --scan-rsp-local-name "local-name" flag -a, --scan-rsp-appearance "appearance" flag -m, --managed-flags "managed-flags" flag -p, --tx-power "tx-power" flag e.g.: add-adv -u 180d -u 180f -d 080954657374204C45 1
广告中的 BLE 数据解码如下(基于 

Assigned Numbers Document):-

    第一个字节 = 长度(n 个字节)
  • 第二个字节 = 类型
  • n-1 字节 = 实际数据
所以我添加的广告数据的含义:-

02 - Length (2 bytes) 01 - Type: Flags 06 - Flag - 02 && 04 LE General Discoverable && BR/EDR Not supported 08 - Length (8 bytes) FF - Type: Manufacturer data 00112233445566 - Actual manufacturer data
其他一些有用的链接:-

  • btmgmt add-adv 不工作
  • 使用 hcitool 获取自定义制造数据
  • 蓝牙广告作品,第二部分
  • 可扫描的 BLE 信标如何在 BlueZ 堆栈上工作
© www.soinside.com 2019 - 2024. All rights reserved.