mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
docs(ble/bluedroid): Optimize BLE example documentation
This commit is contained in:
parent
82a29b7d21
commit
3a9e05984a
@ -363,6 +363,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
|
||||
if (adv_name != NULL) {
|
||||
if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
|
||||
// Note: If there are multiple devices with the same device name, the device may connect to an unintended one.
|
||||
// It is recommended to change the default device name to ensure it is unique.
|
||||
ESP_LOGI(GATTC_TAG, "Device found %s", remote_device_name);
|
||||
if (connect == false) {
|
||||
connect = true;
|
||||
|
@ -365,6 +365,8 @@ We are interested in the `ESP_GAP_SEARCH_INQ_RES_EVT` event, which is called eve
|
||||
ESP_LOGI(GATTC_TAG, " ");
|
||||
if (adv_name != NULL) {
|
||||
if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
|
||||
// Note: If there are multiple devices with the same device name, the device may connect to an unintended one.
|
||||
// It is recommended to change the default device name to ensure it is unique.
|
||||
ESP_LOGI(GATTC_TAG, "searched device %s", remote_device_name);
|
||||
if (connect == false) {
|
||||
connect = true;
|
||||
|
@ -458,6 +458,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
ESP_LOG_BUFFER_CHAR(GATTC_TAG, adv_name, adv_name_len);
|
||||
if (adv_name != NULL) {
|
||||
if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
|
||||
// Note: If there are multiple devices with the same device name, the device may connect to an unintended one.
|
||||
// It is recommended to change the default device name to ensure it is unique.
|
||||
ESP_LOGI(GATTC_TAG, "Device found %s", remote_device_name);
|
||||
if (connect == false) {
|
||||
connect = true;
|
||||
|
@ -492,6 +492,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
ESP_BLE_AD_TYPE_NAME_CMPL,
|
||||
&adv_name_len);
|
||||
if (!connect && strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
|
||||
// Note: If there are multiple devices with the same device name, the device may connect to an unintended one.
|
||||
// It is recommended to change the default device name to ensure it is unique.
|
||||
connect = true;
|
||||
esp_ble_gap_stop_ext_scan();
|
||||
ESP_LOGI(GATTC_TAG, "Device found "ESP_BD_ADDR_STR"", ESP_BD_ADDR_HEX(param->ext_adv_report.params.addr));
|
||||
|
@ -47,11 +47,6 @@
|
||||
|
||||
static SemaphoreHandle_t test_sem = NULL;
|
||||
|
||||
uint8_t addr_1m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x01};
|
||||
uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02};
|
||||
uint8_t addr_legacy[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x03};
|
||||
uint8_t addr_coded[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x04};
|
||||
|
||||
esp_ble_gap_ext_adv_params_t ext_adv_params_1M = {
|
||||
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE,
|
||||
.interval_min = 0x30,
|
||||
@ -236,26 +231,39 @@ void app_main(void)
|
||||
return;
|
||||
}
|
||||
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
// create static random address
|
||||
esp_bd_addr_t addr_1m;
|
||||
esp_bd_addr_t addr_2m;
|
||||
esp_bd_addr_t addr_legacy;
|
||||
esp_bd_addr_t addr_coded;
|
||||
esp_ble_gap_addr_create_static(addr_1m);
|
||||
esp_ble_gap_addr_create_static(addr_2m);
|
||||
esp_ble_gap_addr_create_static(addr_legacy);
|
||||
esp_ble_gap_addr_create_static(addr_coded);
|
||||
|
||||
test_sem = xSemaphoreCreateBinary();
|
||||
|
||||
// 1M phy extend adv, Connectable advertising
|
||||
ESP_LOG_BUFFER_HEX(LOG_TAG, addr_1m, ESP_BD_ADDR_LEN);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(0, &ext_adv_params_1M), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(0, addr_1m), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_adv_data_raw(0, sizeof(raw_adv_data_1m), &raw_adv_data_1m[0]), test_sem);
|
||||
|
||||
// 2M phy extend adv, Scannable advertising
|
||||
ESP_LOG_BUFFER_HEX(LOG_TAG, addr_2m, ESP_BD_ADDR_LEN);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(1, &ext_adv_params_2M), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(1, addr_2m), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_scan_rsp_data_raw(1, sizeof(raw_scan_rsp_data_2m), raw_scan_rsp_data_2m), test_sem);
|
||||
|
||||
// 1M phy legacy adv, ADV_IND
|
||||
ESP_LOG_BUFFER_HEX(LOG_TAG, addr_legacy, ESP_BD_ADDR_LEN);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(2, &legacy_adv_params), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(2, addr_legacy), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_adv_data_raw(2, sizeof(legacy_adv_data), &legacy_adv_data[0]), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_scan_rsp_data_raw(2, sizeof(legacy_scan_rsp_data), &legacy_scan_rsp_data[0]), test_sem);
|
||||
|
||||
// coded phy extend adv, Scannable advertising
|
||||
ESP_LOG_BUFFER_HEX(LOG_TAG, addr_coded, ESP_BD_ADDR_LEN);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(3, &ext_adv_params_coded), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(3, addr_coded), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_scan_rsp_data_raw(3, sizeof(raw_scan_rsp_data_coded), &raw_scan_rsp_data_coded[0]), test_sem);
|
||||
|
@ -56,9 +56,6 @@
|
||||
|
||||
static SemaphoreHandle_t test_sem = NULL;
|
||||
|
||||
|
||||
uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02};
|
||||
|
||||
esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
|
||||
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED,
|
||||
.interval_min = 0x30,
|
||||
@ -81,18 +78,16 @@ static esp_ble_gap_periodic_adv_params_t periodic_adv_params = {
|
||||
};
|
||||
|
||||
static uint8_t periodic_adv_raw_data[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x03, 0x03, 0xab, 0xcd,
|
||||
0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I',
|
||||
'C', '_', 'A', 'D', 'V'
|
||||
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
|
||||
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
|
||||
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xab, 0xcd,
|
||||
0x11, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', 'C', '_', 'A', 'D', 'V'
|
||||
};
|
||||
|
||||
static uint8_t raw_ext_adv_data_2m[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x13, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
|
||||
'D', 'V', '_', '8', '0', 'M', 'S'
|
||||
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
|
||||
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
|
||||
0x11, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'E', 'X', 'T', 'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V'
|
||||
};
|
||||
|
||||
static esp_ble_gap_ext_adv_t ext_adv[1] = {
|
||||
@ -195,12 +190,16 @@ void app_main(void)
|
||||
return;
|
||||
}
|
||||
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
// create static random address
|
||||
esp_bd_addr_t rand_addr;
|
||||
esp_ble_gap_addr_create_static(rand_addr);
|
||||
|
||||
test_sem = xSemaphoreCreateBinary();
|
||||
// 2M phy extend adv, Connectable advertising
|
||||
|
||||
// 2M phy extend adv, Non-Connectable and Non-Scannable Undirected advertising
|
||||
ESP_LOG_BUFFER_HEX(LOG_TAG, rand_addr, ESP_BD_ADDR_LEN);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(EXT_ADV_HANDLE, &ext_adv_params_2M), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(EXT_ADV_HANDLE, addr_2m), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(EXT_ADV_HANDLE, rand_addr), test_sem);
|
||||
FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_adv_data_raw(EXT_ADV_HANDLE, sizeof(raw_ext_adv_data_2m), &raw_ext_adv_data_2m[0]), test_sem);
|
||||
|
||||
// start all adv
|
||||
|
@ -216,10 +216,9 @@ Ext adv raw data:
|
||||
|
||||
```c
|
||||
static uint8_t raw_ext_adv_data_2m[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x13, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A',
|
||||
'D', 'V', '_', '8', '0', 'M', 'S'
|
||||
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
|
||||
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
|
||||
0x11, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'E', 'X', 'T', 'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V'
|
||||
};
|
||||
```
|
||||
|
||||
@ -236,11 +235,10 @@ static esp_ble_gap_periodic_adv_params_t periodic_adv_params = {
|
||||
|
||||
```c
|
||||
static uint8_t periodic_adv_raw_data[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x02, 0x0a, 0xeb,
|
||||
0x03, 0x03, 0xab, 0xcd,
|
||||
0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I',
|
||||
'C', '_', 'A', 'D', 'V'
|
||||
0x02, ESP_BLE_AD_TYPE_FLAG, 0x06,
|
||||
0x02, ESP_BLE_AD_TYPE_TX_PWR, 0xeb,
|
||||
0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xab, 0xcd,
|
||||
0x11, ESP_BLE_AD_TYPE_NAME_CMPL, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', 'C', '_', 'A', 'D', 'V'
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -48,7 +48,7 @@
|
||||
#define EXT_SCAN_DURATION 0
|
||||
#define EXT_SCAN_PERIOD 0
|
||||
|
||||
static char remote_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "ESP_MULTI_ADV_80MS";
|
||||
static char remote_device_name[ESP_BLE_ADV_NAME_LEN_MAX] = "ESP_EXTENDED_ADV";
|
||||
static SemaphoreHandle_t test_sem = NULL;
|
||||
|
||||
static esp_ble_ext_scan_params_t ext_scan_params = {
|
||||
@ -114,6 +114,8 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
ESP_BLE_AD_TYPE_NAME_CMPL,
|
||||
&adv_name_len);
|
||||
if ((adv_name != NULL) && (memcmp(adv_name, remote_device_name, adv_name_len) == 0) && !periodic_sync) {
|
||||
// Note: If there are multiple devices with the same device name, the device may sync to an unintended one.
|
||||
// It is recommended to change the default device name to ensure it is unique.
|
||||
periodic_sync = true;
|
||||
char adv_temp_name[30] = {'0'};
|
||||
memcpy(adv_temp_name, adv_name, adv_name_len);
|
||||
|
Loading…
Reference in New Issue
Block a user