33 esp_attr_control_t control;
34 control.auto_rsp = ESP_GATT_AUTO_RSP;
36#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
37 char uuid_buf[esp32_ble::UUID_STR_LEN];
38 this->
uuid_.to_str(uuid_buf);
39 ESP_LOGV(TAG,
"Creating descriptor - %s", uuid_buf);
41 esp_bt_uuid_t uuid = this->
uuid_.get_uuid();
43 this->permissions_, &this->value_, &control);
45 ESP_LOGE(TAG,
"esp_ble_gatts_add_char_descr failed: %d", err);
67 esp_ble_gatts_cb_param_t *param) {
69 case ESP_GATTS_ADD_CHAR_DESCR_EVT: {
71 this->characteristic_->get_service()->get_handle() == param->add_char_descr.service_handle &&
72 this->characteristic_ == this->characteristic_->get_service()->get_last_created_characteristic()) {
73 this->
handle_ = param->add_char_descr.attr_handle;
78 case ESP_GATTS_WRITE_EVT: {
79 if (this->
handle_ != param->write.handle)
81 if (param->write.len > this->value_.attr_max_len) {
82 ESP_LOGE(TAG,
"Size %d too large, must be no bigger than %d", param->write.len, this->value_.attr_max_len);
85 this->
value_.attr_len = param->write.len;
86 memcpy(this->
value_.attr_value, param->write.value, param->write.len);
88 (*this->
on_write_callback_)(std::span<const uint8_t>(param->write.value, param->write.len),
89 param->write.conn_id);