diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index 208525d7b8ecd5..57ace57f55bf1f 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -497,11 +497,14 @@ menu "CHIP Device Layer" When set, WoBLE advertisements will stop while a WoBLE connection is active. - config DEINIT_BLE_ON_COMMISSIONING_COMPLETE - bool "Disable and DeInit BLE on commissioning complete" + config USE_BLE_ONLY_FOR_COMMISSIONING + bool "Use BLE only for commissioning" default y help - Disable and deinit BLE and reclaim all its memory, once the commissioning is successful and Commissioning complete event is received in the application. + Disable this flag if BLE is used for any other purpose than commissioning. + When enabled, it deinitialized the BLE on successful commissioning, and on + bootup do not initialize the BLE if device is already provisioned with Wi-Fi/Thread credentials. + endmenu menu "CHIP Thread Options" diff --git a/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 b/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 index dc637d31dc7a2e..57c480716e0abd 100644 --- a/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 +++ b/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 @@ -20,7 +20,7 @@ CONFIG_BT_ENABLED=y CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_EXT_ADV=n CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 -CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n # Enable OpenThread CONFIG_OPENTHREAD_ENABLED=y diff --git a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp index ba9eafc19c1397..754d3ef2e86211 100644 --- a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp +++ b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp @@ -79,7 +79,7 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i case DeviceEventType::kCommissioningComplete: { ESP_LOGI(TAG, "Commissioning complete"); -#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE +#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING if (ble_hs_is_enabled()) { diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp index bd93a100eeaaaf..3caa976d3bb2e6 100644 --- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp +++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp @@ -140,6 +140,21 @@ const struct ble_gatt_svc_def BLEManagerImpl::CHIPoBLEGATTAttrs[] = { CHIP_ERROR BLEManagerImpl::_Init() { +#if CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + if (ConnectivityMgr().IsThreadProvisioned()) + { + ESP_LOGI(TAG, "Thread credentials already provisioned, not initializing BLE"); + return CHIP_NO_ERROR; + } +#else + if (ConnectivityMgr().IsWiFiStationProvisioned()) { + ESP_LOGI(TAG, "WiFi station already provisioned, not initializing BLE"); + return CHIP_NO_ERROR; + } +#endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */ +#endif /* CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */ + CHIP_ERROR err; // Initialize the Chip BleLayer.