Merge branch 'docs/optimized_ble_adv_data_type_v5.0' into 'release/v5.0'

docs(ble/bluedroid): Optimize BLE example for setting advertising data (v5.0)

See merge request espressif/esp-idf!32758
This commit is contained in:
Jiang Jiang Jian 2024-08-15 15:58:15 +08:00
commit 018e50895c
7 changed files with 85 additions and 42 deletions

View File

@ -69,22 +69,23 @@ static prepare_type_env_t prepare_write_env;
//#define CONFIG_SET_RAW_ADV_DATA
#ifdef CONFIG_SET_RAW_ADV_DATA
static uint8_t raw_adv_data[] = {
/* flags */
0x02, 0x01, 0x06,
/* tx power*/
0x02, 0x0a, 0xeb,
/* service uuid */
0x03, 0x03, 0xFF, 0x00,
/* device name */
0x0E, 0x09, 'B', 'L', 'E', '_', 'C', 'O','M', 'P', '_', 'T','E', 'S', 'T'
/* Flags */
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
/* TX Power */
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
/* Service UUID */
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xFF, 0x00,
/* Device Name */
0x0E, ESP_BLE_AD_TYPE_NAME_CMPL, 'B', 'L', 'E', '_', 'C', 'O', 'M', 'P', '_', 'T', 'E', 'S', 'T'
};
static uint8_t raw_scan_rsp_data[] = {
/* flags */
0x02, 0x01, 0x06,
/* tx power */
0x02, 0x0a, 0xeb,
/* service uuid */
0x03, 0x03, 0xFF,0x00
/* Flags */
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
/* TX Power */
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
/* Service UUID */
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xFF, 0x00
};
#else

View File

@ -44,11 +44,11 @@ static const uint16_t spp_service_uuid = 0xABF0;
static const uint8_t spp_adv_data[23] = {
/* Flags */
0x02,0x01,0x06,
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
/* Complete List of 16-bit Service Class UUIDs */
0x03,0x03,0xF0,0xAB,
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xF0, 0xAB,
/* Complete Local Name in advertising */
0x0F,0x09, 'E', 'S', 'P', '_', 'S', 'P', 'P', '_', 'S', 'E', 'R','V', 'E', 'R'
0x0F, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'S', 'P', 'P', '_', 'S', 'E', 'R', 'V', 'E', 'R'
};
static uint16_t spp_mtu_size = 23;

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -97,12 +97,17 @@ static uint8_t adv_config_done = 0;
#ifdef CONFIG_EXAMPLE_SET_RAW_ADV_DATA
static uint8_t raw_adv_data[] = {
0x02, 0x01, 0x06,
0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd
/* Flags */
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
/* TX Power Level */
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xEB,
/* Service UUID */
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xAB, 0xCD
};
static uint8_t raw_scan_rsp_data[] = {
0x0f, 0x09, 0x45, 0x53, 0x50, 0x5f, 0x47, 0x41, 0x54, 0x54, 0x53, 0x5f, 0x44,
0x45, 0x4d, 0x4f
/* Complete Local Name */
0x0F, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'G', 'A', 'T', 'T', 'S', '_', 'D', 'E', 'M', 'O'
};
#else

View File

