2121#define BLE_APP_TAG "ble_app"
2222#define BLE_GAP_TAG "ble_gap"
2323
24- static uint8_t adv_data_raw [5 + sizeof (CONFIG_BT_NAME )] = {
24+ #ifdef CONFIG_ENABLE_BLE_CONTROL_IF
25+ static uint8_t adv_data_raw [5 + sizeof (CONFIG_BLE_NAME )] = {
2526 2 ,
2627 ESP_BT_EIR_TYPE_FLAGS ,
2728 ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT ,
28- 1 + sizeof (CONFIG_BT_NAME ),
29+ 1 + sizeof (CONFIG_BLE_NAME ),
2930 ESP_BLE_AD_TYPE_NAME_CMPL
3031};
3132
@@ -54,6 +55,10 @@ static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p
5455 ESP_LOGE (BLE_GAP_TAG , "failed to stop advertising" );
5556 }
5657 break ;
58+ case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT :
59+ strcpy ((char * )adv_data_raw + 5 , CONFIG_BLE_NAME );
60+ esp_ble_gap_config_adv_data_raw (adv_data_raw , sizeof (adv_data_raw ));
61+ break ;
5762 default :
5863 break ;
5964 }
@@ -68,12 +73,8 @@ void ble_app_init(void)
6873{
6974 xEventGroupSetBits (user_event_group , BLE_GATTS_IDLE_BIT );
7075
71- esp_ble_gap_set_device_name (CONFIG_BT_NAME );
72- esp_ble_gap_set_rand_addr (ble_get_mac_address ());
7376 esp_ble_gap_register_callback (ble_gap_event_handler );
74-
75- strcpy ((char * )adv_data_raw + 5 , CONFIG_BT_NAME );
76- esp_ble_gap_config_adv_data_raw (adv_data_raw , sizeof (adv_data_raw ));
77+ esp_ble_gap_config_local_privacy (true);
7778
7879 esp_ble_gatts_register_callback (ble_gatts_event_handler );
7980 esp_ble_gatts_app_register (PROFILE_IDX_OTA );
@@ -83,3 +84,4 @@ void ble_app_init(void)
8384
8485 ESP_LOGI (BLE_APP_TAG , "started." );
8586}
87+ #endif
0 commit comments