From 5021cc6d5ff94af41f10da0ba856b064c113fe03 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 6 Aug 2025 07:24:02 -1000 Subject: [PATCH] [esp32_ble] Make BLE notification limit configurable to fix ESP_GATT_NO_RESOURCES errors (#10098) --- esphome/components/esp32_ble/__init__.py | 15 +++++++++++++++ esphome/components/esp32_ble_tracker/__init__.py | 5 ----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/esphome/components/esp32_ble/__init__.py b/esphome/components/esp32_ble/__init__.py index f208fda34c..bfe8bcf9be 100644 --- a/esphome/components/esp32_ble/__init__.py +++ b/esphome/components/esp32_ble/__init__.py @@ -118,6 +118,7 @@ CONF_IO_CAPABILITY = "io_capability" CONF_ADVERTISING_CYCLE_TIME = "advertising_cycle_time" CONF_DISABLE_BT_LOGS = "disable_bt_logs" CONF_CONNECTION_TIMEOUT = "connection_timeout" +CONF_MAX_NOTIFICATIONS = "max_notifications" NO_BLUETOOTH_VARIANTS = [const.VARIANT_ESP32S2] @@ -173,6 +174,11 @@ CONFIG_SCHEMA = cv.Schema( cv.positive_time_period_seconds, cv.Range(min=TimePeriod(seconds=10), max=TimePeriod(seconds=180)), ), + cv.SplitDefault(CONF_MAX_NOTIFICATIONS, esp32_idf=12): cv.All( + cv.only_with_esp_idf, + cv.positive_int, + cv.Range(min=1, max=64), + ), } ).extend(cv.COMPONENT_SCHEMA) @@ -272,6 +278,15 @@ async def to_code(config): "CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT", timeout_seconds ) + # Set the maximum number of notification registrations + # This controls how many BLE characteristics can have notifications enabled + # across all connections for a single GATT client interface + # https://github.com/esphome/issues/issues/6808 + if CONF_MAX_NOTIFICATIONS in config: + add_idf_sdkconfig_option( + "CONFIG_BT_GATTC_NOTIF_REG_MAX", config[CONF_MAX_NOTIFICATIONS] + ) + cg.add_define("USE_ESP32_BLE") diff --git a/esphome/components/esp32_ble_tracker/__init__.py b/esphome/components/esp32_ble_tracker/__init__.py index e1abdd8490..d03e968e2d 100644 --- a/esphome/components/esp32_ble_tracker/__init__.py +++ b/esphome/components/esp32_ble_tracker/__init__.py @@ -355,11 +355,6 @@ async def to_code(config): add_idf_sdkconfig_option( "CONFIG_BTDM_CTRL_BLE_MAX_CONN", config[CONF_MAX_CONNECTIONS] ) - # CONFIG_BT_GATTC_NOTIF_REG_MAX controls the number of - # max notifications in 5.x, setting CONFIG_BT_ACL_CONNECTIONS - # is enough in 4.x - # https://github.com/esphome/issues/issues/6808 - add_idf_sdkconfig_option("CONFIG_BT_GATTC_NOTIF_REG_MAX", 9) cg.add_define("USE_OTA_STATE_CALLBACK") # To be notified when an OTA update starts cg.add_define("USE_ESP32_BLE_CLIENT")