我在定制的嵌入式Linux 5.15板上运行BlueZ 5.56.主板上装有Atmel wilc3000 WiFi/蓝牙无线电.我已经基于Bluez示例实现了一个python GATT服务器,它在raspberry pi上工作得很好.然而,该示例的广告部分不适用于Wilc3000.因此,我正在使用hciool手动启动广告.这些广告起作用了--然而,我想不出如何将制造数据与服务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

推荐答案

我认为主要问题是您设置了两次广告报告,最有可能发生的情况是第二个广告报告覆盖了第一个广告报告.您只需按如下方式调用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

广告中的数据解码如下(以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命令,因为它是deprecated,并且与较新的Bluez命令相比有许多限制.相反,您可以使用btmgmt工具(如果您的系统上有此工具)来发送同时包含UUID和制造商数据的广告.为此,您可以使用以下命令:-

sudo btmgmt add-adv -u FF01 -u FF02 -d 02010608FF00112233445566 1

上面的行将UUID 0xFF01、0xFF02和制造商数据00112233445566添加到广告报告中.Btmgmt添加-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

广告中的数据解码如下(以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

其他一些有用的链接:

Linux相关问答推荐

Linux内核中维护进程无关寄存器失败

如何将一个变量的 2 行添加到另一个变量的特定行?

我需要制作一个 awk 脚本来解析文件中的文本.我不确定我是否做得正确

如何重新安装最新的 cmake 版本?

隐藏文件 .env 未使用 Docker COPY 复制

如何在 linux 'screen' 中搜索任何单词

在 Ubuntu 中重启 Nginx

在 bash 中检测公共 IP 地址的方法

exec 系统调用(如 exec 和 execve)系列的功能有什么区别?

bash 脚本中的自动 docker 登录

用于 ssh 的类似 teamviewer 的工具?

qstat 和长作业(job)名称

如何知道linux调度器时间片?

linux根据文件名模式搜索文件

linux perf:如何解释和查找热点

Vim 增量搜索

如何在 Linux 中将 .so 文件添加到 java.library.path

Linux(Ubuntu)终端-如何查看以前的页面不再可见

构建窗口管理器

在linux中根据内容拆分文件