KBA_BT_0202: Bluetooth advertising using manufacturer specific data
11/318/2017 | 07:00 AM
Introduction
The basic structure of advertising packets and how to the advertising data is set was covered in article Bluetooth advertising data basics. This article focuses on one specific type of advertising type: Manufacturer Specific Data (type 0xFF).
Manufacturer specific data can be used to add any custom data into advertising packets, using any format that is suitable for your application. For example, you could create a beacon that includes the reading of a temperature sensor it the advertising data.
Custom advertising data example
Let’s assume the following requirements for a BLE beacon:
The device must include its name in advertising packets
The advertising data must also contain a counter value that changes dynamically
We want to advertise the device name so that it is easy to identify the device using any BLE-capable smartphone app, such as the Blue Gecko app for Android / iOS.
To demonstrate dynamic changing of advertising payload, the counter is incremented/decremented when pushbuttons PB1/PB0 on the development kit are pressed. Let’s use one byte for the counter value, meaning that the range is 0..255. As an additional feature, we will also include one byte to indicate which button was pressed last.
Example of an advertising packet that contains the device name and the 8-bit counter value is shown below.
This advertising packet consists of three elements (as explained in the advertising data basics article):
First element is the flags
The second elements contains the counter value and an indication of which button was pressed last
The third and last element is the device name
The second element uses type 0xFF indicating manufacture specific data, meaning that we can formulate the data (almost) any way we want. The other two elements are using predefined AD types.
Note that the custom AD element is formatted using the same convention as any other elements. It begins with a length indicator so that any client receiving this data can still parse the advertising packet element by element and simply jump over those elements that it does not know how to decode.
The first 2 octets contain the Company Identifier Code. Company Identifiers are listed at https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers . The remaining bytes in the custom element can be used for any purpose. The total size of the packet obviously cannot exceed the maximum size that is 31 bytes.
In the example used in this article, the company ID is followed by two additional bytes: one to represent the number of button presses (zero in above example) and another byte to indicate which button was pressed last (0xFF in above example, meaning neither button has been pressed so far).
Using custom advertising data with Silicon Labs Bluetooth SDK
The following two API calls are needed to use custom advertising (and scan response) data:
cmd_le_gap_bt5_set_adv_data
cmd_le_gap_start_advertising
The first call is used to set the advertising data content before starting advertisements. Calling the latter starts the advertising. When using custom data, it is important to note that the parameter "discoverable mode" must be set to le_gap_user_data (value 4).
The code sample included in the next section sets up advertising using the custom format defined earlier in this article.
Code sample
The attached zip file includes sample code to demonstrate how to set custom advertising data. Functions for initializing and updating the custom advertising data content are found in custom_adv.c/h.
This code can be easily added on top of the SoC Empty example. Just copy the files app.c, custom_adv.h and custom_adv.c to the project.
To locate the code that is used to set up and update custom advertising, see event handlers for gecko_evt_system_boot_id and gecko_evt_system_external_signal_id.
The example uses GPIOINT driver from EMDRV to handle button interrupts. Therefore you need to also add file gpiointerrupt.c to your project. It can be copied from the platform directory in the SDK installation. The path is of the form:
As far as the Company ID is concerned, it's not so clear if custom advertising data requires an own Company ID or a different one (e.g. Apple one in case of iBeacon for example, or Silabs...!)
Have you some information about this?
Thanks in advance
0
@ADP custom advertising requires a valid Company ID. If your device is advertising using the iBeacon format, then it would use the Company ID of Apple (because iBeacon format is specified by Apple). BT SIG member companies can also get their own company ID.
The company ID 0xFFFF is reserved for test use only. This is quoted from the BT SIG webpage linked above:
This value (0xFFFF) may be used in the internal and interoperability tests before a Company ID has been assigned. This value shall not be used in shipping end products.
0
it's not so clear if custom advertising data requires an own Company ID Click here
KBA_BT_0202: Bluetooth advertising using manufacturer specific data
Introduction
The basic structure of advertising packets and how to the advertising data is set was covered in article Bluetooth advertising data basics. This article focuses on one specific type of advertising type: Manufacturer Specific Data (type 0xFF).
Manufacturer specific data can be used to add any custom data into advertising packets, using any format that is suitable for your application. For example, you could create a beacon that includes the reading of a temperature sensor it the advertising data.
Custom advertising data example
Let’s assume the following requirements for a BLE beacon:
We want to advertise the device name so that it is easy to identify the device using any BLE-capable smartphone app, such as the Blue Gecko app for Android / iOS.
To demonstrate dynamic changing of advertising payload, the counter is incremented/decremented when pushbuttons PB1/PB0 on the development kit are pressed. Let’s use one byte for the counter value, meaning that the range is 0..255. As an additional feature, we will also include one byte to indicate which button was pressed last.
Example of an advertising packet that contains the device name and the 8-bit counter value is shown below.
This advertising packet consists of three elements (as explained in the advertising data basics article):
The second element uses type 0xFF indicating manufacture specific data, meaning that we can formulate the data (almost) any way we want. The other two elements are using predefined AD types.
Note that the custom AD element is formatted using the same convention as any other elements. It begins with a length indicator so that any client receiving this data can still parse the advertising packet element by element and simply jump over those elements that it does not know how to decode.
The first 2 octets contain the Company Identifier Code. Company Identifiers are listed at https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers . The remaining bytes in the custom element can be used for any purpose. The total size of the packet obviously cannot exceed the maximum size that is 31 bytes.
In the example used in this article, the company ID is followed by two additional bytes: one to represent the number of button presses (zero in above example) and another byte to indicate which button was pressed last (0xFF in above example, meaning neither button has been pressed so far).
Using custom advertising data with Silicon Labs Bluetooth SDK
The following two API calls are needed to use custom advertising (and scan response) data:
The first call is used to set the advertising data content before starting advertisements. Calling the latter starts the advertising. When using custom data, it is important to note that the parameter "discoverable mode" must be set to le_gap_user_data (value 4).
The code sample included in the next section sets up advertising using the custom format defined earlier in this article.
Code sample
The attached zip file includes sample code to demonstrate how to set custom advertising data. Functions for initializing and updating the custom advertising data content are found in custom_adv.c/h.
This code can be easily added on top of the SoC Empty example. Just copy the files app.c, custom_adv.h and custom_adv.c to the project.
To locate the code that is used to set up and update custom advertising, see event handlers for gecko_evt_system_boot_id and gecko_evt_system_external_signal_id.
The example uses GPIOINT driver from EMDRV to handle button interrupts. Therefore you need to also add file gpiointerrupt.c to your project. It can be copied from the platform directory in the SDK installation. The path is of the form:
{$StudioPath}\vX\developer\sdks\gecko_sdk_suite\vY\platform\emdrv\gpiointerrupt\src\
Now you can start smashing buttons and see the counter value change!
As far as the Company ID is concerned, it's not so clear if custom advertising data requires an own Company ID or a different one (e.g. Apple one in case of iBeacon for example, or Silabs...!)
Have you some information about this?
Thanks in advance
@ADP custom advertising requires a valid Company ID. If your device is advertising using the iBeacon format, then it would use the Company ID of Apple (because iBeacon format is specified by Apple). BT SIG member companies can also get their own company ID.
https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers
The company ID 0xFFFF is reserved for test use only. This is quoted from the BT SIG webpage linked above: