KBA_BT_0203: Providing Extra Data by Scan Response
12/361/2017 | 02:30 PM
Introduction
This article describes how to use scan responses to provide additional information about an advertising device without the need to establish a connection
Discussion
The Bluetooth specification defines the size of advertising packets to be thirty-one (31) bytes. This is enough to advertise the name of a device and a short list of services. However, it may be desirable to advertise either a longer name, a longer list of services or other information such as transmit power without establishing a connection. This can be accomplished through the use of scan responses. When a scanner receives an advertising packet from an advertising device, it has the option to request additional data through the use of an active scan. The advertising device can then reply with a different thirty-one byte packet known as a scan response.
Implementation
In this example, we’ll set up a scan response that includes a 128 bit service UUID as well as the transmitted power.
To set up scan responses, the API function cmd_le_gap_set_adv_data() can be used. This API takes two parameters : an 8 bit integer to indicate the type of packet and an array of data to be sent. Start by creating an array of data to be sent in the scan response packet as shown below
This packet contains three pieces of information. The first indicates the flags used. The second indicates the complete list of 128 service class UUIDs. In this case there is a single service being advertised with the UUID 4ab1a750-f49e-4fde-8d06-25de001e7f18. Finally, the transmit power is indicated.
Next, make a call to le_cmd_gap_set_adv_data() as follows
An example main.c is provided along with this article. To use this example, go to the SimplicityStudio Appbuilder and create an soc-empty project for radio board. Replace main.c of this newly generated project with the attached main.c. Next, go to the visual GATT editor and create a new service with the following UUID 4ab1a750-f49e-4fde-8d06-25de001e7f18 and click generate. Now you have a project that advertises it’s name as “Scan test” and will reply to scan requests with the data shown above. You can also import the gatt.xml file to create this service.
This can be seen with the Silicon Labs Blue Gecko mobile app. Open the app and tap “Bluetooth Browser”, find the “Scan test” device, tap the icon on the right and select “advertisement details. You’ll see that the name, service and tx power are all shown in the details.
Additional Reading
Please see the Bluetooth list of assigned numbers for additional information regarding data types used in advertising packets
thx for the example. I want to use it for my first BLE project. I did your instruction steps with a fresh installes Smplicity Studio and get errors of not founded librarys:
#include "boards.h"
#include "aat.h"
#include "bspconfig.h"
#include "InitDevice.h"
and:
enter_DefaultMode_from_RESET(); // implicit declaration of function 'enter_DefaultMode_from_RESET' [-Wimplicit-function-declaration]Sorry for the beginner questions ;)
Peter
0
Hi,
I am using the efr32bg22 ble first time using, how to advertise the data I beacon format including sensor data. Please share the protocol format with any example.
KBA_BT_0203: Providing Extra Data by Scan Response
Introduction
This article describes how to use scan responses to provide additional information about an advertising device without the need to establish a connection
Discussion
The Bluetooth specification defines the size of advertising packets to be thirty-one (31) bytes. This is enough to advertise the name of a device and a short list of services. However, it may be desirable to advertise either a longer name, a longer list of services or other information such as transmit power without establishing a connection. This can be accomplished through the use of scan responses. When a scanner receives an advertising packet from an advertising device, it has the option to request additional data through the use of an active scan. The advertising device can then reply with a different thirty-one byte packet known as a scan response.
Implementation
In this example, we’ll set up a scan response that includes a 128 bit service UUID as well as the transmitted power.
To set up scan responses, the API function cmd_le_gap_set_adv_data() can be used. This API takes two parameters : an 8 bit integer to indicate the type of packet and an array of data to be sent. Start by creating an array of data to be sent in the scan response packet as shown below
uint8 scan_resp_data[31] = {0x02,0x01,0x06,
0x11,0x07,0x18,0x7f,0x1e,0x00,0xde,0x25,0x06,0x8d,0xde,0x4f,0x9e,0xf4,0x50,0xa7,0xb1,0x4a, 0x02, 0x0A, 0x00}; /* indicate tx power = 0 dBm*/
This packet contains three pieces of information. The first indicates the flags used. The second indicates the complete list of 128 service class UUIDs. In this case there is a single service being advertised with the UUID 4ab1a750-f49e-4fde-8d06-25de001e7f18. Finally, the transmit power is indicated.
Next, make a call to le_cmd_gap_set_adv_data() as follows
/* scan response data*/
gecko_cmd_le_gap_set_adv_data(1,sizeof(scan_resp_data), scan_resp_data);
to set the data used for scan responses.
Example
An example main.c is provided along with this article. To use this example, go to the SimplicityStudio Appbuilder and create an soc-empty project for radio board. Replace main.c of this newly generated project with the attached main.c. Next, go to the visual GATT editor and create a new service with the following UUID 4ab1a750-f49e-4fde-8d06-25de001e7f18 and click generate. Now you have a project that advertises it’s name as “Scan test” and will reply to scan requests with the data shown above. You can also import the gatt.xml file to create this service.
This can be seen with the Silicon Labs Blue Gecko mobile app. Open the app and tap “Bluetooth Browser”, find the “Scan test” device, tap the icon on the right and select “advertisement details. You’ll see that the name, service and tx power are all shown in the details.
Additional Reading
Please see the Bluetooth list of assigned numbers for additional information regarding data types used in advertising packets
https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
Hi Steve,
thx for the example. I want to use it for my first BLE project. I did your instruction steps with a fresh installes Smplicity Studio and get errors of not founded librarys:
#include "boards.h"
#include "aat.h"
#include "bspconfig.h"
#include "InitDevice.h"
and:
enter_DefaultMode_from_RESET(); // implicit declaration of function 'enter_DefaultMode_from_RESET' [-Wimplicit-function-declaration]Sorry for the beginner questions ;)
Peter
Hi,
I am using the efr32bg22 ble first time using, how to advertise the data I beacon format including sensor data. Please share the protocol format with any example.
Regards