14#include <unordered_map>
19#include <esp_gatts_api.h>
23using namespace esp32_ble;
24using namespace bytebuffer;
28 void setup()
override;
62 void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
66#ifdef USE_ESP32_BLE_SERVER_SECURITY
67 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
70#ifdef USE_ESP32_BLE_SERVER_STATIC_PASSKEY
81 void on_connect(std::function<
void(uint16_t)> &&callback) {
87#ifdef USE_ESP32_BLE_SERVER_ON_PASSKEY_REQUEST
92#ifdef USE_ESP32_BLE_SERVER_ON_PASSKEY_NOTIFICATION
97#ifdef USE_ESP32_BLE_SERVER_ON_NUMERIC_COMPARISON_REQUEST
125 void add_client_(
const esp_ble_gatts_cb_param_t::gatts_connect_evt_param &connect);
126#ifdef USE_ESP32_BLE_SERVER_SECURITY
133#ifdef USE_ESP32_BLE_SERVER_ON_PASSKEY_REQUEST
136#ifdef USE_ESP32_BLE_SERVER_ON_PASSKEY_NOTIFICATION
139#ifdef USE_ESP32_BLE_SERVER_ON_NUMERIC_COMPARISON_REQUEST
143#ifdef USE_ESP32_BLE_SERVER_STATIC_PASSKEY
149#ifdef USE_ESP32_BLE_SERVER_SECURITY
155 uint16_t
clients_[USE_ESP32_BLE_MAX_CONNECTIONS]{};
156#ifdef USE_ESP32_BLE_SERVER_SECURITY
Helper class to easily give an object a parent of type T.
void set_advertising_required(bool required)
Whether this server needs the device to advertise so clients can find and connect to it.
std::vector< CallbackEntry > callbacks_
esp_gatt_if_t get_gatts_if()
void add_client_(const esp_ble_gatts_cb_param_t::gatts_connect_evt_param &connect)
CallbackManager< void(uint64_t)> passkey_request_callback_
uint32_t get_connected_client_count()
const uint16_t * get_clients() const
std::vector< uint8_t > manufacturer_data_
esp_bd_addr_t client_addresses_[USE_ESP32_BLE_MAX_CONNECTIONS]
uint8_t get_max_clients() const
void set_device_information_service(BLEService *service)
BLEService * device_information_service_
void set_passkey(uint32_t passkey)
void add_on_numeric_comparison_request_callback(F &&callback)
void set_manufacturer_data(const std::vector< uint8_t > &data)
void remove_client_(uint16_t conn_id)
float get_setup_priority() const override
enum esphome::esp32_ble_server::BLEServer::State INIT
uint8_t get_client_count() const
void dump_config() override
void dispatch_callbacks_(CallbackType type, uint16_t conn_id)
bool advertising_required_
void add_on_passkey_request_callback(F &&callback)
ESPHOME_ALWAYS_INLINE bool is_running()
void release_advertising_()
void set_pairing_enabled(bool pairing_enabled)
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
void add_on_passkey_notification_callback(F &&callback)
bool can_proceed() override
BLEService * get_service(ESPBTUUID uuid, uint8_t inst_id=0)
void passkey_reply(uint64_t address, uint32_t passkey)
Answer a passkey request from the connected client at address.
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
std::vector< BLEService * > services_to_start_
void enqueue_start_service(BLEService *service)
bool is_client_address_(const esp_bd_addr_t address) const
void ble_before_disabled_event_handler()
BLEService * create_service(ESPBTUUID uuid, bool advertise=false, uint16_t num_handles=15)
void remove_service(ESPBTUUID uuid, uint8_t inst_id=0)
std::vector< ServiceEntry > services_
uint16_t clients_[USE_ESP32_BLE_MAX_CONNECTIONS]
void restart_advertising_()
CallbackManager< void(uint64_t, uint32_t)> numeric_comparison_request_callback_
void request_advertising_()
int8_t find_client_index_(uint16_t conn_id) const
void numeric_comparison_reply(uint64_t address, bool accept)
Accept or reject a numeric comparison request from the connected client at address.
void on_connect(std::function< void(uint16_t)> &&callback)
void on_disconnect(std::function< void(uint16_t)> &&callback)
void remove_bond(uint64_t address)
void set_max_clients(uint8_t max_clients)
bool advertising_requested_
CallbackManager< void(uint64_t, uint32_t)> passkey_notification_callback_
BLEServer * global_ble_server
std::function< void(uint16_t)> callback