4#include <esp_gap_ble_api.h>
8static esp_ble_adv_data_t adv_data = {
10 .include_name =
false,
11 .include_txpower =
false,
13 .min_interval = 0x000C,
14 .max_interval = 0x000C,
16 .manufacturer_len = 0,
17 .p_manufacturer_data = NULL,
18 .service_data_len = 0,
19 .p_service_data = NULL,
21 .service_uuid_len = 0,
22 .p_service_uuid = NULL,
23 .flag = ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT,
26static esp_ble_adv_data_t adv_data_rsp = {
29 .include_txpower =
true,
31 .min_interval = 0x000C,
32 .max_interval = 0x000C,
34 .manufacturer_len = 0,
35 .p_manufacturer_data = NULL,
36 .service_data_len = 0,
37 .p_service_data = NULL,
39 .service_uuid_len = 0,
40 .p_service_uuid = NULL,
41 .flag = ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT,
45static esp_ble_adv_params_t adv_params = {
48 .adv_type = ADV_TYPE_IND,
49 .own_addr_type = BLE_ADDR_TYPE_PUBLIC,
51 .peer_addr_type = BLE_ADDR_TYPE_PUBLIC,
52 .channel_map = ADV_CHNL_ALL,
53 .adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
56uint8_t adv_config_done = 0;
57const uint8_t adv_config_flag = 1 << 0;
58const uint8_t scan_rsp_config_flag = 1 << 1;
61 ESP_LOGI(
"MIDIBLE",
"advertising_set_service_uuid");
62 adv_data.p_service_uuid = (uint8_t *)uuid;
63 adv_data.service_uuid_len = length;
67 ESP_LOGI(
"MIDIBLE",
"advertising_config");
68 esp_err_t ret = esp_ble_gap_config_adv_data(&adv_data);
70 ESP_LOGE(
"MIDIBLE",
"config adv data failed, error code = %x", ret);
73 adv_config_done |= adv_config_flag;
74 ret = esp_ble_gap_config_adv_data(&adv_data_rsp);
76 ESP_LOGE(
"MIDIBLE",
"config adv rsp data failed, error code = %x", ret);
79 adv_config_done |= scan_rsp_config_flag;
84 if (param->adv_data_cmpl.status != ESP_BT_STATUS_SUCCESS) {
85 ESP_LOGE(
"MIDIBLE",
"esp_ble_gap_config_adv_data failed: %d",
86 param->adv_data_cmpl.status);
91 adv_config_done &= (~adv_config_flag);
92 if (adv_config_done == 0) {
93 esp_ble_gap_start_advertising(&adv_params);
99 esp_ble_gap_cb_param_t *param) {
100 if (param->scan_rsp_data_cmpl.status != ESP_BT_STATUS_SUCCESS) {
101 ESP_LOGE(
"MIDIBLE",
"esp_ble_gap_config_adv_data response failed: %d",
102 param->scan_rsp_data_cmpl.status);
107 adv_config_done &= (~scan_rsp_config_flag);
108 if (adv_config_done == 0) {
109 esp_ble_gap_start_advertising(&adv_params);
void advertising_set_service_uuid(const uint8_t uuid[], uint16_t length)
Set the UUID of the service to be advertised.
bool advertising_handle_config_complete_event(esp_ble_gap_cb_param_t *param)
Callback that indicates that the configuration of the advertising data was complete.
bool advertising_config(void)
Configure the advertising data, register with the Bluetooth driver.
bool advertising_handle_config_response_complete_event(esp_ble_gap_cb_param_t *param)
Callback that indicates that the configuration of the advertising response data was complete.