3#if CONFIG_BT_BLE_ENABLED
6#include <esp_gap_ble_api.h>
10static esp_ble_adv_data_t adv_data = {
11 .set_scan_rsp =
false,
12 .include_name =
false,
13 .include_txpower =
true,
15 .min_interval = 0x000C,
16 .max_interval = 0x000C,
18 .manufacturer_len = 0,
19 .p_manufacturer_data = NULL,
20 .service_data_len = 0,
21 .p_service_data = NULL,
23 .service_uuid_len = 0,
24 .p_service_uuid = NULL,
25 .flag = ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT,
28static esp_ble_adv_data_t adv_data_rsp = {
31 .include_txpower =
false,
33 .min_interval = 0x0000,
34 .max_interval = 0x0000,
36 .manufacturer_len = 0,
37 .p_manufacturer_data = NULL,
38 .service_data_len = 0,
39 .p_service_data = NULL,
40 .service_uuid_len = 0,
41 .p_service_uuid = NULL,
42 .flag = ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT,
46static esp_ble_adv_params_t adv_params = {
49 .adv_type = ADV_TYPE_IND,
50 .own_addr_type = BLE_ADDR_TYPE_PUBLIC,
52 .peer_addr_type = BLE_ADDR_TYPE_PUBLIC,
53 .channel_map = ADV_CHNL_ALL,
54 .adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
57uint8_t adv_config_done = 0;
58const uint8_t adv_config_flag = 1 << 0;
59const uint8_t scan_rsp_config_flag = 1 << 1;
62 ESP_LOGI(
"MIDIBLE",
"advertising_set_service_uuid");
63 adv_data.p_service_uuid = (uint8_t *)uuid;
64 adv_data.service_uuid_len = length;
68 adv_data.min_interval = itvl_min;
69 adv_data.max_interval = itvl_max;
74 *itvl_min = adv_data.min_interval;
75 *itvl_max = adv_data.max_interval;
79 ESP_LOGI(
"MIDIBLE",
"advertising_config");
80 esp_err_t ret = esp_ble_gap_config_adv_data(&adv_data);
82 ESP_LOGE(
"MIDIBLE",
"config adv data failed, error code = %x", ret);
85 adv_config_done |= adv_config_flag;
86 ret = esp_ble_gap_config_adv_data(&adv_data_rsp);
88 ESP_LOGE(
"MIDIBLE",
"config adv rsp data failed, error code = %x", ret);
91 adv_config_done |= scan_rsp_config_flag;
96 if (param->adv_data_cmpl.status != ESP_BT_STATUS_SUCCESS) {
97 ESP_LOGE(
"MIDIBLE",
"esp_ble_gap_config_adv_data failed: %d",
98 param->adv_data_cmpl.status);
103 adv_config_done &= (~adv_config_flag);
104 if (adv_config_done == 0) {
105 esp_ble_gap_start_advertising(&adv_params);
111 esp_ble_gap_cb_param_t *param) {
112 if (param->scan_rsp_data_cmpl.status != ESP_BT_STATUS_SUCCESS) {
113 ESP_LOGE(
"MIDIBLE",
"esp_ble_gap_config_adv_data response failed: %d",
114 param->scan_rsp_data_cmpl.status);
119 adv_config_done &= (~scan_rsp_config_flag);
120 if (adv_config_done == 0) {
121 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.
void advertising_get_connection_interval(uint16_t *itvl_min, uint16_t *itvl_max)
Get the connection interval range from the advertising data.
void advertising_set_connection_interval(uint16_t itvl_min, uint16_t itvl_max)
Set the connection interval range in the advertising data.
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.