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+ static uint8_t adv_data_raw [5 + sizeof (CONFIG_BLE_NAME )] = {
2525 2 ,
2626 ESP_BT_EIR_TYPE_FLAGS ,
2727 ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT ,
28- 1 + sizeof (CONFIG_BT_NAME ),
28+ 1 + sizeof (CONFIG_BLE_NAME ),
2929 ESP_BLE_AD_TYPE_NAME_CMPL
3030};
3131
@@ -54,6 +54,10 @@ static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p
5454 ESP_LOGE (BLE_GAP_TAG , "failed to stop advertising" );
5555 }
5656 break ;
57+ case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT :
58+ strcpy ((char * )adv_data_raw + 5 , CONFIG_BLE_NAME );
59+ esp_ble_gap_config_adv_data_raw (adv_data_raw , sizeof (adv_data_raw ));
60+ break ;
5761 default :
5862 break ;
5963 }
@@ -68,12 +72,8 @@ void ble_app_init(void)
6872{
6973 xEventGroupSetBits (user_event_group , BLE_GATTS_IDLE_BIT );
7074
71- esp_ble_gap_set_device_name (CONFIG_BT_NAME );
72- esp_ble_gap_set_rand_addr (ble_get_mac_address ());
7375 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 ));
76+ esp_ble_gap_config_local_privacy (true);
7777
7878 esp_ble_gatts_register_callback (ble_gatts_event_handler );
7979 esp_ble_gatts_app_register (PROFILE_IDX_OTA );
0 commit comments