Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you use subscriptions? (CON-1109) #890

Closed
jonsmirl opened this issue Mar 30, 2024 · 5 comments
Closed

How do you use subscriptions? (CON-1109) #890

jonsmirl opened this issue Mar 30, 2024 · 5 comments

Comments

@jonsmirl
Copy link
Contributor

This returns esp_err_t shouldn't it be returning cmd? And if it is returning cmd how do I override OnAttributeData()? I need to be able to set my own code for OnAttributeData().

esp_err_t send_subscribe_attr_command(uint64_t node_id, ScopedMemoryBufferWithSize<uint16_t> &endpoint_ids,
                                      ScopedMemoryBufferWithSize<uint32_t> &cluster_ids,
                                      ScopedMemoryBufferWithSize<uint32_t> &attribute_ids, uint16_t min_interval,
                                      uint16_t max_interval, bool auto_resubscribe)
{
    if (endpoint_ids.AllocatedSize() != cluster_ids.AllocatedSize() ||
        endpoint_ids.AllocatedSize() != attribute_ids.AllocatedSize()) {
        ESP_LOGE(TAG,
                 "The endpoint_id array length should be the same as the cluster_ids array length and the "
                 "attribute_ids array length");
        return ESP_ERR_INVALID_ARG;
    }
    ScopedMemoryBufferWithSize<AttributePathParams> attr_paths;
    ScopedMemoryBufferWithSize<EventPathParams> event_paths;
    attr_paths.Alloc(endpoint_ids.AllocatedSize());
    if (!attr_paths.Get()) {
        ESP_LOGE(TAG, "Failed to alloc memory for attribute paths");
        return ESP_ERR_NO_MEM;
    }
    for (size_t i = 0; i < attr_paths.AllocatedSize(); ++i) {
        attr_paths[i] = AttributePathParams(endpoint_ids[i], cluster_ids[i], attribute_ids[i]);
    }

    subscribe_command *cmd = chip::Platform::New<subscribe_command>(
        node_id, std::move(attr_paths), std::move(event_paths), min_interval, max_interval, auto_resubscribe);
    if (!cmd) {
        ESP_LOGE(TAG, "Failed to alloc memory for subscribe_command");
        return ESP_ERR_NO_MEM;
    }
    return cmd->send_command();
}
@github-actions github-actions bot changed the title How do you use subscriptions? How do you use subscriptions? (CON-1109) Mar 30, 2024
@jonsmirl
Copy link
Contributor Author

I've just copied esp_matter_controller_subscribe_command.cpp into my app and started editing on it. It looks like that is the only way to do this.

@wqx6
Copy link
Contributor

wqx6 commented Apr 1, 2024

The current way to use subscriptions is create a subscribe_command object with attribute_data_callback registered and call send_command() then.

We are planing to provide client interaction APIs(read, write, subscribe) with callback input in esp-matter component, which can be called when session is established.

@jonsmirl
Copy link
Contributor Author

jonsmirl commented Apr 1, 2024

The controller example in examples needs to be expanded to show the correct ways to call these APIs.

@wqx6
Copy link
Contributor

wqx6 commented Apr 2, 2024

The controller example in examples needs to be expanded to show the correct ways to call these APIs.

The controller example is only a command line example which supports base functionality of controller/commissioner like chip-tool, we are planing to provide a thermostat example which will call the client interaction APIs after they are added.

@jonsmirl
Copy link
Contributor Author

You don't want a subscription here, instead you want this: #920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants