mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
app_ble: Add support to disable BLE
examples: Disabled BLE once commissioning is complete.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS app_ble.cpp
|
||||
INCLUDE_DIRS .
|
||||
REQUIRES bt)
|
||||
@@ -0,0 +1,8 @@
|
||||
menu "App BLE"
|
||||
|
||||
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,0 +1,45 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
/* It is recommended to copy this code in your example so that you can modify as per your application's needs,
|
||||
* especially for the indicator calbacks, button_factory_reset_pressed_cb() and button_factory_reset_released_cb().
|
||||
*/
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <esp_bt.h>
|
||||
#include <esp_nimble_hci.h>
|
||||
#include <host/ble_hs.h>
|
||||
#include <nimble/nimble_port.h>
|
||||
|
||||
static const char *TAG = "app_ble";
|
||||
|
||||
esp_err_t app_ble_disable()
|
||||
{
|
||||
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE
|
||||
if (!ble_hs_is_enabled()) {
|
||||
ESP_LOGI(TAG, "BLE already deinited");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int ret = nimble_port_stop();
|
||||
if (ret != 0) {
|
||||
ESP_LOGE(TAG, "nimble_port_stop() failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
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_LOGE(TAG, "BLE deinit failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/** Disable BLE
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t app_ble_disable();
|
||||
@@ -1,4 +1,4 @@
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota)
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_ble app_qrcode app_reset esp_matter_ota)
|
||||
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <esp_matter_ota.h>
|
||||
#include <esp_route_hook.h>
|
||||
|
||||
#include <app_ble.h>
|
||||
#include <app_priv.h>
|
||||
#include <app_qrcode.h>
|
||||
|
||||
@@ -37,6 +38,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
|
||||
case chip::DeviceLayer::DeviceEventType::PublicEventTypes::kCommissioningComplete:
|
||||
ESP_LOGI(TAG, "Commissioning complete");
|
||||
app_ble_disable();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota)
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_ble app_qrcode app_reset esp_matter_ota)
|
||||
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <esp_matter_ota.h>
|
||||
#include <esp_route_hook.h>
|
||||
|
||||
#include <app_ble.h>
|
||||
#include <app_priv.h>
|
||||
#include <app_qrcode.h>
|
||||
|
||||
@@ -37,6 +38,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
|
||||
case chip::DeviceLayer::DeviceEventType::PublicEventTypes::kCommissioningComplete:
|
||||
ESP_LOGI(TAG, "Commissioning complete");
|
||||
app_ble_disable();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console esp_matter_rainmaker route_hook app_qrcode app_reset
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console esp_matter_rainmaker route_hook app_ble app_qrcode app_reset
|
||||
esp_rainmaker)
|
||||
|
||||
idf_component_register(SRC_DIRS "."
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <esp_matter_console.h>
|
||||
#include <esp_route_hook.h>
|
||||
|
||||
#include <app_ble.h>
|
||||
#include <app_priv.h>
|
||||
#include <app_qrcode.h>
|
||||
#include <app_rainmaker.h>
|
||||
@@ -37,6 +38,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
|
||||
case chip::DeviceLayer::DeviceEventType::PublicEventTypes::kCommissioningComplete:
|
||||
ESP_LOGI(TAG, "Commissioning complete");
|
||||
app_ble_disable();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset)
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_ble app_qrcode app_reset)
|
||||
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <esp_matter_console.h>
|
||||
#include <esp_route_hook.h>
|
||||
|
||||
#include <app_ble.h>
|
||||
#include <app_priv.h>
|
||||
#include <app_qrcode.h>
|
||||
|
||||
@@ -35,6 +36,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
|
||||
case chip::DeviceLayer::DeviceEventType::PublicEventTypes::kCommissioningComplete:
|
||||
ESP_LOGI(TAG, "Commissioning complete");
|
||||
app_ble_disable();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode esp_matter_ota app_bridge esp-zboss-lib)
|
||||
set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_ble app_qrcode esp_matter_ota app_bridge
|
||||
esp-zboss-lib)
|
||||
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
|
||||
@@ -15,11 +15,12 @@
|
||||
#include <esp_matter_ota.h>
|
||||
#include <esp_route_hook.h>
|
||||
|
||||
#include <app_zigbee_bridge_device.h>
|
||||
#include <app_ble.h>
|
||||
#include <app_qrcode.h>
|
||||
#include <app_zboss.h>
|
||||
#include <app_zigbee_bridge_device.h>
|
||||
#include <zigbee_bridge.h>
|
||||
|
||||
#include "zigbee_bridge.h"
|
||||
static const char *TAG = "app_main";
|
||||
|
||||
using namespace esp_matter;
|
||||
@@ -37,6 +38,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
|
||||
case chip::DeviceLayer::DeviceEventType::PublicEventTypes::kCommissioningComplete:
|
||||
ESP_LOGI(TAG, "Commissioning complete");
|
||||
app_ble_disable();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user