This cluster uses the code-driven approach. The Ember attribute accessors for MeasuredValue, MinMeasuredValue, MaxMeasuredValue, and Tolerance are no longer available.
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);
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 }
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 } }
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)));
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);