mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'controller/commissioner_option' into 'main'
Controller: Make the commissioner feature optional See merge request app-frameworks/esp-matter!233
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
set(src_dirs_list )
|
||||
set(include_dirs_list )
|
||||
set(exclude_srcs_list )
|
||||
if (CONFIG_ESP_MATTER_CONTROLLER_ENABLE)
|
||||
list(APPEND src_dirs_list . logger/zap-generated)
|
||||
list(APPEND include_dirs_list . logger)
|
||||
endif()
|
||||
|
||||
if (NOT CONFIG_ESP_MATTER_COMMISSIONER_ENABLE)
|
||||
list(APPEND exclude_srcs_list esp_matter_commissioner.cpp esp_matter_controller_pairing_command.cpp)
|
||||
endif()
|
||||
|
||||
idf_component_register(SRC_DIRS ${src_dirs_list}
|
||||
EXCLUDE_SRCS ${exclude_srcs_list}
|
||||
INCLUDE_DIRS ${include_dirs_list}
|
||||
REQUIRES chip esp_matter esp_matter_console json_parser)
|
||||
|
||||
@@ -6,11 +6,18 @@ menu "ESP Matter Controller"
|
||||
help
|
||||
Enable the controller.
|
||||
|
||||
config ESP_MATTER_CONTROLLER_MAX_ACTIVE_DEVICES
|
||||
int "Max active device"
|
||||
config ESP_MATTER_COMMISSIONER_ENABLE
|
||||
bool "Enable matter commissioner"
|
||||
depends on ESP_MATTER_CONTROLLER_ENABLE
|
||||
default y
|
||||
help
|
||||
Enable the matter commissioner in the ESP Matter controller.
|
||||
|
||||
config ESP_MATTER_COMMISSIONER_MAX_ACTIVE_DEVICES
|
||||
int "Max active device"
|
||||
depends on ESP_MATTER_COMMISSIONER_ENABLE
|
||||
default 5
|
||||
help
|
||||
Maximum number of active device the controller supports.
|
||||
Maximum number of active device the commissioner supports.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <platform/PlatformManager.h>
|
||||
#include <transport/TransportMgr.h>
|
||||
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
using chip::NodeId;
|
||||
using chip::Controller::AutoCommissioner;
|
||||
using chip::Controller::DeviceCommissioner;
|
||||
@@ -39,3 +40,4 @@ CommissionerDiscoveryController *get_discovery_controller();
|
||||
AutoCommissioner *get_auto_commissioner();
|
||||
} // namespace commissioner
|
||||
} // namespace esp_matter
|
||||
#endif // CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <controller/CommissioneeDeviceProxy.h>
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
#include <esp_matter_commissioner.h>
|
||||
#else
|
||||
#include <app/server/Server.h>
|
||||
#endif
|
||||
#include <esp_matter_controller_cluster_command.h>
|
||||
|
||||
using namespace chip::app::Clusters;
|
||||
@@ -201,11 +205,18 @@ void cluster_command::on_device_connection_failure_fcn(void *context, const Scop
|
||||
|
||||
esp_err_t cluster_command::send_command()
|
||||
{
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
if (CHIP_NO_ERROR ==
|
||||
commissioner::get_device_commissioner()->GetConnectedDevice(m_node_id, &on_device_connected_cb,
|
||||
&on_device_connection_failure_cb)) {
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
chip::Server *server = &(chip::Server::GetInstance());
|
||||
server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(m_node_id, /* fabric index */ 1),
|
||||
&on_device_connected_cb, &on_device_connection_failure_cb);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
chip::Platform::Delete(this);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <esp_matter_commissioner.h>
|
||||
#include <esp_matter_controller_cluster_command.h>
|
||||
#include <esp_matter_controller_console.h>
|
||||
#include <esp_matter_controller_pairing_command.h>
|
||||
@@ -186,6 +185,7 @@ esp_err_t controller_register_commands()
|
||||
.description = "print this page",
|
||||
.handler = controller_help_handler,
|
||||
},
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
{
|
||||
.name = "pairing",
|
||||
.description = "Pairing a node. "
|
||||
@@ -194,6 +194,7 @@ esp_err_t controller_register_commands()
|
||||
"controller pairing ble-thread [nodeid] [pincode] [discriminator] [dataset]",
|
||||
.handler = controller_pairing_handler,
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.name = "invoke-cmd",
|
||||
.description = "Send command to the nodes. "
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
|
||||
#include <controller/CommissioneeDeviceProxy.h>
|
||||
#include <esp_log.h>
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
#include <esp_matter_commissioner.h>
|
||||
#else
|
||||
#include <app/server/Server.h>
|
||||
#endif
|
||||
#include <esp_matter_controller_read_command.h>
|
||||
|
||||
#include "DataModelLogger.h"
|
||||
@@ -74,11 +78,19 @@ void read_command::on_device_connection_failure_fcn(void *context, const ScopedN
|
||||
|
||||
esp_err_t read_command::send_command()
|
||||
{
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
if (CHIP_NO_ERROR ==
|
||||
commissioner::get_device_commissioner()->GetConnectedDevice(m_node_id, &on_device_connected_cb,
|
||||
&on_device_connection_failure_cb)) {
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
chip::Server *server = &(chip::Server::GetInstance());
|
||||
server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(m_node_id, /* fabric index */ 1),
|
||||
&on_device_connected_cb, &on_device_connection_failure_cb);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
|
||||
chip::Platform::Delete(this);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
|
||||
#include <controller/CommissioneeDeviceProxy.h>
|
||||
#include <esp_log.h>
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
#include <esp_matter_commissioner.h>
|
||||
#else
|
||||
#include <app/server/Server.h>
|
||||
#endif
|
||||
#include <esp_matter_controller_subscribe_command.h>
|
||||
|
||||
#include "DataModelLogger.h"
|
||||
@@ -78,11 +82,18 @@ void subscribe_command::on_device_connection_failure_fcn(void *context, const Sc
|
||||
|
||||
esp_err_t subscribe_command::send_command()
|
||||
{
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
if (CHIP_NO_ERROR ==
|
||||
commissioner::get_device_commissioner()->GetConnectedDevice(m_node_id, &on_device_connected_cb,
|
||||
&on_device_connection_failure_cb)) {
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
chip::Server *server = &(chip::Server::GetInstance());
|
||||
server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(m_node_id, /* fabric index */ 1),
|
||||
&on_device_connected_cb, &on_device_connection_failure_cb);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
chip::Platform::Delete(this);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
@@ -183,7 +194,11 @@ esp_err_t send_shutdown_subscription(uint64_t node_id, uint32_t subscription_id)
|
||||
{
|
||||
if (CHIP_NO_ERROR !=
|
||||
InteractionModelEngine::GetInstance()->ShutdownSubscription(
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
ScopedNodeId(node_id, commissioner::get_device_commissioner()->GetFabricIndex()), subscription_id)) {
|
||||
#else
|
||||
ScopedNodeId(node_id, /* fabric index */ 1), subscription_id)) {
|
||||
#endif
|
||||
ESP_LOGE(TAG, "Shutdown Subscription Failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,14 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <esp_check.h>
|
||||
#include <esp_matter_commissioner.h>
|
||||
#include <esp_matter_controller_utils.h>
|
||||
#include <esp_matter_controller_write_command.h>
|
||||
#include <json_parser.h>
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
#include <esp_matter_commissioner.h>
|
||||
#else
|
||||
#include <app/server/Server.h>
|
||||
#endif
|
||||
|
||||
using namespace chip::app::Clusters;
|
||||
using chip::ByteSpan;
|
||||
@@ -69,11 +73,18 @@ void write_command<T>::on_device_connection_failure_fcn(void *context, const Sco
|
||||
template <class T>
|
||||
esp_err_t write_command<T>::send_command()
|
||||
{
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
if (CHIP_NO_ERROR ==
|
||||
commissioner::get_device_commissioner()->GetConnectedDevice(m_node_id, &on_device_connected_cb,
|
||||
&on_device_connection_failure_cb)) {
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
chip::Server *server = &(chip::Server::GetInstance());
|
||||
server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(m_node_id, /* fabric index */ 1),
|
||||
&on_device_connected_cb, &on_device_connection_failure_cb);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
chip::Platform::Delete(this);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ project(controller)
|
||||
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
|
||||
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)
|
||||
|
||||
if (CONFIG_ESP_MATTER_CONTROLLER_ENABLE)
|
||||
idf_build_set_property(CXX_COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY=1;-DCHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES=${CONFIG_ESP_MATTER_CONTROLLER_MAX_ACTIVE_DEVICES}" APPEND)
|
||||
idf_build_set_property(C_COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY=1;-DCHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES=${CONFIG_ESP_MATTER_CONTROLLER_MAX_ACTIVE_DEVICES}" APPEND)
|
||||
if (CONFIG_ESP_MATTER_COMMISSIONER_ENABLE)
|
||||
idf_build_set_property(CXX_COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY=1;-DCHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES=${CONFIG_ESP_MATTER_COMMISSIONER_MAX_ACTIVE_DEVICES}" APPEND)
|
||||
idf_build_set_property(C_COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY=1;-DCHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES=${CONFIG_ESP_MATTER_COMMISSIONER_MAX_ACTIVE_DEVICES}" APPEND)
|
||||
endif()
|
||||
|
||||
# For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various
|
||||
|
||||
@@ -30,7 +30,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
||||
{
|
||||
switch (event->Type) {
|
||||
case chip::DeviceLayer::DeviceEventType::PublicEventTypes::kInterfaceIpAddressChanged:
|
||||
ESP_LOGI(TAG, "Interface gets IP Address");
|
||||
ESP_LOGI(TAG, "Interface IP Address changed");
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -44,19 +44,28 @@ extern "C" void app_main()
|
||||
|
||||
/* Initialize the ESP NVS layer */
|
||||
nvs_flash_init();
|
||||
#if !CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
// If there is no commissioner in the controller, we need a default node so that the controller can be commissioned
|
||||
// to a specific fabric.
|
||||
node::config_t node_config;
|
||||
node_t *node = node::create(&node_config, NULL, NULL);
|
||||
#endif
|
||||
|
||||
/* Matter start */
|
||||
err = esp_matter::start(app_event_cb);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Matter start failed: %d", err);
|
||||
}
|
||||
|
||||
#if CONFIG_ENABLE_CHIP_SHELL
|
||||
esp_matter::console::diagnostics_register_commands();
|
||||
esp_matter::console::init();
|
||||
#if CONFIG_ESP_MATTER_CONTROLLER_ENABLE
|
||||
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
esp_matter::lock::chip_stack_lock(portMAX_DELAY);
|
||||
esp_matter::commissioner::init(5580);
|
||||
esp_matter::lock::chip_stack_unlock();
|
||||
#endif // CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
|
||||
esp_matter::console::controller_register_commands();
|
||||
#endif
|
||||
#endif // CONFIG_ESP_MATTER_CONTROLLER_ENABLE
|
||||
#endif // CONFIG_ENABLE_CHIP_SHELL
|
||||
}
|
||||
|
||||
@@ -36,5 +36,6 @@ CONFIG_ESP_MAIN_TASK_STACK_SIZE=10240
|
||||
# Increase udp endpoints num for commissioner
|
||||
CONFIG_NUM_UDP_ENDPOINTS=16
|
||||
|
||||
# Enable Commissioner
|
||||
# Enable Controller and commissioner
|
||||
CONFIG_ESP_MATTER_CONTROLLER_ENABLE=y
|
||||
CONFIG_ESP_MATTER_COMMISSIONER_ENABLE=y
|
||||
|
||||
Reference in New Issue
Block a user