From ac112a32c998d4cd84144d7bce58bb0d1040b43d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 27 Nov 2022 14:39:35 -1000 Subject: [PATCH] Add logging for BLE connection slots (#4098) --- .../components/bluetooth_proxy/bluetooth_proxy.cpp | 14 ++++++++++++++ .../components/bluetooth_proxy/bluetooth_proxy.h | 10 +--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp index 834901fbdc..eead2a8aea 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +++ b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp @@ -52,6 +52,20 @@ void BluetoothProxy::dump_config() { ESP_LOGCONFIG(TAG, " Active: %s", YESNO(this->active_)); } +int BluetoothProxy::get_bluetooth_connections_free() { + int free = 0; + for (auto *connection : this->connections_) { + if (connection->address_ == 0) { + free++; + ESP_LOGV(TAG, "[%d] Free connection", connection->get_connection_index()); + } else { + ESP_LOGV(TAG, "[%d] Used connection by [%s]", connection->get_connection_index(), + connection->address_str().c_str()); + } + } + return free; +} + void BluetoothProxy::loop() { if (!api::global_api_server->is_connected()) { for (auto *connection : this->connections_) { diff --git a/esphome/components/bluetooth_proxy/bluetooth_proxy.h b/esphome/components/bluetooth_proxy/bluetooth_proxy.h index b33e084b70..b1353b13da 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_proxy.h +++ b/esphome/components/bluetooth_proxy/bluetooth_proxy.h @@ -41,15 +41,7 @@ class BluetoothProxy : public esp32_ble_tracker::ESPBTDeviceListener, public Com void bluetooth_gatt_send_services(const api::BluetoothGATTGetServicesRequest &msg); void bluetooth_gatt_notify(const api::BluetoothGATTNotifyRequest &msg); - int get_bluetooth_connections_free() { - int free = 0; - for (auto *connection : this->connections_) { - if (connection->address_ == 0) { - free++; - } - } - return free; - } + int get_bluetooth_connections_free(); int get_bluetooth_connections_limit() { return this->connections_.size(); } void set_active(bool active) { this->active_ = active; }