Skip to content

Commit

Permalink
Merge branch 'decouple_server' into 'main'
Browse files Browse the repository at this point in the history
esp_matter: Add an option to disable Matter server for client-only examples

See merge request app-frameworks/esp-matter!617
chshu committed Feb 5, 2024
2 parents 52a95ea + 14da080 commit 37dc7d9
Showing 7 changed files with 102 additions and 64 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions components/esp_matter/Kconfig
Original file line number Diff line number Diff line change
@@ -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
121 changes: 63 additions & 58 deletions components/esp_matter/esp_matter_client.cpp

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions components/esp_matter/esp_matter_core.cpp
Original file line number Diff line number Diff line change
@@ -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<TaskHandle_t>(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<intptr_t>(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;
}

8 changes: 7 additions & 1 deletion components/esp_matter/esp_matter_core.h
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@

#pragma once

#include <app/CASESessionManager.h>
#include <app/DeviceProxy.h>
#include <app/InteractionModelEngine.h>
#include <app/util/af-types.h>
@@ -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,14 +856,16 @@ 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.
*
* @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
*
5 changes: 4 additions & 1 deletion examples/esp-now_bridge_light/main/app_driver.cpp
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@

#include <app_priv.h>

#include <app/server/Server.h>

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);
6 changes: 4 additions & 2 deletions examples/light_switch/main/app_driver.cpp
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
#include <app_priv.h>
#include <app_reset.h>

#include <app/server/Server.h>

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);

0 comments on commit 37dc7d9

Please sign in to comment.