Skip to content

Commit d87aea1

Browse files
Update subscription_command callbacks
1 parent bd5fb3a commit d87aea1

5 files changed

Lines changed: 89 additions & 16 deletions

File tree

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 5-Mar-2026
2+
### API Changes
3+
- In `subscribe_command`, `subscribe_done_cb_t` has been renamed to `subscribe_terminated_cb_t` to align better with the terminology.
4+
- In `subscribe_command` a new callback `subscription_established_cb_t` has been added to report successfully subscription commands.
5+
16
# 4-Feb-2026
27
### API Changes
38
- Removed APIs: `plugin_init_callback_common()`, `add_bounds_callback_common()` and `delegate_init_callback_common()`.

components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ void subscribe_command::OnSubscriptionEstablished(chip::SubscriptionId subscript
159159
m_subscription_id = subscriptionId;
160160
m_resubscribe_retries = 0;
161161
ESP_LOGI(TAG, "Subscription 0x%" PRIx32 " established", subscriptionId);
162+
163+
if (subscription_established_cb) {
164+
// This will be called when the subscription is established.
165+
subscription_established_cb(m_node_id, m_subscription_id);
166+
}
162167
}
163168

164169
CHIP_ERROR subscribe_command::OnResubscriptionNeeded(ReadClient *apReadClient, CHIP_ERROR aTerminationCause)
@@ -175,9 +180,9 @@ CHIP_ERROR subscribe_command::OnResubscriptionNeeded(ReadClient *apReadClient, C
175180
void subscribe_command::OnDone(ReadClient *apReadClient)
176181
{
177182
ESP_LOGI(TAG, "Subscription 0x%" PRIx32 " Done for remote node 0x%" PRIx64, m_subscription_id, m_node_id);
178-
if (subscribe_done_cb) {
183+
if (subscription_terminated_cb) {
179184
// This will be called when the subscription is terminated.
180-
subscribe_done_cb(m_node_id, m_subscription_id);
185+
subscription_terminated_cb(m_node_id, m_subscription_id);
181186
}
182187
chip::Platform::Delete(this);
183188
}
@@ -207,7 +212,7 @@ esp_err_t send_subscribe_attr_command(uint64_t node_id, ScopedMemoryBufferWithSi
207212

208213
subscribe_command *cmd = chip::Platform::New<subscribe_command>(
209214
node_id, std::move(attr_paths), std::move(event_paths), min_interval, max_interval, auto_resubscribe, nullptr,
210-
nullptr, nullptr, nullptr, keep_subscription);
215+
nullptr, nullptr, nullptr, nullptr, keep_subscription);
211216
if (!cmd) {
212217
ESP_LOGE(TAG, "Failed to alloc memory for subscribe_command");
213218
return ESP_ERR_NO_MEM;
@@ -240,7 +245,7 @@ esp_err_t send_subscribe_event_command(uint64_t node_id, ScopedMemoryBufferWithS
240245

241246
subscribe_command *cmd = chip::Platform::New<subscribe_command>(
242247
node_id, std::move(attr_paths), std::move(event_paths), min_interval, max_interval, auto_resubscribe, nullptr,
243-
nullptr, nullptr, nullptr, keep_subscription);
248+
nullptr, nullptr, nullptr, nullptr, keep_subscription);
244249
if (!cmd) {
245250
ESP_LOGE(TAG, "Failed to alloc memory for subscribe_command");
246251
return ESP_ERR_NO_MEM;

components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.h

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,31 @@ class subscribe_command : public ReadClient::Callback {
4545
subscribe_command(uint64_t node_id, ScopedMemoryBufferWithSize<AttributePathParams> &&attr_paths,
4646
ScopedMemoryBufferWithSize<EventPathParams> &&event_paths, uint16_t min_interval,
4747
uint16_t max_interval, bool auto_resubscribe = true, attribute_report_cb_t attribute_cb = nullptr,
48-
event_report_cb_t event_cb = nullptr, subscribe_done_cb_t done_cb = nullptr,
48+
event_report_cb_t event_cb = nullptr, subscription_established_cb_t established_cb = nullptr,
49+
subscription_terminated_cb_t terminated_cb = nullptr, subscribe_failure_cb_t connect_failure_cb = nullptr, bool keep_subscription = true)
50+
: m_node_id(node_id)
51+
, m_min_interval(min_interval)
52+
, m_max_interval(max_interval)
53+
, m_auto_resubscribe(auto_resubscribe)
54+
, m_keep_subscription(keep_subscription)
55+
, m_buffered_read_cb(*this)
56+
, m_attr_paths(std::move(attr_paths))
57+
, m_event_paths(std::move(event_paths))
58+
, on_device_connected_cb(on_device_connected_fcn, this)
59+
, on_device_connection_failure_cb(on_device_connection_failure_fcn, this)
60+
, attribute_data_cb(attribute_cb)
61+
, event_data_cb(event_cb)
62+
, subscription_established_cb(established_cb)
63+
, subscription_terminated_cb(terminated_cb)
64+
, subscribe_failure_cb(connect_failure_cb)
65+
{
66+
}
67+
68+
/** Constructor for command with multiple paths**/
69+
subscribe_command(uint64_t node_id, ScopedMemoryBufferWithSize<AttributePathParams> &&attr_paths,
70+
ScopedMemoryBufferWithSize<EventPathParams> &&event_paths, uint16_t min_interval,
71+
uint16_t max_interval, bool auto_resubscribe = true, attribute_report_cb_t attribute_cb = nullptr,
72+
event_report_cb_t event_cb = nullptr, subscription_terminated_cb_t terminated_cb = nullptr,
4973
subscribe_failure_cb_t connect_failure_cb = nullptr, bool keep_subscription = true)
5074
: m_node_id(node_id)
5175
, m_min_interval(min_interval)
@@ -59,9 +83,46 @@ class subscribe_command : public ReadClient::Callback {
5983
, on_device_connection_failure_cb(on_device_connection_failure_fcn, this)
6084
, attribute_data_cb(attribute_cb)
6185
, event_data_cb(event_cb)
62-
, subscribe_done_cb(done_cb)
86+
, subscription_terminated_cb(terminated_cb)
87+
, subscribe_failure_cb(connect_failure_cb)
88+
{
89+
}
90+
91+
/** Constructor for command with single path.
92+
* @note 0xFFFF could be used as wildcard EndpointId
93+
* @note 0xFFFFFFFF could be used as wildcard ClusterId/AttributeId/EventId
94+
*/
95+
subscribe_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_or_event_id,
96+
subscribe_command_type_t command_type, uint16_t min_interval, uint16_t max_interval,
97+
bool auto_resubscribe = true, attribute_report_cb_t attribute_cb = nullptr,
98+
event_report_cb_t event_cb = nullptr, subscription_established_cb_t established_cb = nullptr,
99+
subscription_terminated_cb_t terminated_cb = nullptr, subscribe_failure_cb_t connect_failure_cb = nullptr,
100+
bool keep_subscription = true)
101+
: m_node_id(node_id)
102+
, m_min_interval(min_interval)
103+
, m_max_interval(max_interval)
104+
, m_auto_resubscribe(auto_resubscribe)
105+
, m_keep_subscription(keep_subscription)
106+
, m_buffered_read_cb(*this)
107+
, on_device_connected_cb(on_device_connected_fcn, this)
108+
, on_device_connection_failure_cb(on_device_connection_failure_fcn, this)
109+
, attribute_data_cb(attribute_cb)
110+
, event_data_cb(event_cb)
111+
, subscription_established_cb(established_cb)
112+
, subscription_terminated_cb(terminated_cb)
63113
, subscribe_failure_cb(connect_failure_cb)
64114
{
115+
if (command_type == SUBSCRIBE_ATTRIBUTE) {
116+
m_attr_paths.Alloc(1);
117+
if (m_attr_paths.Get()) {
118+
m_attr_paths[0] = AttributePathParams(endpoint_id, cluster_id, attribute_or_event_id);
119+
}
120+
} else if (command_type == SUBSCRIBE_EVENT) {
121+
m_event_paths.Alloc(1);
122+
if (m_event_paths.Get()) {
123+
m_event_paths[0] = EventPathParams(endpoint_id, cluster_id, attribute_or_event_id);
124+
}
125+
}
65126
}
66127

67128
/** Constructor for command with single path.
@@ -71,7 +132,7 @@ class subscribe_command : public ReadClient::Callback {
71132
subscribe_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_or_event_id,
72133
subscribe_command_type_t command_type, uint16_t min_interval, uint16_t max_interval,
73134
bool auto_resubscribe = true, attribute_report_cb_t attribute_cb = nullptr,
74-
event_report_cb_t event_cb = nullptr, subscribe_done_cb_t done_cb = nullptr,
135+
event_report_cb_t event_cb = nullptr, subscription_terminated_cb_t terminated_cb = nullptr,
75136
subscribe_failure_cb_t connect_failure_cb = nullptr, bool keep_subscription = true)
76137
: m_node_id(node_id)
77138
, m_min_interval(min_interval)
@@ -83,7 +144,7 @@ class subscribe_command : public ReadClient::Callback {
83144
, on_device_connection_failure_cb(on_device_connection_failure_fcn, this)
84145
, attribute_data_cb(attribute_cb)
85146
, event_data_cb(event_cb)
86-
, subscribe_done_cb(done_cb)
147+
, subscription_terminated_cb(terminated_cb)
87148
, subscribe_failure_cb(connect_failure_cb)
88149
{
89150
if (command_type == SUBSCRIBE_ATTRIBUTE) {
@@ -145,7 +206,8 @@ class subscribe_command : public ReadClient::Callback {
145206
chip::Callback::Callback<chip::OnDeviceConnectionFailure> on_device_connection_failure_cb;
146207
attribute_report_cb_t attribute_data_cb;
147208
event_report_cb_t event_data_cb;
148-
subscribe_done_cb_t subscribe_done_cb;
209+
subscription_established_cb_t subscription_established_cb;
210+
subscription_terminated_cb_t subscription_terminated_cb;
149211
subscribe_failure_cb_t subscribe_failure_cb;
150212
};
151213

components/esp_matter_controller/core/esp_matter_controller_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ using attribute_report_cb_t = void (*)(uint64_t remote_node_id, const chip::app:
3131
chip::TLV::TLVReader *data);
3232
using event_report_cb_t = void (*)(uint64_t remote_node_id, const chip::app::EventHeader &header,
3333
chip::TLV::TLVReader *data);
34-
using subscribe_done_cb_t = void (*)(uint64_t remote_node_id, uint32_t subscription_id);
34+
using subscription_established_cb_t = void (*)(uint64_t remote_node_id, uint32_t subscription_id);
35+
using subscription_terminated_cb_t = void (*)(uint64_t remote_node_id, uint32_t subscription_id);
3536
using subscribe_failure_cb_t = void (*)(void *subscribe_command);
3637
using read_done_cb_t = void (*)(uint64_t remote_node_id,
3738
const ScopedMemoryBufferWithSize<AttributePathParams> &attr_paths,

docs/en/controller.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ The controller should support the following features:
3636
The ``invoke-cmd`` command is used for sending cluster commands to the end-devices. It utilizes a ``cluster_command`` class to establish the sessions and send the command packets. The class constructor function could accept two callback inputs:
3737

3838
- **Success callback**:
39-
This callback will be called upon the reception of the success response. It could be used to handle the response data for the command that requires a reponse. Now the default success callback will print the response data for GroupKeyManagement, Groups, Scenes, Thermostat, and DoorLock clusters. If you want to handle the response data in your example, you can register your success callback when creating the ``cluster_command`` object.
39+
This callback will be called upon the reception of the success response. It could be used to handle the response data for the command that requires a response. Now the default success callback will print the response data for GroupKeyManagement, Groups, Scenes, Thermostat, and DoorLock clusters. If you want to handle the response data in your example, you can register your success callback when creating the ``cluster_command`` object.
4040

4141
- **Error callback**:
42-
This callback will be called upon the reception of the failure response or reponse timeout.
42+
This callback will be called upon the reception of the failure response or response timeout.
4343

4444
^^^^^^^^^^^^^^^^
4545

@@ -169,11 +169,11 @@ inputs:
169169
- **Event report callback**:
170170
This callback will be invoked upon the reception of the event report for subscribe-event commands.
171171

172-
- **Subscribe done callback**:
173-
This callback will be invoked when the subscription is terminated or shutdown.
172+
- **Subscription established callback**:
173+
This callback will be invoked when the subscription is established successfully.
174174

175-
- **Subscribe failure callback**:
176-
This callback will be invoked upon the failure of establishing CASE session.
175+
- **Subscription terminated callback**:
176+
This callback will be invoked when the subscription is terminated or shutdown.
177177

178178
1.4.1 Subscribe attribute commands
179179
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)