1 #include "ble_service.h" 8 namespace esp32_ble_server {
10 static const char *
const TAG =
"esp32_ble_server.service";
13 : uuid_(uuid), num_handles_(num_handles), inst_id_(inst_id), advertise_(advertise) {}
22 if (chr->get_uuid() == uuid)
41 return characteristic;
47 esp_gatt_srvc_id_t srvc_id;
48 srvc_id.is_primary =
true;
54 ESP_LOGE(TAG,
"esp_ble_gatts_create_service failed: %d", err);
55 this->init_state_ =
FAILED;
68 esp_err_t err = esp_ble_gatts_delete_service(this->
handle_);
70 ESP_LOGE(TAG,
"esp_ble_gatts_delete_service failed: %d", err);
94 esp_err_t err = esp_ble_gatts_start_service(this->
handle_);
96 ESP_LOGE(TAG,
"esp_ble_gatts_start_service failed: %d", err);
110 if (this->running_state_ ==
STOPPING || this->running_state_ ==
STOPPED)
113 esp_err_t err = esp_ble_gatts_stop_service(this->
handle_);
115 ESP_LOGE(TAG,
"esp_ble_gatts_stop_service failed: %d", err);
124 if (this->init_state_ ==
FAILED)
128 failed |= characteristic->is_failed();
131 this->init_state_ =
FAILED;
132 return this->init_state_ ==
FAILED;
136 esp_ble_gatts_cb_param_t *param) {
138 case ESP_GATTS_CREATE_EVT: {
140 this->inst_id_ == param->create.service_id.id.inst_id) {
141 this->
handle_ = param->create.service_handle;
148 case ESP_GATTS_DELETE_EVT:
149 if (param->del.service_handle == this->handle_) {
153 case ESP_GATTS_START_EVT: {
154 if (param->start.service_handle == this->handle_) {
155 this->running_state_ =
RUNNING;
159 case ESP_GATTS_STOP_EVT: {
160 if (param->start.service_handle == this->handle_) {
161 this->running_state_ =
STOPPED;
170 characteristic->gatts_event_handler(event, gatts_if, param);
void do_create(BLEService *service)
bool do_create_characteristics_()
BLECharacteristic * last_created_characteristic_
void advertising_remove_service_uuid(ESPBTUUID uuid)
uint32_t created_characteristic_count_
esp_gatt_if_t get_gatts_if()
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
BLEService(ESPBTUUID uuid, uint16_t num_handles, uint8_t inst_id, bool advertise)
static ESPBTUUID from_uuid(esp_bt_uuid_t uuid)
static ESPBTUUID from_uint16(uint16_t uuid)
void do_create(BLEServer *server)
std::vector< BLECharacteristic * > characteristics_
Implementation of SPI Controller mode.
static ESPBTUUID from_raw(const uint8_t *data)
BLECharacteristic * get_characteristic(ESPBTUUID uuid)
BLECharacteristic * create_characteristic(const std::string &uuid, esp_gatt_char_prop_t properties)
void advertising_add_service_uuid(ESPBTUUID uuid)
esp_bt_uuid_t get_uuid() const
enum esphome::esp32_ble_server::BLEService::RunningState STOPPED