问题
I am writing a custom service over BLE to transmit custom characteristics. It has it's own UUID such as '8E400001-B5A3-F393-E0A9-E50E24DCCA9E'.
I have found that a particular android app (BLE client) I wish to support requires that a custom service UUID is included in the advertising packet.
However our peripheral is running via bluez 5.43 on debian and I cannot figure out how to put this UUID in the advertising packet.
I think it will be something like:
hcitool -i hci0 cmd 0x08 0x0008 .... ?
回答1:
I verified the following commands to be working (BlueZ ver 5.43, Linux 4.9.0-2-amd64 (x86_64)):
hcitool -i hci0 cmd 0x08 0x0008 12 11 07 9E CA DC 24 0E E5 A9 E0 93 F3 A3 B5 01 00 40 8E 00 00 00 00 00 00 00 00 00 00 00 00 00
Explanation:
I assume everything until 0x0008 is clear, if not let me know or look at the description of the LE Set Advertising Data Command in the spec. 0x12 is Advertising_Data_Length
, i.e., the number of useful bytes that comes after (until the padding bytes). Now you have to insert the Advertising_Data
, which is formatted as in Vol 3 Part C, Section 11, Fig. 11.1 of the spec. So, 0x11 is the length of the AD Structure. Then, 0x07 is the AD Type "Complete List of 128-bit Service Class UUIDs" (see here). Finally comes the UUID. Notice that everything is little endian.
Then send the LE Set Advertising Parameters Commands, for example:
hcitool -i hci0 cmd 0x08 0x0006 00 08 00 08 00 00 00 00 00 00 00 00 00 07 00
Then enable advertising by sending the LE Advertising Enable command:
hcitool -i hci0 cmd 0x08 0x000A 01
See btmon output here.
来源:https://stackoverflow.com/questions/47427913/advertise-custom-service-uuid-with-bluez-5-4x