Skip to content

Commit

Permalink
[ESP32]: Do not initialize BLE if wifi/thread is already provisioned.
Browse files Browse the repository at this point in the history
If ble is only used for commissioning then there is no use to initialize
the ble.
Also, renamed the config option for the purpose to make it more aligned.
  • Loading branch information
shubhamdp committed Sep 30, 2022
1 parent cd34049 commit 91bd264
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
9 changes: 6 additions & 3 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/esp32/sdkconfig.defaults.esp32h2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/esp32/common/CommonDeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
15 changes: 15 additions & 0 deletions src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 91bd264

Please sign in to comment.