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
  • Loading branch information
jadhavrohit924 committed Mar 21, 2022
1 parent 4522ebe commit 3f33106
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 0 deletions.
15 changes: 15 additions & 0 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 @@ -116,6 +119,18 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_

case DeviceEventType::kCommissioningComplete:
ESP_LOGI(TAG, "Commissioning complete");
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
ESP_LOGI(TAG, "Free heap: %d", esp_get_free_heap_size());
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_nimble_hci_and_controller_deinit();
esp_bt_mem_release(ESP_BT_MODE_BLE);
}
vTaskDelay(100);
ESP_LOGI(TAG, "Free heap after BLE deinit: %d", esp_get_free_heap_size());
#endif
break;

case DeviceEventType::kInterfaceIpAddressChanged:
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
27 changes: 27 additions & 0 deletions examples/bridge-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
*/

#include "DeviceCallbacks.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/cluster-id.h>
Expand All @@ -46,6 +49,30 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
OnSessionEstablished(event);
break;

case DeviceEventType::kCHIPoBLEConnectionEstablished:
ESP_LOGI(TAG, "CHIPoBLE connection established");
break;

case DeviceEventType::kCHIPoBLEConnectionClosed:
ESP_LOGI(TAG, "CHIPoBLE disconnected");
break;

case DeviceEventType::kCommissioningComplete:
ESP_LOGI(TAG, "Commissioning complete");
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
ESP_LOGI(TAG, "Free heap: %d", esp_get_free_heap_size());
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_nimble_hci_and_controller_deinit();
esp_bt_mem_release(ESP_BT_MODE_BLE);
}
vTaskDelay(100);
ESP_LOGI(TAG, "Free heap after BLE deinit: %d", esp_get_free_heap_size());
#endif
break;

case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
Expand Down
6 changes: 6 additions & 0 deletions examples/bridge-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ 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
15 changes: 15 additions & 0 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 @@ -68,6 +71,18 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_

case DeviceEventType::kCommissioningComplete:
ESP_LOGI(TAG, "Commissioning complete");
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
ESP_LOGI(TAG, "Free heap: %d", esp_get_free_heap_size());
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_nimble_hci_and_controller_deinit();
esp_bt_mem_release(ESP_BT_MODE_BLE);
}
vTaskDelay(100);
ESP_LOGI(TAG, "Free heap after BLE deinit: %d", esp_get_free_heap_size());
#endif
break;

case DeviceEventType::kInterfaceIpAddressChanged:
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
27 changes: 27 additions & 0 deletions examples/lock-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
#include "AppConfig.h"
#include "BoltLockManager.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/cluster-id.h>
Expand All @@ -56,6 +59,30 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
OnSessionEstablished(event);
break;

case DeviceEventType::kCHIPoBLEConnectionEstablished:
ESP_LOGI(TAG, "CHIPoBLE connection established");
break;

case DeviceEventType::kCHIPoBLEConnectionClosed:
ESP_LOGI(TAG, "CHIPoBLE disconnected");
break;

case DeviceEventType::kCommissioningComplete:
ESP_LOGI(TAG, "Commissioning complete");
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
ESP_LOGI(TAG, "Free heap: %d", esp_get_free_heap_size());
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_nimble_hci_and_controller_deinit();
esp_bt_mem_release(ESP_BT_MODE_BLE);
}
vTaskDelay(100);
ESP_LOGI(TAG, "Free heap after BLE deinit: %d", esp_get_free_heap_size());
#endif
break;

case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
Expand Down
7 changes: 7 additions & 0 deletions examples/lock-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ 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

menu "PW RPC Debug channel"
Expand Down
28 changes: 28 additions & 0 deletions examples/ota-provider-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
**/
#include "DeviceCallbacks.h"

#include "esp_bt.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "esp_nimble_hci.h"
#include "nimble/nimble_port.h"
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/Dnssd.h>
Expand All @@ -49,6 +52,31 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
case DeviceEventType::kSessionEstablished:
OnSessionEstablished(event);
break;

case DeviceEventType::kCHIPoBLEConnectionEstablished:
ESP_LOGI(TAG, "CHIPoBLE connection established");
break;

case DeviceEventType::kCHIPoBLEConnectionClosed:
ESP_LOGI(TAG, "CHIPoBLE disconnected");
break;

case DeviceEventType::kCommissioningComplete:
ESP_LOGI(TAG, "Commissioning complete");
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
ESP_LOGI(TAG, "Free heap: %d", esp_get_free_heap_size());
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_nimble_hci_and_controller_deinit();
esp_bt_mem_release(ESP_BT_MODE_BLE);
}
vTaskDelay(100);
ESP_LOGI(TAG, "Free heap after BLE deinit: %d", esp_get_free_heap_size());
#endif
break;

case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
Expand Down
5 changes: 5 additions & 0 deletions examples/ota-provider-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ menu "Demo"
default "hello_world.bin"
help
Name of OTA image file which will be added to '/spiffs_image/' and sent to the OTA Requestor.
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
28 changes: 28 additions & 0 deletions examples/ota-requestor-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
**/
#include "DeviceCallbacks.h"

#include "esp_bt.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "esp_nimble_hci.h"
#include "nimble/nimble_port.h"
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/Dnssd.h>
Expand All @@ -49,6 +52,31 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
case DeviceEventType::kSessionEstablished:
OnSessionEstablished(event);
break;

case DeviceEventType::kCHIPoBLEConnectionEstablished:
ESP_LOGI(TAG, "CHIPoBLE connection established");
break;

case DeviceEventType::kCHIPoBLEConnectionClosed:
ESP_LOGI(TAG, "CHIPoBLE disconnected");
break;

case DeviceEventType::kCommissioningComplete:
ESP_LOGI(TAG, "Commissioning complete");
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
ESP_LOGI(TAG, "Free heap: %d", esp_get_free_heap_size());
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_nimble_hci_and_controller_deinit();
esp_bt_mem_release(ESP_BT_MODE_BLE);
}
vTaskDelay(100);
ESP_LOGI(TAG, "Free heap after BLE deinit: %d", esp_get_free_heap_size());
#endif
break;

case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
Expand Down
6 changes: 6 additions & 0 deletions examples/ota-requestor-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
**/
#include "DeviceCallbacks.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/cluster-id.h>
Expand All @@ -52,6 +55,31 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
case DeviceEventType::kSessionEstablished:
OnSessionEstablished(event);
break;

case DeviceEventType::kCHIPoBLEConnectionEstablished:
ESP_LOGI(TAG, "CHIPoBLE connection established");
break;

case DeviceEventType::kCHIPoBLEConnectionClosed:
ESP_LOGI(TAG, "CHIPoBLE disconnected");
break;

case DeviceEventType::kCommissioningComplete:
ESP_LOGI(TAG, "Commissioning complete");
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
ESP_LOGI(TAG, "Free heap: %d", esp_get_free_heap_size());
int ret = nimble_port_stop();
if (ret == 0)
{
nimble_port_deinit();
esp_nimble_hci_and_controller_deinit();
esp_bt_mem_release(ESP_BT_MODE_BLE);
}
vTaskDelay(100);
ESP_LOGI(TAG, "Free heap after BLE deinit: %d", esp_get_free_heap_size());
#endif
break;

case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ 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

menu "PW RPC Debug channel"
Expand Down

0 comments on commit 3f33106

Please sign in to comment.