How to config endpoint number dynamically in Matter with nrf54l15?

We are trying to develop a smart controller based on the nRF54L15 that supports a dynamically configurable number of buttons.
We want users to be able to select the number of buttons, and have them correctly mapped on the Matter controller.

Currently, we are experimenting based on the Light Switch example, and we have managed to statically generate multiple buttons.
Could you advise how to implement dynamic button configuration on the nRF54L15?

In the official demo, I noticed that the matter_bridge example supports adding endpoints dynamically. However, this demo is based on the nRF54-30 and cannot be compiled for the nRF54L15.
I tried to port the dynamic endpoint functionality from matter_bridge into the Light Switch example.

Here is the code used to add endpoints:

void AddGenericSwitchEndpoints(int count)
{
    if (count <= 0) {
        return;
    }

    if (static_cast<size_t>(count) > kMaxDynamicEndpoints) {
        ChipLogError(AppServer, "Requested %d endpoints > kMaxDynamicEndpoints(%u), clamping.",
                     count, static_cast<unsigned>(kMaxDynamicEndpoints));
        count = static_cast<int>(kMaxDynamicEndpoints);
    }

    EndpointId nextId = 2; // 0 = Root Node, 1 = 模板
    for (int i = 0; i < count; ++i) {
        EndpointId ep = nextId++;

        // 取本 index 的 DataVersion 缓冲;确保生命周期覆盖整个运行期
        DataVersion * dv = sDataVersionPool[i]; // 已零初始化

        ChipLogProgress(AppServer, "ep %u cluster count=%u", ep,
                static_cast<unsigned>(genericSwitchEndpoint.clusterCount));

        CHIP_ERROR err = emberAfSetDynamicEndpoint(
            static_cast<uint16_t>(i),    // 动态 endpoint index
            ep,                          // endpointId
            &genericSwitchEndpoint,      // endpoint 模板
            Span<DataVersion>(dv, kClusterCount), // cluster data versions
            Span<const EmberAfDeviceType>(kGenericSwitchDeviceTypes, ArraySize(kGenericSwitchDeviceTypes)),
            kInvalidEndpointId);         // 无 parent endpoint

        if (err == CHIP_NO_ERROR) {
            ChipLogProgress(AppServer, "✅ Added GenericSwitch endpoint %u", static_cast<unsigned>(ep));

        for (size_t j = 0; j < ArraySize(switchAttrs); j++) {
    ChipLogProgress(AppServer, "SwitchAttr[%u] = 0x%08lx",
                    (unsigned) j, (unsigned long) switchAttrs[j].attributeId);
}

The log shows that the endpoint was added, but setting the attribute values failed.

The attached file is the ZAP configuration.
Currently, endpoint 0 is set as the root, and endpoint 1 is used as the Generic Switch template. The actual button endpoints start from endpoint 2.

Could you please help check what went wrong?
Thank you!

Parents Reply Children
Related