From 14da080ac36f027b792e1ab78bfd51a6d32cd8b1 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Mon, 29 Jan 2024 19:07:37 +0800 Subject: [PATCH] esp_matter: Add an option to disable Matter server for client-only examples --- RELEASE_NOTES.md | 4 + components/esp_matter/Kconfig | 9 ++ components/esp_matter/esp_matter_client.cpp | 121 +++++++++--------- components/esp_matter/esp_matter_core.cpp | 13 +- components/esp_matter/esp_matter_core.h | 8 +- .../esp-now_bridge_light/main/app_driver.cpp | 5 +- examples/light_switch/main/app_driver.cpp | 6 +- 7 files changed, 102 insertions(+), 64 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d2faa03f5..8a84c5545 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,7 @@ +# 29-January-2024 + +- Add a new parameter for esp_matter::client::connect() to set the CASESessionManager for finding or establishing the CASE sessions. + # 16-January-2024 - We have moved the creation of bridge devices to the application callback. diff --git a/components/esp_matter/Kconfig b/components/esp_matter/Kconfig index c77d7bf94..6e88e9834 100644 --- a/components/esp_matter/Kconfig +++ b/components/esp_matter/Kconfig @@ -231,4 +231,13 @@ menu "ESP Matter" If enabled, we will not use zap to define the data model of the node. All of the endpoints are dynamic. + config ESP_MATTER_ENABLE_MATTER_SERVER + bool "Enable Matter Server" + default y + help + This option should be disable for client-only examples, such as Matter commissioner. + + If enabled, we will start Matter server when calling esp_matter::start() + If disabled, the Matter server will not be initialized in esp_matter::start() + endmenu diff --git a/components/esp_matter/esp_matter_client.cpp b/components/esp_matter/esp_matter_client.cpp index cdcbd5e61..955eec22d 100644 --- a/components/esp_matter/esp_matter_client.cpp +++ b/components/esp_matter/esp_matter_client.cpp @@ -19,6 +19,8 @@ #include #include #include +#include "app/CASESessionManager.h" +#include "app/InteractionModelEngine.h" using namespace chip::app::Clusters; using chip::BitMask; @@ -77,8 +79,12 @@ void esp_matter_connection_failure_callback(void *context, const ScopedNodeId &p } } -esp_err_t connect(uint8_t fabric_index, uint64_t node_id, command_handle_t *cmd_handle) +esp_err_t connect(case_session_mgr_t *case_session_mgr, uint8_t fabric_index, uint64_t node_id, + command_handle_t *cmd_handle) { + if (!case_session_mgr) { + return ESP_ERR_INVALID_ARG; + } static Callback success_callback(esp_matter_connection_success_callback, NULL); static Callback failure_callback(esp_matter_connection_failure_callback, NULL); @@ -89,9 +95,8 @@ esp_err_t connect(uint8_t fabric_index, uint64_t node_id, command_handle_t *cmd_ } success_callback.mContext = static_cast(context); failure_callback.mContext = static_cast(context); - Server *server = &(chip::Server::GetInstance()); - server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(node_id, fabric_index), &success_callback, - &failure_callback); + case_session_mgr->FindOrEstablishSession(ScopedNodeId(node_id, fabric_index), &success_callback, + &failure_callback); return ESP_OK; } @@ -270,8 +275,8 @@ esp_err_t send_group_command(const uint8_t fabric_index, const CommandPathParams return ESP_ERR_INVALID_ARG; } chip::Transport::OutgoingGroupSession session(command_path.mGroupId, fabric_index); - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); - auto command_sender = chip::Platform::MakeUnique(nullptr, &exchange_mgr); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); + auto command_sender = chip::Platform::MakeUnique(nullptr, exchange_mgr); if (command_sender == nullptr) { ESP_LOGE(TAG, "No memory for command sender"); return ESP_ERR_NO_MEM; @@ -319,9 +324,9 @@ esp_err_t send_on(peer_device_t *remote_device, uint16_t remote_endpoint_id) esp_err_t group_send_on(uint8_t fabric_index, uint16_t group_id) { OnOff::Commands::On::Type command_data; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -338,9 +343,9 @@ esp_err_t send_off(peer_device_t *remote_device, uint16_t remote_endpoint_id) esp_err_t group_send_off(uint8_t fabric_index, uint16_t group_id) { OnOff::Commands::Off::Type command_data; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -357,9 +362,9 @@ esp_err_t send_toggle(peer_device_t *remote_device, uint16_t remote_endpoint_id) esp_err_t group_send_toggle(uint8_t fabric_index, uint16_t group_id) { OnOff::Commands::Toggle::Type command_data; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -393,9 +398,9 @@ esp_err_t group_send_move(uint8_t fabric_index, uint16_t group_id, uint8_t move_ command_data.optionsMask.SetRaw(option_mask); command_data.optionsOverride.SetRaw(option_override); - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -423,9 +428,9 @@ esp_err_t group_send_move_to_level(uint8_t fabric_index, uint16_t group_id, uint command_data.optionsMask.SetRaw(option_mask); command_data.optionsOverride.SetRaw(option_override); - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -449,9 +454,9 @@ esp_err_t group_send_move_to_level_with_on_off(uint8_t fabric_index, uint16_t gr command_data.level = level; command_data.transitionTime.SetNonNull(transition_time); - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -474,9 +479,9 @@ esp_err_t group_send_move_with_on_off(uint8_t fabric_index, uint16_t group_id, u command_data.moveMode = (LevelControl::MoveMode)move_mode; command_data.rate.SetNonNull(rate); - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -506,9 +511,9 @@ esp_err_t group_send_step(uint8_t fabric_index, uint16_t group_id, uint8_t step_ command_data.optionsMask.SetRaw(option_mask); command_data.optionsOverride.SetRaw(option_override); - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -534,9 +539,9 @@ esp_err_t group_send_step_with_on_off(uint8_t fabric_index, uint16_t group_id, u command_data.stepSize = step_size; command_data.transitionTime.SetNonNull(transition_time); - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -559,9 +564,9 @@ esp_err_t group_send_stop(uint8_t fabric_index, uint16_t group_id, uint8_t optio command_data.optionsMask.SetRaw(option_mask); command_data.optionsOverride.SetRaw(option_override); - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -579,9 +584,9 @@ esp_err_t group_send_stop_with_on_off(uint8_t fabric_index, uint16_t group_id) { LevelControl::Commands::Stop::Type command_data; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -615,9 +620,9 @@ esp_err_t group_send_move_hue(uint8_t fabric_index, uint16_t group_id, uint8_t m command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -645,9 +650,9 @@ esp_err_t group_send_move_saturation(uint8_t fabric_index, uint16_t group_id, ui command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -677,9 +682,9 @@ esp_err_t group_send_move_to_hue(uint8_t fabric_index, uint16_t group_id, uint8_ command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -711,9 +716,9 @@ esp_err_t group_send_move_to_hue_and_saturation(uint8_t fabric_index, uint16_t g command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -741,9 +746,9 @@ esp_err_t group_send_move_to_saturation(uint8_t fabric_index, uint16_t group_id, command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -773,9 +778,9 @@ esp_err_t group_send_step_hue(uint8_t fabric_index, uint16_t group_id, uint8_t s command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -806,9 +811,9 @@ esp_err_t group_send_step_saturation(uint8_t fabric_index, uint16_t group_id, ui command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -838,9 +843,9 @@ esp_err_t group_send_move_to_color(uint8_t fabric_index, uint16_t group_id, uint command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -868,9 +873,9 @@ esp_err_t group_send_move_color(uint8_t fabric_index, uint16_t group_id, int16_t command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -900,9 +905,9 @@ esp_err_t group_send_step_color(uint8_t fabric_index, uint16_t group_id, int16_t command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -932,9 +937,9 @@ esp_err_t group_send_move_to_color_temperature(uint8_t fabric_index, uint16_t gr command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -958,9 +963,9 @@ esp_err_t group_send_stop_move_step(uint8_t fabric_index, uint16_t group_id, uin command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -996,9 +1001,9 @@ esp_err_t group_send_move_color_temperature(uint8_t fabric_index, uint16_t group command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -1038,9 +1043,9 @@ esp_err_t group_send_step_color_temperature(uint8_t fabric_index, uint16_t group command_data.optionsMask = option_mask; command_data.optionsOverride = option_override; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } @@ -1065,9 +1070,9 @@ esp_err_t group_send_identify(uint8_t fabric_index, uint16_t group_id, uint16_t Identify::Commands::Identify::Type command_data; command_data.identifyTime = identify_time; - chip::Messaging::ExchangeManager &exchange_mgr = chip::Server::GetInstance().GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - chip::Controller::InvokeGroupCommandRequest(&exchange_mgr, fabric_index, group_id, command_data); + chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); return ESP_OK; } diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 76d5c32a1..bb4c06892 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -71,6 +71,11 @@ using chip::DeviceLayer::ThreadStackMgr; static const char *TAG = "esp_matter_core"; static bool esp_matter_started = false; +#ifndef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER +// If Matter Server is disabled, we should have an empty InitDataModelHandler() +void InitDataModelHandler() {} +#endif + namespace esp_matter { namespace { @@ -839,6 +844,7 @@ esp_err_t chip_stack_unlock() } } /* lock */ +#ifdef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER static void deinit_ble_if_commissioned(void) { #if CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING @@ -878,7 +884,6 @@ static void deinit_ble_if_commissioned(void) static void esp_matter_chip_init_task(intptr_t context) { TaskHandle_t task_to_notify = reinterpret_cast(context); - static chip::CommonCaseDeviceServerInitParams initParams; initParams.InitializeStaticResourcesBeforeServerInit(); initParams.appDelegate = &s_app_delegate; @@ -925,6 +930,7 @@ static void esp_matter_chip_init_task(intptr_t context) deinit_ble_if_commissioned(); xTaskNotifyGive(task_to_notify); } +#endif // CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER static void device_callback_internal(const ChipDeviceEvent * event, intptr_t arg) { @@ -938,7 +944,7 @@ static void device_callback_internal(const ChipDeviceEvent * event, intptr_t arg } #endif break; - +#ifdef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER case chip::DeviceLayer::DeviceEventType::kDnssdInitialized: esp_matter_ota_requestor_start(); /* Initialize binding manager */ @@ -953,6 +959,7 @@ static void device_callback_internal(const ChipDeviceEvent * event, intptr_t arg ESP_LOGI(TAG, "BLE Disconnected"); deinit_ble_if_commissioned(); break; +#endif default: break; } @@ -1008,9 +1015,11 @@ static esp_err_t chip_init(event_callback_t callback, intptr_t callback_arg) } #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD +#if CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER PlatformMgr().ScheduleWork(esp_matter_chip_init_task, reinterpret_cast(xTaskGetCurrentTaskHandle())); // Wait for the matter stack to be initialized xTaskNotifyWait(0, 0, NULL, portMAX_DELAY); +#endif // CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER return ESP_OK; } diff --git a/components/esp_matter/esp_matter_core.h b/components/esp_matter/esp_matter_core.h index b4d38440c..d7d95e75d 100644 --- a/components/esp_matter/esp_matter_core.h +++ b/components/esp_matter/esp_matter_core.h @@ -14,6 +14,7 @@ #pragma once +#include #include #include #include @@ -811,6 +812,9 @@ typedef struct command_handle { /** Peer device handle */ typedef chip::DeviceProxy peer_device_t; +/** CASE Session Manager */ +typedef chip::CASESessionManager case_session_mgr_t; + /** Command send callback * * This callback will be called when `connect()` or `cluster_update()` is called and the connection completes. The @@ -852,6 +856,7 @@ void binding_manager_init(); * * Connect to another device on the same fabric to send a command. * + * @param[in] case_session_mgr CASE Session Manager to find or establish the session * @param[in] fabric_index Fabric index. * @param[in] node_id Node ID of the other device. * @param[in] cmd_handle Command to be sent to the remote device. @@ -859,7 +864,8 @@ void binding_manager_init(); * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t connect(uint8_t fabric_index, uint64_t node_id, command_handle_t *cmd_handle); +esp_err_t connect(case_session_mgr_t *case_session_mgr, uint8_t fabric_index, uint64_t node_id, + command_handle_t *cmd_handle); /** group_command_send * diff --git a/examples/esp-now_bridge_light/main/app_driver.cpp b/examples/esp-now_bridge_light/main/app_driver.cpp index 2452c896c..256b5e488 100644 --- a/examples/esp-now_bridge_light/main/app_driver.cpp +++ b/examples/esp-now_bridge_light/main/app_driver.cpp @@ -17,6 +17,8 @@ #include +#include + using namespace chip::app::Clusters; using namespace esp_matter; using namespace esp_matter::cluster; @@ -94,7 +96,8 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv) cmd_handle.command_data = console_buffer; } - client::connect(fabric_index, node_id, &cmd_handle); + auto &server = chip::Server::GetInstance(); + client::connect(server.GetCASESessionManager(), fabric_index, node_id, &cmd_handle); } else if (argc >= 5 && strncmp(argv[0], "invoke-group", sizeof("invoke-group")) == 0) { client::command_handle_t cmd_handle; uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16); diff --git a/examples/light_switch/main/app_driver.cpp b/examples/light_switch/main/app_driver.cpp index 01bf6bb30..91b84f535 100644 --- a/examples/light_switch/main/app_driver.cpp +++ b/examples/light_switch/main/app_driver.cpp @@ -18,6 +18,8 @@ #include #include +#include + using chip::kInvalidClusterId; static constexpr chip::CommandId kInvalidCommandId = 0xFFFF'FFFF; @@ -97,8 +99,8 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv) cmd_handle.command_data = console_buffer; } - - client::connect(fabric_index, node_id, &cmd_handle); + auto &server = chip::Server::GetInstance(); + client::connect(server.GetCASESessionManager(), fabric_index, node_id, &cmd_handle); } else if (argc >= 5 && strncmp(argv[0], "invoke-group", sizeof("invoke-group")) == 0) { client::command_handle_t cmd_handle; uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16);