12static const char *
const TAG =
"esp32_ble_server.descriptor";
14static RAMAllocator<uint8_t> descriptor_allocator{};
19 this->
value_.attr_max_len = max_len;
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];
39 ESP_LOGV(TAG,
"Creating descriptor - %s", uuid_buf);
43 this->permissions_, &this->value_, &control);
45 ESP_LOGE(TAG,
"esp_ble_gatts_add_char_descr failed: %d", err);
58 ESP_LOGE(TAG,
"Size %d too large, must be no bigger than %d",
length, this->
value_.attr_max_len);
66 esp_ble_gatts_cb_param_t *param) {
68 case ESP_GATTS_ADD_CHAR_DESCR_EVT: {
70 this->characteristic_->get_service()->get_handle() == param->add_char_descr.service_handle &&
71 this->characteristic_ == this->characteristic_->get_service()->get_last_created_characteristic()) {
72 this->
handle_ = param->add_char_descr.attr_handle;
77 case ESP_GATTS_WRITE_EVT: {
78 if (this->
handle_ != param->write.handle)
80 if (param->write.len > this->value_.attr_max_len) {
81 ESP_LOGE(TAG,
"Size %d too large, must be no bigger than %d", param->write.len, this->value_.attr_max_len);
84 this->
value_.attr_len = param->write.len;
85 memcpy(this->
value_.attr_value, param->write.value, param->write.len);
87 (*this->
on_write_callback_)(std::span<const uint8_t>(param->write.value, param->write.len),
88 param->write.conn_id);
static ESPBTUUID from_uuid(esp_bt_uuid_t uuid)
Source compatibility with the historical esp32_ble API (esp32 builds only).
esp_bt_uuid_t get_uuid() const
const char * to_str(char *buf) const
Write "0xABCD" / "0xABCDEF01" / the dashed 128-bit form, or "None" for an unset UUID,...
BLEService * get_service()
esp_gatt_perm_t permissions_
std::unique_ptr< std::function< void(std::span< const uint8_t >, uint16_t)> > on_write_callback_
void set_value(std::vector< uint8_t > &&buffer)
void set_value_impl_(const uint8_t *data, size_t length)
void do_create(BLECharacteristic *characteristic)
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
BLEDescriptor(ESPBTUUID uuid, uint16_t max_len=100, bool read=true, bool write=true)
BLECharacteristic * characteristic_