Advertising Manufacturer Specific Data
This code example has a related User's Guide, here: Bluetooth Advertising Data Basics.
The general structure of advertising packets is described in Bluetooth Advertising Data Basics. This document focuses on a Manufacturer-Specific Data (type 0xFF) as a specific advertising type.
Manufacturer-specific data can be used to add any custom data into advertising packets in any format suitable for your application. For example, you could create a beacon that includes the reading of a temperature sensor in the advertising data.
The assumption is that your application has the following requirements:
The device must include its name in advertising packets
The advertising data must also contain a counter value that changes dynamically
Advertise the device name so that it is easy to identify the device using any BLE-capable smart phone app, such as the EFR Connect app for Android / iOS.
To demonstrate dynamic changing of the advertising payload, the counter is incremented/decremented when pushbuttons PB1/PB0 on the development kit are pressed. One byte is used for the counter value, meaning that the range is 0..255. As an additional feature, one byte is included to indicate which button was pressed last.
An example of an advertising packet that contains the device name and the 8-bit counter value is shown below.
Adv Data Example
This advertising packet consists of three elements (as explained in the advertising data basics documentation):
The first element is the flags.
The second element contains the counter value and an indication of which button was pressed last.
The third and the last element is the device name.
The second element uses type 0xFF indicating manufacturer-specific data, meaning that data can be formulated in (almost) any way. 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 skip 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 cannot exceed the maximum size that is 31 bytes.
In the example used here, the company ID is followed by two additional bytes, one to represent the number of button presses (zero in the above example) and another byte to indicate which button was pressed last (0xFF in the above example, meaning neither button has been pressed so far).
The following two API calls are needed to use custom advertising (and scan response) data:
The first call sets the advertising data content before starting advertisements. Calling the latter starts the advertising. When using custom data, note that the parameter "discoverable mode" must be set to le_gap_user_data (value 4).
The attached code example sets up advertising using the custom format defined earlier in this document.
Create an SoC-Empty software example for your device in Simplicity Studio.
Copy the attached files (app.c, custom_adv.c, custom_adv.h) into the project (overwriting existing ones).
Copy gpiointerrupt.c file from the SDK directories (
C:\SiliconLabs\SimplicityStudio\vX\developer\sdks\gecko_sdk_suite\vY\platform\emdrv\gpiointerrupt\src) to the project's
Build and flash the project to your device.
A smart phone app is required, such as the EFR Connect app, to see nearby advertising devices.
Open the EFR Connect app.
Open the Bluetooth Browser.
Find the device advertising as CustomAdvDemo.
Click on the context menu of the device and select "Advertisement Details". Now, you should see the counter and the last button value above MANUFACTURER SPECIFIC DATA.
Push PB1 some times on your WSTK.
Refresh the list of devices in the Bluetooth Browser.
Select "Advertisement Details" next to CustomAdvDemo.
Check the value of the counter again.
Manufacturer specific data