10#ifndef CONFIG_BT_CONTROLLER_DISABLED
16#include <esp_hosted.h>
18#include <eh_host_bt.h>
19#include <esp_hosted_bt_host_stack.h>
21#include <esp_bt_device.h>
22#include <esp_bt_main.h>
23#include <esp_gap_ble_api.h>
24#include <freertos/FreeRTOS.h>
25#include <freertos/FreeRTOSConfig.h>
26#include <freertos/task.h>
36#if !defined(CONFIG_BT_CONTROLLER_DISABLED) && \
37 (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3))
39#define USE_ESP32_BLE_TERMINATE_PATCH
53#ifdef USE_ESP32_BLE_TERMINATE_PATCH
60static constexpr size_t TERMINATE_MAX_EVT_SLOT = 0x7dc /
sizeof(
void *);
61static constexpr uint8_t TERMINATE_MAX_EVT = 5;
63static uint8_t IRAM_ATTR terminate_until_acked(uint8_t link_id, uint8_t acked) {
66 if (!acked && info[2] != 0 && info[3] >= TERMINATE_MAX_EVT)
67 info[3] = TERMINATE_MAX_EVT - 1;
76static const char *
const TERMINATE_PATCH_CONTROLLER_BUILDS[] = {
81static void patch_terminate_until_acked() {
83 if (table ==
nullptr) {
84 ESP_LOGW(TAG,
"Controller layout not recognised; disconnects keep the controller's 6-event limit");
88 bool known_build =
false;
89 for (
const char *known : TERMINATE_PATCH_CONTROLLER_BUILDS)
90 known_build = known_build || strcmp(build, known) == 0;
94 "Controller build %s not checked for the terminate patch; disconnects keep the controller's 6-event limit",
98 if (table[TERMINATE_MAX_EVT_SLOT] ==
reinterpret_cast<void *
>(&terminate_until_acked))
101 ESP_LOGW(TAG,
"Controller build %s has an unexpected terminate handler; terminate patch skipped", build);
104 table[TERMINATE_MAX_EVT_SLOT] =
reinterpret_cast<void *
>(&terminate_until_acked);
108#ifdef CONFIG_BT_CONTROLLER_DISABLED
119static constexpr uint32_t HOSTED_BT_WDT_TIMEOUT_MS = 60000;
123#define GAP_SCAN_COMPLETE_EVENTS \
124 case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: \
125 case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: \
126 case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT
128#define GAP_ADV_COMPLETE_EVENTS \
129 case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: \
130 case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: \
131 case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: \
132 case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT: \
133 case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: \
134 case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT
136#define GAP_SECURITY_EVENTS \
137 case ESP_GAP_BLE_AUTH_CMPL_EVT: \
138 case ESP_GAP_BLE_SEC_REQ_EVT: \
139 case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: \
140 case ESP_GAP_BLE_PASSKEY_REQ_EVT: \
141 case ESP_GAP_BLE_NC_REQ_EVT
147 ESP_LOGE(TAG,
"NVS unavailable");
153 if (this->enable_on_boot_) {
177#ifdef USE_ESP32_BLE_ADVERTISING
180 this->advertising_ref_count_++;
185 if (this->advertising_ref_count_ == 0)
187 this->advertising_ref_count_--;
192 if (this->advertising_ ==
nullptr || !this->
is_active())
195 if (this->advertising_ref_count_ == 0) {
196 this->advertising_->
stop();
254 if (this->advertising_ !=
nullptr)
265#ifdef USE_ESP32_BLE_ADVERTISING
267 if (this->advertising_ !=
nullptr)
269 this->advertising_ =
new BLEAdvertising(this->advertising_cycle_time_);
276 if (this->name_ !=
nullptr) {
280 constexpr size_t mac_address_suffix_len = 6;
281 char mac_addr[MAC_ADDRESS_BUFFER_SIZE];
284 mac_addr + mac_address_suffix_len, mac_address_suffix_len);
295#ifdef CONFIG_BT_CONTROLLER_DISABLED
298#ifndef CONFIG_BT_CONTROLLER_DISABLED
299 if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
301 if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE) {
302 esp_bt_controller_config_t cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
303 err = esp_bt_controller_init(&cfg);
305 ESP_LOGE(TAG,
"esp_bt_controller_init failed: %s", esp_err_to_name(err));
308 while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE)
311 if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED) {
312 err = esp_bt_controller_enable(ESP_BT_MODE_BLE);
314 ESP_LOGE(TAG,
"esp_bt_controller_enable failed: %s", esp_err_to_name(err));
318 if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
319 ESP_LOGE(TAG,
"esp bt controller enable failed");
323#ifdef USE_ESP32_BLE_TERMINATE_PATCH
324 patch_terminate_until_acked();
327 esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
329 if (esp_hosted_connect_to_slave() != ESP_OK) {
330 ESP_LOGE(TAG,
"Co-processor transport failed; BLE disabled");
336 esp_hosted_coprocessor_fwver_t fw_ver{};
337 if (esp_hosted_get_coprocessor_fwversion(&fw_ver) != ESP_OK) {
338 ESP_LOGE(TAG,
"Co-processor not responding; BLE disabled. Update its firmware with the esp32_hosted "
342 ESP_LOGD(TAG,
"Co-processor firmware %" PRIu32
".%" PRIu32
".%" PRIu32, fw_ver.major1, fw_ver.minor1, fw_ver.patch1);
345 err = eh_host_bt_controller_init();
346 if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
348 "BT controller init failed; co-processor firmware %" PRIu32
".%" PRIu32
".%" PRIu32
349 " may lack BT support. Update it with the esp32_hosted update component; BLE disabled",
350 fw_ver.major1, fw_ver.minor1, fw_ver.patch1);
353 err = eh_host_bt_controller_enable();
354 if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
355 ESP_LOGE(TAG,
"BT controller enable failed: %s; BLE disabled", esp_err_to_name(err));
359 esp_hosted_bt_host_stack_cfg_t bt_cfg{};
360 bt_cfg.stack = ESP_HOSTED_BT_HOST_STACK_BLUEDROID;
361 bt_cfg.bring_up_controller =
false;
362 if (esp_hosted_bt_host_stack_setup(&bt_cfg) != ESP_OK) {
363 ESP_LOGE(TAG,
"BT host stack setup failed; BLE disabled");
368 err = esp_bluedroid_init();
370 ESP_LOGE(TAG,
"esp_bluedroid_init failed: %d", err);
373 err = esp_bluedroid_enable();
375 ESP_LOGE(TAG,
"esp_bluedroid_enable failed: %d", err);
379#ifdef ESPHOME_ESP32_BLE_GAP_EVENT_HANDLER_COUNT
382 ESP_LOGE(TAG,
"esp_ble_gap_register_callback failed: %d", err);
387#if defined(USE_ESP32_BLE_SERVER) && defined(ESPHOME_ESP32_BLE_GATTS_EVENT_HANDLER_COUNT)
390 ESP_LOGE(TAG,
"esp_ble_gatts_register_callback failed: %d", err);
395#if defined(USE_ESP32_BLE_CLIENT) && defined(ESPHOME_ESP32_BLE_GATTC_EVENT_HANDLER_COUNT)
398 ESP_LOGE(TAG,
"esp_ble_gattc_register_callback failed: %d", err);
407 ESP_LOGE(TAG,
"esp_ble_gap_set_device_name failed: %d", err);
411 err = esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &(this->io_cap_),
sizeof(esp_ble_io_cap_t));
413 ESP_LOGE(TAG,
"esp_ble_gap_set_security_param iocap_mode failed: %d", err);
417#ifdef ESPHOME_ESP32_BLE_EXTENDED_AUTH_PARAMS
418 if (this->max_key_size_) {
419 err = esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &(this->max_key_size_),
sizeof(uint8_t));
421 ESP_LOGE(TAG,
"esp_ble_gap_set_security_param max_key_size failed: %d", err);
426 if (this->min_key_size_) {
427 err = esp_ble_gap_set_security_param(ESP_BLE_SM_MIN_KEY_SIZE, &(this->min_key_size_),
sizeof(uint8_t));
429 ESP_LOGE(TAG,
"esp_ble_gap_set_security_param min_key_size failed: %d", err);
434 if (this->auth_req_mode_) {
435 err = esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &(this->auth_req_mode_.value()),
436 sizeof(esp_ble_auth_req_t));
438 ESP_LOGE(TAG,
"esp_ble_gap_set_security_param authen_req_mode failed: %d", err);
451#ifdef CONFIG_BT_CONTROLLER_DISABLED
455 esp_err_t err = esp_bluedroid_disable();
458 if (err != ESP_ERR_INVALID_STATE) {
459 ESP_LOGE(TAG,
"esp_bluedroid_disable failed: %d", err);
462 ESP_LOGD(TAG,
"Already disabled");
464 err = esp_bluedroid_deinit();
467 if (err != ESP_ERR_INVALID_STATE) {
468 ESP_LOGE(TAG,
"esp_bluedroid_deinit failed: %d", err);
471 ESP_LOGD(TAG,
"Already deinitialized");
474#ifndef CONFIG_BT_CONTROLLER_DISABLED
475 if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_IDLE) {
477 if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED) {
478 err = esp_bt_controller_disable();
480 ESP_LOGE(TAG,
"esp_bt_controller_disable failed: %s", esp_err_to_name(err));
483 while (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED)
486 if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED) {
487 err = esp_bt_controller_deinit();
489 ESP_LOGE(TAG,
"esp_bt_controller_deinit failed: %s", esp_err_to_name(err));
493 if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_IDLE) {
494 ESP_LOGE(TAG,
"esp bt controller disable failed");
499 if (esp_hosted_bt_host_stack_teardown() != ESP_OK) {
500 ESP_LOGE(TAG,
"esp_hosted_bt_host_stack_teardown failed");
509 this->loop_handle_state_transition_not_active_();
513 BLEEvent *ble_event = this->ble_events_.pop();
514 if (ble_event ==
nullptr) {
520 switch (ble_event->
type_) {
521#if defined(USE_ESP32_BLE_SERVER) && defined(ESPHOME_ESP32_BLE_GATTS_EVENT_HANDLER_COUNT)
523 esp_gatts_cb_event_t
event = ble_event->
event_.
gatts.gatts_event;
524 esp_gatt_if_t gatts_if = ble_event->
event_.
gatts.gatts_if;
525 esp_ble_gatts_cb_param_t *param = &ble_event->
event_.
gatts.gatts_param;
526 ESP_LOGV(TAG,
"gatts_event [esp_gatt_if: %d] - %d", gatts_if, event);
527#ifdef USE_ESP32_BLE_ADVERTISING
529 if (event == ESP_GATTS_CONNECT_EVT && param->connect.link_role == 1)
532 this->gatts_event_callbacks_.call(event, gatts_if, param);
536#if defined(USE_ESP32_BLE_CLIENT) && defined(ESPHOME_ESP32_BLE_GATTC_EVENT_HANDLER_COUNT)
538 esp_gattc_cb_event_t
event = ble_event->
event_.
gattc.gattc_event;
539 esp_gatt_if_t gattc_if = ble_event->
event_.
gattc.gattc_if;
540 esp_ble_gattc_cb_param_t *param = &ble_event->
event_.
gattc.gattc_param;
541 ESP_LOGV(TAG,
"gattc_event [esp_gatt_if: %d] - %d", gattc_if, event);
542 this->gattc_event_callbacks_.call(event, gattc_if, param);
547 esp_gap_ble_cb_event_t gap_event = ble_event->
event_.
gap.gap_event;
549 case ESP_GAP_BLE_SCAN_RESULT_EVT:
550#ifdef ESPHOME_ESP32_BLE_GAP_SCAN_EVENT_HANDLER_COUNT
551 this->gap_scan_event_callbacks_.call(ble_event->
scan_result());
556 GAP_SCAN_COMPLETE_EVENTS:
558 GAP_ADV_COMPLETE_EVENTS:
560 case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT:
563 ESP_LOGV(TAG,
"gap_event_handler - %d", gap_event);
564#ifdef ESPHOME_ESP32_BLE_GAP_EVENT_HANDLER_COUNT
566 esp_ble_gap_cb_param_t *param = NULL;
573 GAP_SCAN_COMPLETE_EVENTS:
574 param =
reinterpret_cast<esp_ble_gap_cb_param_t *
>(&ble_event->
event_.
gap.scan_complete);
578 GAP_ADV_COMPLETE_EVENTS:
579 param =
reinterpret_cast<esp_ble_gap_cb_param_t *
>(&ble_event->
event_.
gap.adv_complete);
582 case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT:
583 param =
reinterpret_cast<esp_ble_gap_cb_param_t *
>(&ble_event->
event_.
gap.read_rssi_complete);
587 param =
reinterpret_cast<esp_ble_gap_cb_param_t *
>(&ble_event->
event_.
gap.security);
595 this->gap_event_callbacks_.call(gap_event, param);
602 ESP_LOGW(TAG,
"Unhandled GAP event type in loop: %d", gap_event);
611 this->ble_event_pool_.release(ble_event);
612 }
while ((ble_event = this->ble_events_.pop()) !=
nullptr);
617 uint16_t dropped = this->ble_events_.get_and_reset_dropped_count();
619 ESP_LOGW(TAG,
"Dropped %u BLE events due to buffer overflow", dropped);
625void ESP32BLE::loop_handle_state_transition_not_active_() {
628 ESP_LOGD(TAG,
"Disabling");
630#ifdef ESPHOME_ESP32_BLE_BLE_STATUS_EVENT_HANDLER_COUNT
631 this->ble_status_event_callbacks_.call();
635 ESP_LOGE(TAG,
"Could not be dismantled");
640#ifdef USE_ESP32_BLE_ADVERTISING
648 ESP_LOGD(TAG,
"Enabling");
652 ESP_LOGE(TAG,
"Could not be set up");
658#ifdef USE_ESP32_BLE_ADVERTISING
667 event->load_gap_event(e, p);
670#ifdef USE_ESP32_BLE_CLIENT
672 event->load_gattc_event(e, i, p);
676#ifdef USE_ESP32_BLE_SERVER
678 event->load_gatts_event(e, i, p);
685 if (event ==
nullptr) {
687 global_ble->ble_events_.increment_dropped_count();
702#ifdef USE_ESP32_BLE_SERVER
703template void enqueue_ble_event(esp_gatts_cb_event_t, esp_gatt_if_t, esp_ble_gatts_cb_param_t *);
705#ifdef USE_ESP32_BLE_CLIENT
706template void enqueue_ble_event(esp_gattc_cb_event_t, esp_gatt_if_t, esp_ble_gattc_cb_param_t *);
713 case ESP_GAP_BLE_SCAN_RESULT_EVT:
714 GAP_SCAN_COMPLETE_EVENTS:
716 GAP_ADV_COMPLETE_EVENTS:
718 case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT:
733 case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: {
736 if (param->update_conn_params.status != ESP_BT_STATUS_SUCCESS) {
737 char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
740 ESP_LOGV(TAG,
"[%s] Conn param update failed again, status=%d", mac_s, param->update_conn_params.status);
742 ESP_LOGW(TAG,
"[%s] Conn param update failed, status=%d", mac_s, param->update_conn_params.status);
743 static constexpr esp_bd_addr_t FREE{};
746 memcpy(slot, param->update_conn_params.bda,
sizeof(esp_bd_addr_t));
750#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
751 char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
753 ESP_LOGV(TAG,
"[%s] Conn params updated: interval=%u (x1.25ms) latency=%u timeout=%u (x10ms)", mac_s,
754 param->update_conn_params.conn_int, param->update_conn_params.latency,
755 param->update_conn_params.timeout);
762 case ESP_GAP_BLE_KEY_EVT:
763 case ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT:
764 case ESP_GAP_BLE_PHY_UPDATE_COMPLETE_EVT:
765 case ESP_GAP_BLE_CHANNEL_SELECT_ALGORITHM_EVT:
766 case ESP_GAP_BLE_LOCAL_IR_EVT:
767 case ESP_GAP_BLE_LOCAL_ER_EVT:
773 ESP_LOGW(TAG,
"Ignoring unexpected GAP event type: %d", event);
776#ifdef USE_ESP32_BLE_SERVER
778 esp_ble_gatts_cb_param_t *param) {
779 if (event == ESP_GATTS_DISCONNECT_EVT)
787#ifdef USE_ESP32_BLE_CLIENT
789 esp_ble_gattc_cb_param_t *param) {
790 if (event == ESP_GATTC_DISCONNECT_EVT)
799 for (
auto &slot : this->conn_param_failed_bdas_) {
800 if (memcmp(slot, bda,
sizeof(esp_bd_addr_t)) == 0)
809 memset(slot, 0,
sizeof(esp_bd_addr_t));
815 const uint8_t *mac = esp_bt_dev_get_address();
816 if (mac !=
nullptr) {
817 memcpy(
out, mac, MAC_ADDRESS_SIZE);
819 memset(
out, 0, MAC_ADDRESS_SIZE);
826 uint8_t mac_address[MAC_ADDRESS_SIZE];
829 const char *io_capability_s;
830 switch (this->io_cap_) {
832 io_capability_s =
"display_only";
835 io_capability_s =
"display_yes_no";
838 io_capability_s =
"keyboard_only";
840 case ESP_IO_CAP_NONE:
841 io_capability_s =
"none";
843 case ESP_IO_CAP_KBDISP:
844 io_capability_s =
"keyboard_display";
847 io_capability_s =
"invalid";
851 char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
856 " IO Capability: %s",
857 mac_s, io_capability_s);
858#ifdef USE_ESP32_BLE_PSRAM
859 ESP_LOGCONFIG(TAG,
" PSRAM BLE allocation: enabled");
862#ifdef ESPHOME_ESP32_BLE_EXTENDED_AUTH_PARAMS
863 const char *auth_req_mode_s =
"<default>";
864 if (this->auth_req_mode_) {
865 switch (this->auth_req_mode_.value()) {
867 auth_req_mode_s =
"no_bond";
870 auth_req_mode_s =
"bond";
873 auth_req_mode_s =
"mitm";
876 auth_req_mode_s =
"bond_mitm";
879 auth_req_mode_s =
"sc_only";
882 auth_req_mode_s =
"sc_bond";
885 auth_req_mode_s =
"sc_mitm";
888 auth_req_mode_s =
"sc_mitm_bond";
893 ESP_LOGCONFIG(TAG,
" Auth Req Mode: %s", auth_req_mode_s);
894 if (this->max_key_size_ && this->min_key_size_) {
895 ESP_LOGCONFIG(TAG,
" Key Size: %u - %u", this->min_key_size_, this->max_key_size_);
896 }
else if (this->max_key_size_) {
897 ESP_LOGCONFIG(TAG,
" Key Size: <default> - %u", this->max_key_size_);
898 }
else if (this->min_key_size_) {
899 ESP_LOGCONFIG(TAG,
" Key Size: %u - <default>", this->min_key_size_);
904 ESP_LOGCONFIG(TAG,
"Bluetooth stack is not enabled");
const char * btdm_controller_get_compile_version()
uint8_t r_lld_con_terminate_max_evt_update(uint8_t link_id, uint8_t acked)
uint8_t * r_lld_con_cntl_pkt_info_get()
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
void wake_loop_threadsafe()
Wake the main event loop from another thread or callback.
bool is_name_add_mac_suffix_enabled() const
void mark_failed()
Mark this component as failed.
void set_manufacturer_data(const std::vector< uint8_t > &data)
void add_service_uuid(ESPBTUUID uuid)
void clear_priority_uuid()
void set_include_name(bool include_name)
void set_priority_uuid(ESPBTUUID uuid)
Give uuid and the service data the advertising packet; the rest moves to the scan response.
void set_service_data(const std::vector< uint8_t > &data)
void remove_service_uuid(ESPBTUUID uuid)
void register_raw_advertisement_callback(std::function< void(bool)> &&callback)
void set_appearance(uint16_t appearance)
void request_start()
Send from the next loop(): a burst of refreshes becomes one send instead of flooding the Bluetooth ta...
BLEScanResult scan_result
struct esphome::esp32_ble::BLEEvent::@79::gap_event gap
struct esphome::esp32_ble::BLEEvent::@79::gatts_event gatts
union esphome::esp32_ble::BLEEvent::@79 event_
struct esphome::esp32_ble::BLEEvent::@79::gattc_event gattc
void advertising_set_manufacturer_data(const std::vector< uint8_t > &data)
void get_mac_msb_first(uint8_t out[MAC_ADDRESS_SIZE]) const
Adapter MAC in printable (MSB-first) order; all-zero until the stack is up.
ESPHOME_ALWAYS_INLINE void advertising_loop_()
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
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.
static void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
void advertising_start()
Request advertising on behalf of a component.
void advertising_refresh()
Apply the current payload and request count: advertise while requested, otherwise stop.
friend void enqueue_ble_event(Args... args)
void forget_conn_param_failure_(const uint8_t *bda)
uint8_t * conn_param_failed_slot_(const uint8_t *bda)
void advertising_register_raw_advertisement_callback(std::function< void(bool)> &&callback)
void advertising_set_service_data_and_name(std::span< const uint8_t > data, bool include_name)
void advertising_add_service_uuid(ESPBTUUID uuid)
void advertising_cancel_start_()
void advertising_clear_priority_uuid()
void dump_config() override
void request_state_(bool enable)
static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
void advertising_set_priority_uuid(ESPBTUUID uuid)
Keep uuid and the service data alone in the advertising packet; applies on the next refresh.
void advertising_set_service_data(const std::vector< uint8_t > &data)
ESPHOME_ALWAYS_INLINE bool is_active()
float get_setup_priority() const override
void advertising_stop()
Release a request made with advertising_start(); advertising stops at the last release.
void advertising_remove_service_uuid(ESPBTUUID uuid)
std::vector< uint8_t > & out
void load_ble_event(BLEEvent *event, esp_gap_ble_cb_event_t e, esp_ble_gap_cb_param_t *p)
@ BLE_COMPONENT_STATE_DISABLE
BLE should be disabled on next loop.
@ BLE_COMPONENT_STATE_OFF
Nothing has been initialized yet.
@ BLE_COMPONENT_STATE_ENABLE
BLE should be enabled on next loop.
@ BLE_COMPONENT_STATE_DISABLED
BLE is disabled.
@ BLE_COMPONENT_STATE_ACTIVE
BLE is active.
void enqueue_ble_event(Args... args)
ESPHOME_LOG_TAG(TAG, "esp32_ble")
constexpr float BLUETOOTH
static uint64_t const uint8_t * table
size_t make_name_with_suffix_to(char *buffer, size_t buffer_size, const char *name, size_t name_len, char sep, const char *suffix_ptr, size_t suffix_len)
Format name + separator + suffix directly into buffer without heap allocation.
size_t truncate_name_to(char *buffer, size_t buffer_size, const char *name, size_t name_len, size_t keep_suffix_len)
Copy a name into a buffer, cutting it when it does not fit.
bool mac_address_is_valid(const uint8_t *mac)
Check if the MAC address is not all zeros or all ones.
ESPPreferences * global_preferences
void get_mac_address_into_buffer(std::span< char, MAC_ADDRESS_BUFFER_SIZE > buf)
Get the device MAC address into the given buffer, in lowercase hex notation.
void HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.
char * format_mac_addr_upper(const uint8_t *mac, char *output)
Format MAC address as XX:XX:XX:XX:XX:XX (uppercase, colon separators)