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