3 #include "ble_service.h" 4 #include "ble_characteristic.h" 16 #include <unordered_map> 20 #include <esp_gap_ble_api.h> 21 #include <esp_gatts_api.h> 24 namespace esp32_ble_server {
26 using namespace esp32_ble;
38 void setup()
override;
40 void dump_config()
override;
41 float get_setup_priority()
const override;
42 bool can_proceed()
override;
47 void set_manufacturer(
const std::string &manufacturer) { this->manufacturer_ = manufacturer; }
48 void set_model(
const std::string &model) { this->model_ = model; }
50 this->manufacturer_data_ = data;
51 this->restart_advertising_();
54 void create_service(
ESPBTUUID uuid,
bool advertise =
false, uint16_t num_handles = 15, uint8_t inst_id = 0);
60 const std::unordered_map<uint16_t, void *> &
get_clients() {
return this->clients_; }
62 void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
63 esp_ble_gatts_cb_param_t *param)
override;
65 void ble_before_disabled_event_handler()
override;
70 bool create_device_characteristics_();
71 void restart_advertising_();
73 void add_client_(uint16_t conn_id,
void *client) { this->clients_.emplace(conn_id, client); }
74 bool remove_client_(uint16_t conn_id) {
return this->clients_.erase(conn_id) > 0; }
79 esp_gatt_if_t gatts_if_{0};
80 bool registered_{
false};
82 uint32_t connected_clients_{0};
84 std::unordered_map<std::string, BLEService *>
services_;
bool remove_client_(uint16_t conn_id)
const std::unordered_map< uint16_t, void * > & get_clients()
std::unordered_map< uint16_t, void * > clients_
BLEService * device_information_service_
esp_gatt_if_t get_gatts_if()
void set_manufacturer_data(const std::vector< uint8_t > &data)
optional< std::string > model_
void add_client_(uint16_t conn_id, void *client)
std::unordered_map< std::string, BLEService * > services_
std::vector< BLEServiceComponent * > service_components_
virtual void on_client_connect()
BLEServer * global_ble_server
std::string manufacturer_
uint32_t get_connected_client_count()
void register_service_component(BLEServiceComponent *component)
void set_model(const std::string &model)
virtual void on_client_disconnect()
void set_manufacturer(const std::string &manufacturer)
Implementation of SPI Controller mode.
Helper class to easily give an object a parent of type T.
std::vector< uint8_t > manufacturer_data_