两个问题:
首先,为了使BlueZ进行广告发布,您提供的字节序列必须包含一个有效的BLE广告标题 ,该 标题 至少为8个字节。因此,要宣传“
helloworld”,您实际上需要发送:
sudo hcitool -i hci0 cmd 0x08 0x0008 10 02 01 1a 0c ff 18 01 48 45 4c 4c 4f 57
4f 52 4c 44
前8个字节为标头,后10个字节为编码为8位ASCII的字符串“ helloworld”。
前8个字节可以像这样分解:
10 # Total length of the advertising packet02 # Number of bytes that follow in first AD structure01 # Flags AD type1A # Flags value 0x1A = 000011010 bit 0 (OFF) LE Limited Discoverable Mode bit 1 (ON) LE General Discoverable Mode bit 2 (OFF) BR/EDR Not Supported bit 3 (ON) Simultaneous LE and BR/EDR to Same Device Capable (controller) bit 4 (ON) Simultaneous LE and BR/EDR to Same Device Capable (Host)0C # Number of bytes that follow in second (and last) AD structureFF # Manufacturer specific data AD type18 01 # Company identifier pre (0x0118 == Radius Networks)
请注意,此标头包含两个不同的长度字段,如果您更改“
helloworld”有效负载的长度,则必须调整这些字段。另外,出于实验目的,欢迎您将任意两个字节用作所需的公司标识符。
其次,您无法使用该hcitool lescan
命令查看检测到的广告的原始字节。要查看原始字节,必须将此命令与
hcidump命令结合使用



