12 : uuid_(uuid), num_handles_(num_handles), inst_id_(inst_id), advertise_(advertise) {}
21 if (chr->get_uuid() == uuid)
31 esp_gatt_perm_t permissions) {
35 esp_gatt_perm_t permissions) {
39 esp_gatt_perm_t permissions) {
43 return characteristic;
49 esp_gatt_srvc_id_t srvc_id;
50 srvc_id.is_primary =
true;
52 srvc_id.id.uuid = this->
uuid_.get_uuid();
54 esp_err_t err = esp_ble_gatts_create_service(server->
get_gatts_if(), &srvc_id, this->num_handles_);
56 ESP_LOGE(TAG,
"esp_ble_gatts_create_service failed: %d", err);
73 esp_err_t err = esp_ble_gatts_delete_service(this->
handle_);
75 ESP_LOGE(TAG,
"esp_ble_gatts_delete_service failed: %d", err);
82 (this->last_created_characteristic_ ==
nullptr || this->last_created_characteristic_->is_created()))
100 esp_err_t err = esp_ble_gatts_start_service(this->
handle_);
102 ESP_LOGE(TAG,
"esp_ble_gatts_start_service failed: %d", err);
118 esp_err_t err = esp_ble_gatts_stop_service(this->
handle_);
120 ESP_LOGE(TAG,
"esp_ble_gatts_stop_service failed: %d", err);
128 if (this->state_ ==
FAILED)
132 failed |= characteristic->is_failed();
136 return this->state_ ==
FAILED;
140 esp_ble_gatts_cb_param_t *param) {
142 case ESP_GATTS_CREATE_EVT: {
144 this->inst_id_ == param->create.service_id.id.inst_id) {
145 this->
handle_ = param->create.service_handle;
152 case ESP_GATTS_DELETE_EVT:
153 if (param->del.service_handle == this->handle_) {
157 case ESP_GATTS_START_EVT: {
158 if (param->start.service_handle == this->handle_) {
163 case ESP_GATTS_STOP_EVT: {
164 if (param->stop.service_handle == this->handle_) {
174 characteristic->gatts_event_handler(event, gatts_if, param);
static ESPBTUUID from_uuid(esp_bt_uuid_t uuid)
Source compatibility with the historical esp32_ble API (esp32 builds only).
static ESPBTUUID from_uint16(uint16_t uuid)
static ESPBTUUID from_raw(const uint8_t *data)
Construct from raw 16-byte little-endian UUID.
void advertising_add_service_uuid(ESPBTUUID uuid)
void advertising_remove_service_uuid(ESPBTUUID uuid)
void do_create(BLEService *service)
esp_gatt_if_t get_gatts_if()
BLEService(ESPBTUUID uuid, uint16_t num_handles, uint8_t inst_id, bool advertise)
uint32_t created_characteristic_count_
void do_create(BLEServer *server)
BLECharacteristic * create_characteristic(const std::string &uuid, esp_gatt_char_prop_t properties, esp_gatt_perm_t permissions=ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE)
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
BLECharacteristic * last_created_characteristic_
bool do_create_characteristics_()
std::vector< BLECharacteristic * > characteristics_
BLECharacteristic * get_characteristic(ESPBTUUID uuid)
ESPHOME_LOG_TAG(TAG, "esp32_ble")