tree: 805f59a2fd5514f18b282baf35efe3917f21843d
  1. tests/
  2. app_config_dependent_sources.cmake
  3. app_config_dependent_sources.gni
  4. BUILD.gn
  5. CodegenIntegration.cpp
  6. CodegenIntegration.h
  7. README.md
  8. RelativeHumidityMeasurementCluster.cpp
  9. RelativeHumidityMeasurementCluster.h
src/app/clusters/relative-humidity-measurement-server/README.md

Relative Humidity Measurement Cluster

This cluster uses the code-driven approach. The Ember attribute accessors for MeasuredValue, MinMeasuredValue, MaxMeasuredValue, and Tolerance are no longer available.

Usage

1. Instantiate the Cluster

Declare a RegisteredServerCluster in a .cpp file at global or static scope. Use the Config struct to set the optional range and tolerance attributes.

#include <app/clusters/relative-humidity-measurement-server/RelativeHumidityMeasurementCluster.h>
#include <app/server-cluster/ServerClusterInterfaceRegistry.h>

// Minimal — no optional attributes
chip::app::RegisteredServerCluster<chip::app::Clusters::RelativeHumidityMeasurementCluster>
    gHumidityCluster(kYourEndpointId);

// With min/max range and optional Tolerance attribute
chip::app::Clusters::RelativeHumidityMeasurementCluster::Config gHumidityConfig;
gHumidityConfig.minMeasuredValue = chip::app::DataModel::MakeNullable(uint16_t(0));
gHumidityConfig.maxMeasuredValue = chip::app::DataModel::MakeNullable(uint16_t(10000));
gHumidityConfig.WithTolerance(100);

chip::app::RegisteredServerCluster<chip::app::Clusters::RelativeHumidityMeasurementCluster>
    gHumidityCluster(kYourEndpointId, gHumidityConfig);

2. Register the Cluster

In your application's initialization, register the cluster with the data model provider:

#include <data-model-providers/codegen/CodegenDataModelProvider.h>

void ApplicationInit()
{
    CHIP_ERROR err = chip::app::CodegenDataModelProvider::Instance().Registry().Register(
        gHumidityCluster.Registration());
    // handle err
}

3. Push New Sensor Readings

Call SetMeasuredValue from within the Matter task context whenever the sensor produces a new reading. Use ScheduleWork if calling from a separate thread.

void OnSensorReading(uint16_t newHumidity)
{
    chip::app::Clusters::RelativeHumidityMeasurementCluster * cluster = gHumidityCluster.Get();
    if (cluster)
    {
        CHIP_ERROR err = cluster->SetMeasuredValue(chip::app::DataModel::MakeNullable(newHumidity));
        // handle err
    }
}

Compatibility with ZAP/Codegen

For applications that rely on ZAP-generated patterns, a compatibility layer is provided in CodegenIntegration.h and CodegenIntegration.cpp. The MatterRelativeHumidityMeasurementClusterInitCallback generated by ZAP is implemented by this layer to automatically instantiate the cluster.

To push readings in this mode, use FindClusterOnEndpoint:

#include <app/clusters/relative-humidity-measurement-server/CodegenIntegration.h>

CHIP_ERROR err = chip::app::Clusters::RelativeHumidityMeasurement::SetMeasuredValue(
    endpointId, chip::app::DataModel::MakeNullable(uint16_t(newValue)));

Configuring min/max range and tolerance

MinMeasuredValue, MaxMeasuredValue, and Tolerance are fixed attributes. They are configured once at startup via the Config struct and cannot be changed at runtime.

If you need to set them via code (e.g. in tests or for dynamic endpoints), pass a Config at construction time:

// Min/max only
RelativeHumidityMeasurementCluster::Config config;
config.minMeasuredValue = DataModel::MakeNullable(uint16_t(0));
config.maxMeasuredValue = DataModel::MakeNullable(uint16_t(10000));
auto cluster = RelativeHumidityMeasurementCluster(endpointId, config);

// With optional Tolerance attribute
RelativeHumidityMeasurementCluster::Config config;
config.minMeasuredValue = DataModel::MakeNullable(uint16_t(0));
config.maxMeasuredValue = DataModel::MakeNullable(uint16_t(10000));
config.WithTolerance(100);
auto cluster = RelativeHumidityMeasurementCluster(endpointId, config);