Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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