While developing with Silicon Labs Bluetooth SDK, users can use the API – gecko_cmd_le_gap_bt5_set_adv_data() to set the advertisement and scan response data. The data has a standard format, whereas the data passed to above API is uint8array. This article will focus on adding a middle layer between user application and the BG stack API to set the advertisement payload, which makes the payload more straightforward, visible and easier to understand for users.
For more information about the advertising data, you can go to the Bluetooth KBA Index and see the “Advertising” category.
Introduction
Below is the architecture of the advertisement constructor, which is developed on the latest Bluetooth SDK - v2.8.1, it can also be used on other versions of SDK directly or with just simple modification, depending on the specific SDK version.
adv_cons.c
adv_cons_ret_t construct_adv(adv_t adv) – function to set the advertisement and scan response data according to the input parameter.
void setup_adv(void) – example function to show how to set up advertisement and scan response data, the first three elements are used to set the advertisement data and the fourth element is used for scan response data.
adv_cons.h
ad_type_t – enumeration of all the assign numbers.
adv_packet_type_t – enumeration of all values for scan_rsp parameter of gecko_cmd_le_gap_bt5_set_adv_data()
adv_t – complete information of the advertisement or scan response data to be set.
The example sets the advertisement and scan response data as below:
Advertisement
Flags – 0x06
Complete local name – “AdvC”
More 128 uuids – Silicon Labs OTA service UUID
Scan response
Manufacturer specific data
Company ID – 0x02FF, Silicon Labs
Data - “KBA – Adv Constructor”
Import it to your project
Copy adv_cons.c and adv_cons.h to your project.
Add include ”adv_cons.h” to main.c
Call setup_adv() after gecko_evt_system_boot_id event received
Modify the second parameter of gecko_cmd_le_gap_start_advertising in main.c to le_gap_user_data.
Compile and run, verify it by e.g. Blue Gecko app, Figure 1 is a Blue Gecko app screenshot, from where you can see the advertisement details. Figure 2 is the breakdown of the advertisement payload and figure 3 is the breakdown of the scan response payload.
I am trying to use onboard DHT si7021 sensor to measure and BGM 121 to send data to a client. In my case, I need to reduce the energy consumption of the sensor hence I do not want to connect to the sensor but want to broadcast the data like a beacon. I am trying to use scan response and/or beacons as a possible solution. I tried this code but was not able to find log.h file. can you help me with this as well as with this connectionless data sharing?
KBA_BT_0205: Advertisement Constructor
While developing with Silicon Labs Bluetooth SDK, users can use the API – gecko_cmd_le_gap_bt5_set_adv_data() to set the advertisement and scan response data. The data has a standard format, whereas the data passed to above API is uint8array. This article will focus on adding a middle layer between user application and the BG stack API to set the advertisement payload, which makes the payload more straightforward, visible and easier to understand for users.
For more information about the advertising data, you can go to the Bluetooth KBA Index and see the “Advertising” category.
Introduction
Below is the architecture of the advertisement constructor, which is developed on the latest Bluetooth SDK - v2.8.1, it can also be used on other versions of SDK directly or with just simple modification, depending on the specific SDK version.
The example sets the advertisement and scan response data as below:
Import it to your project
Figure 1. Advertisement details
Figure 2. Advertisement payload breakdown
Figure 3. Scan response payload breakdown
Hi,
Thanks for reporting this and you can find the log.h file from https://github.com/KevinFuSilabs/log_module, I will also add this to the article.
Thanks,
Kevin
@Ramanand Mandayam,
You can find the log.h in the link - https://github.com/KevinFuSilabs/log_module. I will find time to update the attachment.
Thanks,
Kevin
Does the SiLabs BLE Stack "require" that the first element of the advertisement packet always contain the "flag".
I am using BLE SDK 2.11.5 and want to know if I absolutely must include this as the first element in the advertisement packet?
Nor stack nor Bluetooth Specification require any of data-types in the AdvData field.