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.
This commit is contained in:
Adam 2019-05-11 20:02:26 +12:00 committed by Me No Dev
parent 7dd537f8d3
commit bea7bd1852
2 changed files with 22 additions and 0 deletions

View File

@ -253,6 +253,27 @@ void BLEAdvertising::stop() {
log_v("<< stop"); log_v("<< stop");
} // stop } // stop
/**
* @brief Set BLE address.
* @param [in] Bluetooth address.
* @param [in] Bluetooth address type.
* Set BLE address.
*/
void BLEAdvertising::setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type)
{
log_v(">> setPrivateAddress")
m_advParams.own_addr_type = type;
esp_err_t errRc = esp_ble_gap_set_rand_addr((uint8_t*)addr);
if (errRc != ESP_OK)
{
log_e("esp_ble_gap_set_rand_addr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
log_v("<< setPrivateAddress")
} // setPrivateAddress
/** /**
* @brief Add data to the payload to be advertised. * @brief Add data to the payload to be advertised.
* @param [in] data The data to be added to the payload. * @param [in] data The data to be added to the payload.

View File

@ -58,6 +58,7 @@ public:
void setScanFilter(bool scanRequertWhitelistOnly, bool connectWhitelistOnly); void setScanFilter(bool scanRequertWhitelistOnly, bool connectWhitelistOnly);
void setScanResponseData(BLEAdvertisementData& advertisementData); void setScanResponseData(BLEAdvertisementData& advertisementData);
void setPrivateAddress(esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM); void setPrivateAddress(esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM);
void setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM);
void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param); void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param);
void setMinPreferred(uint16_t); void setMinPreferred(uint16_t);