Skip to content

Commit

Permalink
[ESP32] Added config option to disable and de-init BLE post commissio…
Browse files Browse the repository at this point in the history
…ning (project-chip#16483)

* [ESP32] Added config option to disable and de-init BLE post commissioning

* Fixed pipline failure

* Implemented config option for all-cluster and lighting app

* Address review comment
  • Loading branch information
jadhavrohit924 authored and andrei-menzopol committed Apr 14, 2022
1 parent ac7343f commit 38c5f67
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
25 changes: 23 additions & 2 deletions examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
#include "Globals.h"
#include "LEDWidget.h"
#include "WiFiWidget.h"
#include "esp_bt.h"
#include "esp_check.h"
#include "esp_err.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "esp_nimble_hci.h"
#include "nimble/nimble_port.h"
#include "route_hook/esp_route_hook.h"
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
Expand Down Expand Up @@ -114,9 +117,27 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
ESP_LOGI(TAG, "CHIPoBLE disconnected");
break;

case DeviceEventType::kCommissioningComplete:
case DeviceEventType::kCommissioningComplete: {
ESP_LOGI(TAG, "Commissioning complete");
break;
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_err_t err = esp_nimble_hci_and_controller_deinit();
err += esp_bt_mem_release(ESP_BT_MODE_BLE);
if (err == ESP_OK)
{
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
}
}
else
{
ESP_LOGW(TAG, "nimble_port_stop() failed");
}
#endif
}
break;

case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
Expand Down
5 changes: 5 additions & 0 deletions examples/all-clusters-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ menu "Demo"
help
Each board has a status led, define its pin number.

config DEINIT_BLE_ON_COMMISSIONING_COMPLETE
bool "Disable and DeInit BLE on commissioning complete"
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.
endmenu

menu "PW RPC Debug channel"
Expand Down
25 changes: 23 additions & 2 deletions examples/lighting-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
#include "DeviceCallbacks.h"
#include "LEDWidget.h"

#include "esp_bt.h"
#include "esp_err.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "esp_nimble_hci.h"
#include "nimble/nimble_port.h"
#include "route_hook/esp_route_hook.h"
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
Expand Down Expand Up @@ -66,9 +69,27 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
ESP_LOGI(TAG, "CHIPoBLE disconnected");
break;

case DeviceEventType::kCommissioningComplete:
case DeviceEventType::kCommissioningComplete: {
ESP_LOGI(TAG, "Commissioning complete");
break;
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_err_t err = esp_nimble_hci_and_controller_deinit();
err += esp_bt_mem_release(ESP_BT_MODE_BLE);
if (err == ESP_OK)
{
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
}
}
else
{
ESP_LOGW(TAG, "nimble_port_stop() failed");
}
#endif
}
break;

case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
Expand Down
5 changes: 5 additions & 0 deletions examples/lighting-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ menu "Demo"
default 4 if RENDEZVOUS_MODE_THREAD
default 8 if RENDEZVOUS_MODE_ETHERNET

config DEINIT_BLE_ON_COMMISSIONING_COMPLETE
bool "Disable and DeInit BLE on commissioning complete"
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.
endmenu

0 comments on commit 38c5f67

Please sign in to comment.