@ -74,13 +74,17 @@ static uint8_t adv_config_done = 0;
#ifdef CONFIG_SET_RAW_ADV_DATA
static uint8_t raw_adv_data[] = {
0x02, 0x01, 0x06, // Length 2, Data Type 1 (Flags), Data 1 (LE General Discoverable Mode, BR/EDR Not Supported)
0x02, 0x0a, 0xeb, // Length 2, Data Type 10 (TX power leve), Data 2 (-21)
0x03, 0x03, 0xab, 0xcd, // Length 3, Data Type 3 (Complete 16-bit Service UUIDs), Data 3 (UUID)
/* Flags */
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06, // Length 2, Data Type ESP_BLE_AD_TYPE_FLAG, Data 1 (LE General Discoverable Mode, BR/EDR Not Supported)
/* TX Power Level */
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xEB, // Length 2, Data Type ESP_BLE_AD_TYPE_TX_PWR, Data 2 (-21)
/* Complete 16-bit Service UUIDs */
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xAB, 0xCD // Length 3, Data Type ESP_BLE_AD_TYPE_16SRV_CMPL, Data 3 (UUID)
};
static uint8_t raw_scan_rsp_data[] = { // Length 15, Data Type 9 (Complete Local Name), Data 1 (ESP_GATTS_DEMO)
0x0f, 0x09, 0x45, 0x53, 0x50, 0x5f, 0x47, 0x41, 0x54, 0x54, 0x53, 0x5f, 0x44,
0x45, 0x4d, 0x4f
static uint8_t raw_scan_rsp_data[] = {
/* Complete Local Name */
0x0F, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'G', 'A', 'T', 'T', 'S', '_', 'D', 'E', 'M', 'O' // Length 15, Data Type ESP_BLE_AD_TYPE_NAME_CMPL, Data (ESP_GATTS_DEMO)
};
#else

View File

@ -61,22 +61,24 @@ static prepare_type_env_t prepare_write_env;
#define CONFIG_SET_RAW_ADV_DATA
#ifdef CONFIG_SET_RAW_ADV_DATA
static uint8_t raw_adv_data[] = {
/* flags */
0x02, 0x01, 0x06,
/* tx power*/
0x02, 0x0a, 0xeb,
/* service uuid */
0x03, 0x03, 0xFF, 0x00,
/* device name */
0x0f, 0x09, 'E', 'S', 'P', '_', 'G', 'A', 'T', 'T', 'S', '_', 'D','E', 'M', 'O'
/* Flags */
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
/* TX Power Level */
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xEB,
/* Complete 16-bit Service UUIDs */
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xFF, 0x00,
/* Complete Local Name */
0x0F, ESP_BLE_AD_TYPE_NAME_CMPL,
'E', 'S', 'P', '_', 'G', 'A', 'T', 'T', 'S', '_', 'D', 'E', 'M', 'O'
};
static uint8_t raw_scan_rsp_data[] = {
/* flags */
0x02, 0x01, 0x06,
/* tx power */
0x02, 0x0a, 0xeb,
/* service uuid */
0x03, 0x03, 0xFF,0x00
/* Flags */
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
/* TX Power Level */
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xEB,
/* Complete 16-bit Service UUIDs */
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xFF, 0x00
};
#else

View File

@ -0,0 +1,14 @@
menu "Example 'GATTC_GATTS_COEX' Config"
config SET_RAW_ADV_DATA
bool "Use raw data for advertising packets and scan response data"
help
If this config item is set, raw binary data will be used to generate advertising & scan response data.
This option uses the esp_ble_gap_config_adv_data_raw() and esp_ble_gap_config_scan_rsp_data_raw()
functions.
If this config item is unset, advertising & scan response data is provided via a higher-level
esp_ble_adv_data_t structure. The lower layer will generate the BLE packets. This option has higher
overhead at runtime.
endmenu

View File

@ -116,6 +116,22 @@ esp_attr_value_t gatts_demo_char1_val = {
.attr_value = char1_str,
};
#ifdef CONFIG_SET_RAW_ADV_DATA
static uint8_t raw_adv_data[] = {
/* Flags */
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06, // Length 2, Data Type ESP_BLE_AD_TYPE_FLAG, Data 1 (LE General Discoverable Mode, BR/EDR Not Supported)
/* TX Power Level */
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xEB, // Length 2, Data Type ESP_BLE_AD_TYPE_TX_PWR, Data 2 (-21)
/* Complete 16-bit Service UUIDs */
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xAB, 0xCD // Length 3, Data Type ESP_BLE_AD_TYPE_16SRV_CMPL, Data 3 (UUID)
};
static uint8_t raw_scan_rsp_data[] = {
/* Complete Local Name */
0x0F, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'G', 'A', 'T', 'T', 'S', '_', 'D', 'E', 'M', 'O' // Length 15, Data Type ESP_BLE_AD_TYPE_NAME_CMPL, Data (ESP_GATTS_DEMO)
};
#else
static uint8_t service_uuid128[32] = {
/* LSB <--------------------------------------------------------------------------------> MSB */
//first uuid, 16bit, [12],[13] is the value
@ -156,6 +172,7 @@ static esp_ble_adv_data_t scan_rsp_data = {
.p_service_uuid = NULL,
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
};
#endif /* CONFIG_SET_RAW_ADV_DATA */
static esp_ble_adv_params_t adv_params = {
.adv_int_min = 0x20,