4#ifdef USE_ESP32_BLE_ADVERTISING
14#ifndef CONFIG_BT_CONTROLLER_DISABLED
20using ble_device_base::AdvPayload;
26static int8_t adv_tx_power_dbm() {
27#ifdef CONFIG_IDF_TARGET_ESP32
28 static constexpr int8_t TX_POWER_DBM[] = {-12, -9, -6, -3, 0, 3, 6, 9};
30 static constexpr int8_t TX_POWER_DBM[] = {-24, -21, -18, -15, -12, -9, -6, -3, 0, 3, 6, 9, 12, 15, 18, 20};
32#ifdef CONFIG_BT_CONTROLLER_DISABLED
33 const size_t level = 0;
35 const size_t level = esp_ble_tx_power_get(ESP_BLE_PWR_TYPE_ADV);
37 return TX_POWER_DBM[std::min(level, std::size(TX_POWER_DBM) - 1)];
53 this->advertising_uuids_.end());
59 memcpy(this->
service_data_.data(), data.data(), this->service_data_len_);
82 .name_len = strlen(name),
84 .tx_power_dbm = adv_tx_power_dbm(),
89 esp_err_t err = esp_ble_gap_config_adv_data_raw(
const_cast<uint8_t *
>(adv.
data()), adv.
size());
91 ESP_LOGE(TAG,
"esp_ble_gap_config_adv_data_raw failed: %s", esp_err_to_name(err));
94 err = esp_ble_gap_config_scan_rsp_data_raw(
const_cast<uint8_t *
>(rsp.
data()), rsp.
size());
96 ESP_LOGE(TAG,
"esp_ble_gap_config_scan_rsp_data_raw failed: %s", esp_err_to_name(err));
101 ESP_LOGE(TAG,
"esp_ble_gap_start_advertising failed: %s", esp_err_to_name(err));
117 esp_err_t err = esp_ble_gap_stop_advertising();
119 ESP_LOGE(TAG,
"esp_ble_gap_stop_advertising failed: %d", err);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
A 31 byte advertising or scan response payload, packed in the order and with the fit rules of Bluedro...
const uint8_t * data() const
void set_manufacturer_data(const std::vector< uint8_t > &data)
void add_service_uuid(ESPBTUUID uuid)
uint8_t service_data_len_
uint8_t manufacturer_data_len_
bool include_name_in_adv_
std::vector< ESPBTUUID > advertising_uuids_
int8_t current_adv_index_
std::array< uint8_t, MAX_DATA_LEN > service_data_
std::vector< std::function< void(bool)> > raw_advertisements_callbacks_
BLEAdvertising(uint32_t advertising_cycle_time)
static constexpr size_t MAX_DATA_LEN
esp_err_t services_advertisement_()
esp_ble_adv_params_t advertising_params_
void set_service_data(const std::vector< uint8_t > &data)
const uint32_t advertising_cycle_time_
void remove_service_uuid(ESPBTUUID uuid)
uint32_t last_advertisement_time_
std::array< uint8_t, MAX_DATA_LEN > manufacturer_data_
void register_raw_advertisement_callback(std::function< void(bool)> &&callback)
static constexpr size_t DEVICE_NAME_BUFFER_SIZE
const char * device_name(char *buffer) const
The device name; written to buffer unless the configured name is used as is.
void build_adv_packets(const AdvContent &content, AdvPayload &adv, AdvPayload &rsp)
Split content between the advertising packet and the scan response.
ESPHOME_LOG_TAG(TAG, "esp32_ble")
Application App
Global storage of Application pointer - only one Application can exist.