7#ifdef USE_ESP32_BLE_ADVERTISING
24#include <esp_gap_ble_api.h>
25#include <esp_gattc_api.h>
26#include <esp_gatts_api.h>
33static constexpr uint8_t MAX_BLE_QUEUE_SIZE = 100;
35static constexpr uint8_t MAX_BLE_QUEUE_SIZE = 88;
55#ifdef ESPHOME_ESP32_BLE_EXTENDED_AUTH_PARAMS
83 virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) = 0;
91#ifdef USE_ESP32_BLE_CLIENT
95 esp_ble_gattc_cb_param_t *param) = 0;
99#ifdef USE_ESP32_BLE_SERVER
103 esp_ble_gatts_cb_param_t *param) = 0;
116#ifdef ESPHOME_ESP32_BLE_EXTENDED_AUTH_PARAMS
123 this->advertising_cycle_time_ = advertising_cycle_time;
130 void setup()
override;
131 void loop()
override;
134 void set_name(
const char *name) { this->name_ = name; }
136#ifdef USE_ESP32_BLE_ADVERTISING
147#ifdef ESPHOME_ESP32_BLE_GAP_EVENT_HANDLER_COUNT
150#ifdef ESPHOME_ESP32_BLE_GAP_SCAN_EVENT_HANDLER_COUNT
152 this->gap_scan_event_handlers_.push_back(handler);
155#if defined(USE_ESP32_BLE_CLIENT) && defined(ESPHOME_ESP32_BLE_GATTC_EVENT_HANDLER_COUNT)
158#if defined(USE_ESP32_BLE_SERVER) && defined(ESPHOME_ESP32_BLE_GATTS_EVENT_HANDLER_COUNT)
161#ifdef ESPHOME_ESP32_BLE_BLE_STATUS_EVENT_HANDLER_COUNT
163 this->ble_status_event_handlers_.push_back(handler);
169#ifdef USE_ESP32_BLE_SERVER
170 static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
172#ifdef USE_ESP32_BLE_CLIENT
173 static void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
175 static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
184#ifdef USE_ESP32_BLE_ADVERTISING
197#ifdef ESPHOME_ESP32_BLE_GAP_EVENT_HANDLER_COUNT
200#ifdef ESPHOME_ESP32_BLE_GAP_SCAN_EVENT_HANDLER_COUNT
203#if defined(USE_ESP32_BLE_CLIENT) && defined(ESPHOME_ESP32_BLE_GATTC_EVENT_HANDLER_COUNT)
206#if defined(USE_ESP32_BLE_SERVER) && defined(ESPHOME_ESP32_BLE_GATTS_EVENT_HANDLER_COUNT)
209#ifdef ESPHOME_ESP32_BLE_BLE_STATUS_EVENT_HANDLER_COUNT
218#ifdef USE_ESP32_BLE_ADVERTISING
221 const char *name_{
nullptr};
222 esp_ble_io_cap_t io_cap_{ESP_IO_CAP_NONE};
223 uint32_t advertising_cycle_time_{};
226 uint16_t appearance_{0};
230 bool enable_on_boot_{};
232#ifdef ESPHOME_ESP32_BLE_EXTENDED_AUTH_PARAMS
233 optional<esp_ble_auth_req_t> auth_req_mode_;
235 uint8_t max_key_size_{0};
236 uint8_t min_key_size_{0};
250 void play(
const Ts &...
x)
override {
258 void play(
const Ts &...
x)
override {
Base class for all automation conditions.
Minimal static vector - saves memory by avoiding std::vector overhead.
void play(const Ts &...x) override
void play(const Ts &...x) override
bool check(const Ts &...x) override
virtual void ble_before_disabled_event_handler()=0
void advertising_set_manufacturer_data(const std::vector< uint8_t > &data)
void register_gap_event_handler(GAPEventHandler *handler)
void set_enable_on_boot(bool enable_on_boot)
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
void set_auth_req(AuthReqMode req)
void register_gattc_event_handler(GATTcEventHandler *handler)
void register_gap_scan_event_handler(GAPScanEventHandler *handler)
void set_name(const char *name)
static void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
friend void enqueue_ble_event(Args... args)
void __attribute__((noinline)) loop_handle_state_transition_not_active_()
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 set_advertising_cycle_time(uint32_t advertising_cycle_time)
void register_ble_status_event_handler(BLEStatusEventHandler *handler)
void advertising_add_service_uuid(ESPBTUUID uuid)
void dump_config() override
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 register_gatts_event_handler(GATTsEventHandler *handler)
void set_max_key_size(uint8_t key_size)
void advertising_set_service_data(const std::vector< uint8_t > &data)
void set_io_capability(IoCapability io_capability)
void advertising_set_appearance(uint16_t appearance)
float get_setup_priority() const override
void set_min_key_size(uint8_t key_size)
uint32_t get_advertising_cycle_time() const
void advertising_remove_service_uuid(ESPBTUUID uuid)
virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)=0
virtual void gap_scan_event_handler(const BLEScanResult &scan_result)=0
virtual void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)=0
virtual void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)=0
@ 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.
uint64_t ble_addr_to_uint64(const esp_bd_addr_t address)