Skip to content

Commit 454d764

Browse files
committed
Implemented ability to change BLE address (#2690)
Implemented the ability to change the ESP32s BLE device address as according the the BLE specification. This address is used when advertising the ESP32 over BLE.
1 parent 009ff57 commit 454d764

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: libraries/BLE/src/BLEAdvertising.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,27 @@ void BLEAdvertising::stop() {
253253
log_v("<< stop");
254254
} // stop
255255

256+
/**
257+
* @brief Set BLE address.
258+
* @param [in] Bluetooth address.
259+
* @param [in] Bluetooth address type.
260+
* Set BLE address.
261+
*/
262+
263+
void BLEAdvertising::setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type)
264+
{
265+
log_v(">> setPrivateAddress")
266+
267+
m_advParams.own_addr_type = type;
268+
esp_err_t errRc = esp_ble_gap_set_rand_addr((uint8_t*)addr);
269+
if (errRc != ESP_OK)
270+
{
271+
log_e("esp_ble_gap_set_rand_addr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
272+
return;
273+
}
274+
log_v("<< setPrivateAddress")
275+
} // setPrivateAddress
276+
256277
/**
257278
* @brief Add data to the payload to be advertised.
258279
* @param [in] data The data to be added to the payload.

Diff for: libraries/BLE/src/BLEAdvertising.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class BLEAdvertising {
5858
void setScanFilter(bool scanRequertWhitelistOnly, bool connectWhitelistOnly);
5959
void setScanResponseData(BLEAdvertisementData& advertisementData);
6060
void setPrivateAddress(esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM);
61+
void setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM);
6162

6263
void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param);
6364
void setMinPreferred(uint16_t);

0 commit comments

Comments
 (0)