Skip to content

Commit 10b5597

Browse files
committed
ble_app: use random address
1 parent a91460c commit 10b5597

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

main/Kconfig.projbuild

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
menu "PWM Fan Controller"
22

33
menu "Bluetooth Configuration"
4-
config BT_NAME
5-
string "Bluetooth Name"
6-
default "PWM Fan Controller"
7-
84
config ENABLE_BLE_CONTROL_IF
95
bool "Enable BLE Control Interface"
106
default y
7+
8+
config BLE_NAME
9+
string "BLE Control Interface Name"
10+
default "PWM Fan Controller"
11+
depends on ENABLE_BLE_CONTROL_IF
1112
endmenu
1213

1314
menu "Power Configuration"

main/src/user/ble_app.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
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

Comments
 (0)