ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
bluetooth_connection.cpp
Go to the documentation of this file.
2
5#include "esphome/core/log.h"
6
7#ifdef USE_ESP32
8
9#include "bluetooth_proxy.h"
10
12
13static const char *const TAG = "bluetooth_proxy.connection";
14
15// This function is allocation-free and directly packs UUIDs into the output array
16// using precalculated constants for the Bluetooth base UUID
17static void fill_128bit_uuid_array(std::array<uint64_t, 2> &out, esp_bt_uuid_t uuid_source) {
18 // Bluetooth base UUID: 00000000-0000-1000-8000-00805F9B34FB
19 // out[0] = bytes 8-15 (big-endian)
20 // - For 128-bit UUIDs: use bytes 8-15 as-is
21 // - For 16/32-bit UUIDs: insert into bytes 12-15, use 0x00001000 for bytes 8-11
22 out[0] = uuid_source.len == ESP_UUID_LEN_128
23 ? (((uint64_t) uuid_source.uuid.uuid128[15] << 56) | ((uint64_t) uuid_source.uuid.uuid128[14] << 48) |
24 ((uint64_t) uuid_source.uuid.uuid128[13] << 40) | ((uint64_t) uuid_source.uuid.uuid128[12] << 32) |
25 ((uint64_t) uuid_source.uuid.uuid128[11] << 24) | ((uint64_t) uuid_source.uuid.uuid128[10] << 16) |
26 ((uint64_t) uuid_source.uuid.uuid128[9] << 8) | ((uint64_t) uuid_source.uuid.uuid128[8]))
27 : (((uint64_t) (uuid_source.len == ESP_UUID_LEN_16 ? uuid_source.uuid.uuid16 : uuid_source.uuid.uuid32)
28 << 32) |
29 0x00001000ULL); // Base UUID bytes 8-11
30 // out[1] = bytes 0-7 (big-endian)
31 // - For 128-bit UUIDs: use bytes 0-7 as-is
32 // - For 16/32-bit UUIDs: use precalculated base UUID constant
33 out[1] = uuid_source.len == ESP_UUID_LEN_128
34 ? ((uint64_t) uuid_source.uuid.uuid128[7] << 56) | ((uint64_t) uuid_source.uuid.uuid128[6] << 48) |
35 ((uint64_t) uuid_source.uuid.uuid128[5] << 40) | ((uint64_t) uuid_source.uuid.uuid128[4] << 32) |
36 ((uint64_t) uuid_source.uuid.uuid128[3] << 24) | ((uint64_t) uuid_source.uuid.uuid128[2] << 16) |
37 ((uint64_t) uuid_source.uuid.uuid128[1] << 8) | ((uint64_t) uuid_source.uuid.uuid128[0])
38 : 0x800000805F9B34FBULL; // Base UUID bytes 0-7: 80-00-00-80-5F-9B-34-FB
39}
40
41// Helper to fill UUID in the appropriate format based on client support and UUID type
42static void fill_gatt_uuid(std::array<uint64_t, 2> &uuid_128, uint32_t &short_uuid, const esp_bt_uuid_t &uuid,
43 bool use_efficient_uuids) {
44 if (!use_efficient_uuids || uuid.len == ESP_UUID_LEN_128) {
45 // Use 128-bit format for old clients or when UUID is already 128-bit
46 fill_128bit_uuid_array(uuid_128, uuid);
47 } else if (uuid.len == ESP_UUID_LEN_16) {
48 short_uuid = uuid.uuid.uuid16;
49 } else if (uuid.len == ESP_UUID_LEN_32) {
50 short_uuid = uuid.uuid.uuid32;
51 }
52}
53
54// Constants for size estimation
55static constexpr uint8_t SERVICE_OVERHEAD_LEGACY = 25; // UUID(20) + handle(4) + overhead(1)
56static constexpr uint8_t SERVICE_OVERHEAD_EFFICIENT = 10; // UUID(6) + handle(4)
57static constexpr uint8_t CHAR_SIZE_128BIT = 35; // UUID(20) + handle(4) + props(4) + overhead(7)
58static constexpr uint8_t DESC_SIZE_128BIT = 25; // UUID(20) + handle(4) + overhead(1)
59static constexpr uint8_t DESC_SIZE_16BIT = 10; // UUID(6) + handle(4)
60static constexpr uint8_t DESC_PER_CHAR = 1; // Assume 1 descriptor per characteristic
61
62// Helper to estimate service size before fetching all data
75static size_t estimate_service_size(uint16_t char_count, bool use_efficient_uuids) {
76 size_t service_overhead = use_efficient_uuids ? SERVICE_OVERHEAD_EFFICIENT : SERVICE_OVERHEAD_LEGACY;
77 // Always assume 128-bit UUIDs for characteristics to be safe
78 size_t char_size = CHAR_SIZE_128BIT;
79 // Assume one 128-bit descriptor per characteristic
80 size_t desc_size = DESC_SIZE_128BIT * DESC_PER_CHAR;
81
82 return service_overhead + (char_size + desc_size) * char_count;
83}
84
86 auto *api_conn = this->proxy_->get_api_connection();
87 return api_conn && api_conn->client_supports_api_version(1, 12);
88}
89
91 ESP_LOGCONFIG(TAG, "BLE Connection:");
93}
94
95void BluetoothConnection::update_allocated_slot_(uint64_t find_value, uint64_t set_value) {
96 auto &allocated = this->proxy_->connections_free_response_.allocated;
97 for (auto &slot : allocated) {
98 if (slot == find_value) {
99 slot = set_value;
100 return;
101 }
102 }
103}
104
106 // If we're clearing an address (disconnecting), update the pre-allocated message
107 if (address == 0 && this->address_ != 0) {
109 this->update_allocated_slot_(this->address_, 0);
110 }
111 // If we're setting a new address (connecting), update the pre-allocated message
112 else if (address != 0 && this->address_ == 0) {
114 this->update_allocated_slot_(0, address);
115 }
116
117 // Call parent implementation to actually set the address
119}
120
123
124 // Early return if no active connection
125 if (this->address_ == 0) {
126 return;
127 }
128
129 // Handle service discovery if in valid range
132 }
133
134 // Check if we should disable the loop
135 // - For V3_WITH_CACHE: Services are never sent, disable after INIT state
136 // - For other connections: Disable only after service discovery is complete
137 // (send_service_ == DONE_SENDING_SERVICES, which is only set after services are sent)
138 if (this->state_ != espbt::ClientState::INIT && (this->connection_type_ == espbt::ConnectionType::V3_WITH_CACHE ||
139 this->send_service_ == DONE_SENDING_SERVICES)) {
140 this->disable_loop();
141 }
142}
143
145 // Send disconnection notification
146 this->proxy_->send_device_connection(this->address_, false, 0, reason);
147
148 // Important: If we were in the middle of sending services, we do NOT send
149 // send_gatt_services_done() here. This ensures the client knows that
150 // the service discovery was interrupted and can retry. The client
151 // (aioesphomeapi) implements a 30-second timeout (DEFAULT_BLE_TIMEOUT)
152 // to detect incomplete service discovery rather than relying on us to
153 // tell them about a partial list.
154 this->set_address(0);
155 this->send_service_ = INIT_SENDING_SERVICES;
157}
158
160 if (this->send_service_ >= this->service_count_) {
161 this->send_service_ = DONE_SENDING_SERVICES;
163 if (this->connection_type_ == espbt::ConnectionType::V3_WITH_CACHE ||
164 this->connection_type_ == espbt::ConnectionType::V3_WITHOUT_CACHE) {
165 this->release_services();
166 }
167 return;
168 }
169
170 // Early return if no API connection
171 auto *api_conn = this->proxy_->get_api_connection();
172 if (api_conn == nullptr) {
173 this->send_service_ = DONE_SENDING_SERVICES;
174 return;
175 }
176
177 // Check if client supports efficient UUIDs
178 bool use_efficient_uuids = this->supports_efficient_uuids_();
179
180 // Prepare response
182 resp.address = this->address_;
183
184 // Dynamic batching based on actual size
185 // Conservative MTU limit for API messages (accounts for WPA3 overhead)
186 static constexpr size_t MAX_PACKET_SIZE = 1360;
187
188 // Keep running total of actual message size
189 size_t current_size = 0;
190 api::ProtoSize size;
191 resp.calculate_size(size);
192 current_size = size.get_size();
193
195 esp_gattc_service_elem_t service_result;
196 uint16_t service_count = 1;
197 esp_gatt_status_t service_status = esp_ble_gattc_get_service(this->gattc_if_, this->conn_id_, nullptr,
198 &service_result, &service_count, this->send_service_);
199
200 if (service_status != ESP_GATT_OK || service_count == 0) {
201 ESP_LOGE(TAG, "[%d] [%s] esp_ble_gattc_get_service %s, status=%d, service_count=%d, offset=%d",
202 this->connection_index_, this->address_str().c_str(),
203 service_status != ESP_GATT_OK ? "error" : "missing", service_status, service_count, this->send_service_);
204 this->send_service_ = DONE_SENDING_SERVICES;
205 return;
206 }
207
208 // Get the number of characteristics BEFORE adding to response
209 uint16_t total_char_count = 0;
210 esp_gatt_status_t char_count_status =
211 esp_ble_gattc_get_attr_count(this->gattc_if_, this->conn_id_, ESP_GATT_DB_CHARACTERISTIC,
212 service_result.start_handle, service_result.end_handle, 0, &total_char_count);
213
214 if (char_count_status != ESP_GATT_OK) {
215 this->log_connection_error_("esp_ble_gattc_get_attr_count", char_count_status);
216 this->send_service_ = DONE_SENDING_SERVICES;
217 return;
218 }
219
220 // If this service likely won't fit, send current batch (unless it's the first)
221 size_t estimated_size = estimate_service_size(total_char_count, use_efficient_uuids);
222 if (!resp.services.empty() && (current_size + estimated_size > MAX_PACKET_SIZE)) {
223 // This service likely won't fit, send current batch
224 break;
225 }
226
227 // Now add the service since we know it will likely fit
228 resp.services.emplace_back();
229 auto &service_resp = resp.services.back();
230
231 fill_gatt_uuid(service_resp.uuid, service_resp.short_uuid, service_result.uuid, use_efficient_uuids);
232
233 service_resp.handle = service_result.start_handle;
234
235 if (total_char_count > 0) {
236 // Reserve space and process characteristics
237 service_resp.characteristics.reserve(total_char_count);
238 uint16_t char_offset = 0;
239 esp_gattc_char_elem_t char_result;
240 while (true) { // characteristics
241 uint16_t char_count = 1;
242 esp_gatt_status_t char_status =
243 esp_ble_gattc_get_all_char(this->gattc_if_, this->conn_id_, service_result.start_handle,
244 service_result.end_handle, &char_result, &char_count, char_offset);
245 if (char_status == ESP_GATT_INVALID_OFFSET || char_status == ESP_GATT_NOT_FOUND) {
246 break;
247 }
248 if (char_status != ESP_GATT_OK) {
249 this->log_connection_error_("esp_ble_gattc_get_all_char", char_status);
250 this->send_service_ = DONE_SENDING_SERVICES;
251 return;
252 }
253 if (char_count == 0) {
254 break;
255 }
256
257 service_resp.characteristics.emplace_back();
258 auto &characteristic_resp = service_resp.characteristics.back();
259
260 fill_gatt_uuid(characteristic_resp.uuid, characteristic_resp.short_uuid, char_result.uuid, use_efficient_uuids);
261
262 characteristic_resp.handle = char_result.char_handle;
263 characteristic_resp.properties = char_result.properties;
264 char_offset++;
265
266 // Get the number of descriptors directly with one call
267 uint16_t total_desc_count = 0;
268 esp_gatt_status_t desc_count_status = esp_ble_gattc_get_attr_count(
269 this->gattc_if_, this->conn_id_, ESP_GATT_DB_DESCRIPTOR, 0, 0, char_result.char_handle, &total_desc_count);
270
271 if (desc_count_status != ESP_GATT_OK) {
272 this->log_connection_error_("esp_ble_gattc_get_attr_count", desc_count_status);
273 this->send_service_ = DONE_SENDING_SERVICES;
274 return;
275 }
276 if (total_desc_count == 0) {
277 // No descriptors, continue to next characteristic
278 continue;
279 }
280
281 // Reserve space and process descriptors
282 characteristic_resp.descriptors.reserve(total_desc_count);
283 uint16_t desc_offset = 0;
284 esp_gattc_descr_elem_t desc_result;
285 while (true) { // descriptors
286 uint16_t desc_count = 1;
287 esp_gatt_status_t desc_status = esp_ble_gattc_get_all_descr(
288 this->gattc_if_, this->conn_id_, char_result.char_handle, &desc_result, &desc_count, desc_offset);
289 if (desc_status == ESP_GATT_INVALID_OFFSET || desc_status == ESP_GATT_NOT_FOUND) {
290 break;
291 }
292 if (desc_status != ESP_GATT_OK) {
293 this->log_connection_error_("esp_ble_gattc_get_all_descr", desc_status);
294 this->send_service_ = DONE_SENDING_SERVICES;
295 return;
296 }
297 if (desc_count == 0) {
298 break; // No more descriptors
299 }
300
301 characteristic_resp.descriptors.emplace_back();
302 auto &descriptor_resp = characteristic_resp.descriptors.back();
303
304 fill_gatt_uuid(descriptor_resp.uuid, descriptor_resp.short_uuid, desc_result.uuid, use_efficient_uuids);
305
306 descriptor_resp.handle = desc_result.handle;
307 desc_offset++;
308 }
309 }
310 } // end if (total_char_count > 0)
311
312 // Calculate the actual size of just this service
313 api::ProtoSize service_sizer;
314 service_resp.calculate_size(service_sizer);
315 size_t service_size = service_sizer.get_size() + 1; // +1 for field tag
316
317 // Check if adding this service would exceed the limit
318 if (current_size + service_size > MAX_PACKET_SIZE) {
319 // We would go over - pop the last service if we have more than one
320 if (resp.services.size() > 1) {
321 resp.services.pop_back();
322 ESP_LOGD(TAG, "[%d] [%s] Service %d would exceed limit (current: %d + service: %d > %d), sending current batch",
323 this->connection_index_, this->address_str().c_str(), this->send_service_, current_size, service_size,
324 MAX_PACKET_SIZE);
325 // Don't increment send_service_ - we'll retry this service in next batch
326 } else {
327 // This single service is too large, but we have to send it anyway
328 ESP_LOGV(TAG, "[%d] [%s] Service %d is too large (%d bytes) but sending anyway", this->connection_index_,
329 this->address_str().c_str(), this->send_service_, service_size);
330 // Increment so we don't get stuck
331 this->send_service_++;
332 }
333 // Send what we have
334 break;
335 }
336
337 // Now we know we're keeping this service, add its size
338 current_size += service_size;
339 // Successfully added this service, increment counter
340 this->send_service_++;
341 }
342
343 // Send the message with dynamically batched services
344 api_conn->send_message(resp, api::BluetoothGATTGetServicesResponse::MESSAGE_TYPE);
345}
346
347void BluetoothConnection::log_connection_error_(const char *operation, esp_gatt_status_t status) {
348 ESP_LOGE(TAG, "[%d] [%s] %s error, status=%d", this->connection_index_, this->address_str().c_str(), operation,
349 status);
350}
351
352void BluetoothConnection::log_connection_warning_(const char *operation, esp_err_t err) {
353 ESP_LOGW(TAG, "[%d] [%s] %s failed, err=%d", this->connection_index_, this->address_str().c_str(), operation, err);
354}
355
356void BluetoothConnection::log_gatt_not_connected_(const char *action, const char *type) {
357 ESP_LOGW(TAG, "[%d] [%s] Cannot %s GATT %s, not connected.", this->connection_index_, this->address_str().c_str(),
358 action, type);
359}
360
361void BluetoothConnection::log_gatt_operation_error_(const char *operation, uint16_t handle, esp_gatt_status_t status) {
362 ESP_LOGW(TAG, "[%d] [%s] Error %s for handle 0x%2X, status=%d", this->connection_index_, this->address_str().c_str(),
363 operation, handle, status);
364}
365
366esp_err_t BluetoothConnection::check_and_log_error_(const char *operation, esp_err_t err) {
367 if (err != ESP_OK) {
368 this->log_connection_warning_(operation, err);
369 return err;
370 }
371 return ESP_OK;
372}
373
374bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
375 esp_ble_gattc_cb_param_t *param) {
376 if (!BLEClientBase::gattc_event_handler(event, gattc_if, param))
377 return false;
378
379 switch (event) {
380 case ESP_GATTC_DISCONNECT_EVT: {
381 this->reset_connection_(param->disconnect.reason);
382 break;
383 }
384 case ESP_GATTC_CLOSE_EVT: {
385 this->reset_connection_(param->close.reason);
386 break;
387 }
388 case ESP_GATTC_OPEN_EVT: {
389 if (param->open.status != ESP_GATT_OK && param->open.status != ESP_GATT_ALREADY_OPEN) {
390 this->reset_connection_(param->open.status);
391 } else if (this->connection_type_ == espbt::ConnectionType::V3_WITH_CACHE) {
392 this->proxy_->send_device_connection(this->address_, true, this->mtu_);
394 }
395 this->seen_mtu_or_services_ = false;
396 break;
397 }
398 case ESP_GATTC_CFG_MTU_EVT:
399 case ESP_GATTC_SEARCH_CMPL_EVT: {
400 if (!this->seen_mtu_or_services_) {
401 // We don't know if we will get the MTU or the services first, so
402 // only send the device connection true if we have already received
403 // the services.
404 this->seen_mtu_or_services_ = true;
405 break;
406 }
407 this->proxy_->send_device_connection(this->address_, true, this->mtu_);
409 break;
410 }
411 case ESP_GATTC_READ_DESCR_EVT:
412 case ESP_GATTC_READ_CHAR_EVT: {
413 if (param->read.status != ESP_GATT_OK) {
414 this->log_gatt_operation_error_("reading char/descriptor", param->read.handle, param->read.status);
415 this->proxy_->send_gatt_error(this->address_, param->read.handle, param->read.status);
416 break;
417 }
419 resp.address = this->address_;
420 resp.handle = param->read.handle;
421 resp.set_data(param->read.value, param->read.value_len);
423 break;
424 }
425 case ESP_GATTC_WRITE_CHAR_EVT:
426 case ESP_GATTC_WRITE_DESCR_EVT: {
427 if (param->write.status != ESP_GATT_OK) {
428 this->log_gatt_operation_error_("writing char/descriptor", param->write.handle, param->write.status);
429 this->proxy_->send_gatt_error(this->address_, param->write.handle, param->write.status);
430 break;
431 }
433 resp.address = this->address_;
434 resp.handle = param->write.handle;
436 break;
437 }
438 case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: {
439 if (param->unreg_for_notify.status != ESP_GATT_OK) {
440 this->log_gatt_operation_error_("unregistering notifications", param->unreg_for_notify.handle,
441 param->unreg_for_notify.status);
442 this->proxy_->send_gatt_error(this->address_, param->unreg_for_notify.handle, param->unreg_for_notify.status);
443 break;
444 }
446 resp.address = this->address_;
447 resp.handle = param->unreg_for_notify.handle;
449 break;
450 }
451 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
452 if (param->reg_for_notify.status != ESP_GATT_OK) {
453 this->log_gatt_operation_error_("registering notifications", param->reg_for_notify.handle,
454 param->reg_for_notify.status);
455 this->proxy_->send_gatt_error(this->address_, param->reg_for_notify.handle, param->reg_for_notify.status);
456 break;
457 }
459 resp.address = this->address_;
460 resp.handle = param->reg_for_notify.handle;
462 break;
463 }
464 case ESP_GATTC_NOTIFY_EVT: {
465 ESP_LOGV(TAG, "[%d] [%s] ESP_GATTC_NOTIFY_EVT: handle=0x%2X", this->connection_index_, this->address_str_.c_str(),
466 param->notify.handle);
468 resp.address = this->address_;
469 resp.handle = param->notify.handle;
470 resp.set_data(param->notify.value, param->notify.value_len);
472 break;
473 }
474 default:
475 break;
476 }
477 return true;
478}
479
480void BluetoothConnection::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
482
483 switch (event) {
484 case ESP_GAP_BLE_AUTH_CMPL_EVT:
485 if (memcmp(param->ble_security.auth_cmpl.bd_addr, this->remote_bda_, 6) != 0)
486 break;
487 if (param->ble_security.auth_cmpl.success) {
488 this->proxy_->send_device_pairing(this->address_, true);
489 } else {
490 this->proxy_->send_device_pairing(this->address_, false, param->ble_security.auth_cmpl.fail_reason);
491 }
492 break;
493 default:
494 break;
495 }
496}
497
499 if (!this->connected()) {
500 this->log_gatt_not_connected_("read", "characteristic");
501 return ESP_GATT_NOT_CONNECTED;
502 }
503
504 ESP_LOGV(TAG, "[%d] [%s] Reading GATT characteristic handle %d", this->connection_index_, this->address_str_.c_str(),
505 handle);
506
507 esp_err_t err = esp_ble_gattc_read_char(this->gattc_if_, this->conn_id_, handle, ESP_GATT_AUTH_REQ_NONE);
508 return this->check_and_log_error_("esp_ble_gattc_read_char", err);
509}
510
511esp_err_t BluetoothConnection::write_characteristic(uint16_t handle, const std::string &data, bool response) {
512 if (!this->connected()) {
513 this->log_gatt_not_connected_("write", "characteristic");
514 return ESP_GATT_NOT_CONNECTED;
515 }
516 ESP_LOGV(TAG, "[%d] [%s] Writing GATT characteristic handle %d", this->connection_index_, this->address_str_.c_str(),
517 handle);
518
519 esp_err_t err =
520 esp_ble_gattc_write_char(this->gattc_if_, this->conn_id_, handle, data.size(), (uint8_t *) data.data(),
521 response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
522 return this->check_and_log_error_("esp_ble_gattc_write_char", err);
523}
524
525esp_err_t BluetoothConnection::read_descriptor(uint16_t handle) {
526 if (!this->connected()) {
527 this->log_gatt_not_connected_("read", "descriptor");
528 return ESP_GATT_NOT_CONNECTED;
529 }
530 ESP_LOGV(TAG, "[%d] [%s] Reading GATT descriptor handle %d", this->connection_index_, this->address_str_.c_str(),
531 handle);
532
533 esp_err_t err = esp_ble_gattc_read_char_descr(this->gattc_if_, this->conn_id_, handle, ESP_GATT_AUTH_REQ_NONE);
534 return this->check_and_log_error_("esp_ble_gattc_read_char_descr", err);
535}
536
537esp_err_t BluetoothConnection::write_descriptor(uint16_t handle, const std::string &data, bool response) {
538 if (!this->connected()) {
539 this->log_gatt_not_connected_("write", "descriptor");
540 return ESP_GATT_NOT_CONNECTED;
541 }
542 ESP_LOGV(TAG, "[%d] [%s] Writing GATT descriptor handle %d", this->connection_index_, this->address_str_.c_str(),
543 handle);
544
545 esp_err_t err = esp_ble_gattc_write_char_descr(
546 this->gattc_if_, this->conn_id_, handle, data.size(), (uint8_t *) data.data(),
547 response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
548 return this->check_and_log_error_("esp_ble_gattc_write_char_descr", err);
549}
550
551esp_err_t BluetoothConnection::notify_characteristic(uint16_t handle, bool enable) {
552 if (!this->connected()) {
553 this->log_gatt_not_connected_("notify", "characteristic");
554 return ESP_GATT_NOT_CONNECTED;
555 }
556
557 if (enable) {
558 ESP_LOGV(TAG, "[%d] [%s] Registering for GATT characteristic notifications handle %d", this->connection_index_,
559 this->address_str_.c_str(), handle);
560 esp_err_t err = esp_ble_gattc_register_for_notify(this->gattc_if_, this->remote_bda_, handle);
561 return this->check_and_log_error_("esp_ble_gattc_register_for_notify", err);
562 }
563
564 ESP_LOGV(TAG, "[%d] [%s] Unregistering for GATT characteristic notifications handle %d", this->connection_index_,
565 this->address_str_.c_str(), handle);
566 esp_err_t err = esp_ble_gattc_unregister_for_notify(this->gattc_if_, this->remote_bda_, handle);
567 return this->check_and_log_error_("esp_ble_gattc_unregister_for_notify", err);
568}
569
573
574} // namespace esphome::bluetooth_proxy
575
576#endif // USE_ESP32
uint8_t address
Definition bl0906.h:4
uint8_t status
Definition bl0942.h:8
void disable_loop()
Disable this component's loop.
bool client_supports_api_version(uint16_t major, uint16_t minor) const
bool send_message(const ProtoMessage &msg, uint8_t message_type)
std::array< uint64_t, BLUETOOTH_PROXY_MAX_CONNECTIONS > allocated
Definition api_pb2.h:2086
void calculate_size(ProtoSize &size) const override
Definition api_pb2.cpp:1960
std::vector< BluetoothGATTService > services
Definition api_pb2.h:1907
void set_data(const uint8_t *data, size_t len)
Definition api_pb2.h:2052
static constexpr uint8_t MESSAGE_TYPE
Definition api_pb2.h:2132
static constexpr uint8_t MESSAGE_TYPE
Definition api_pb2.h:1950
void set_data(const uint8_t *data, size_t len)
Definition api_pb2.h:1959
static constexpr uint8_t MESSAGE_TYPE
Definition api_pb2.h:2115
uint32_t get_size() const
Definition proto.h:387
void log_connection_error_(const char *operation, esp_gatt_status_t status)
void log_gatt_operation_error_(const char *operation, uint16_t handle, esp_gatt_status_t status)
esp32_ble_tracker::AdvertisementParserType get_advertisement_parser_type() override
esp_err_t write_descriptor(uint16_t handle, const std::string &data, bool response)
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
void log_connection_warning_(const char *operation, esp_err_t err)
esp_err_t write_characteristic(uint16_t handle, const std::string &data, bool response)
esp_err_t check_and_log_error_(const char *operation, esp_err_t err)
esp_err_t notify_characteristic(uint16_t handle, bool enable)
void log_gatt_not_connected_(const char *action, const char *type)
void update_allocated_slot_(uint64_t find_value, uint64_t set_value)
esp32_ble_tracker::AdvertisementParserType get_advertisement_parser_type() override
void send_device_connection(uint64_t address, bool connected, uint16_t mtu=0, esp_err_t error=ESP_OK)
void send_device_pairing(uint64_t address, bool paired, esp_err_t error=ESP_OK)
void send_gatt_error(uint64_t address, uint16_t handle, esp_err_t error)
api::BluetoothConnectionsFreeResponse connections_free_response_
const std::string & address_str() const
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
virtual void set_address(uint64_t address)
bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
uint8_t type