Skip to content

[Soil Measurement] Adds server implementation for soil measurement cluster #38606

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
96ebccf
Enable soil measurement in all-clusters zap
ReneJosefsen Apr 25, 2025
78464f7
Enabled soil measurement in all clusters
ReneJosefsen Apr 25, 2025
72713c5
Added soil sensor to matter-devices
ReneJosefsen Apr 25, 2025
9af9edd
Initial server impl
ReneJosefsen Apr 25, 2025
28ad016
Added all-clusters stub and reworked server impl
ReneJosefsen Apr 25, 2025
d3c9044
Added SetSoilMoistureMeasuredValue function
ReneJosefsen Apr 25, 2025
e9d3046
Added function to header file
ReneJosefsen Apr 25, 2025
dfb8e6c
Removed server handling of measured value and added allcluster comman…
ReneJosefsen Apr 28, 2025
e9b4f7a
Moved server to use global structs and enum
ReneJosefsen Apr 29, 2025
6f8b482
Remove redundant check
ReneJosefsen Apr 29, 2025
b01ef81
Marked SoilMoistureMeasuredValue as external
ReneJosefsen May 5, 2025
6f87666
Added handling for cluster rev and soilMoistureMeasuredValue in server
ReneJosefsen May 5, 2025
e9ad1ba
Apply suggestions from code review
ReneJosefsen May 6, 2025
227b1c8
Reworked server implementation based on review feedback
ReneJosefsen May 6, 2025
4d2e7e5
Added ClusterRevision to list of external
ReneJosefsen May 6, 2025
9855892
Updated SetSoilMeasurementAccuracy comment
ReneJosefsen May 6, 2025
8356661
Add server build files
ReneJosefsen May 7, 2025
52da415
Remove unused includes and used metadata cluster revision
ReneJosefsen May 7, 2025
ae8e49e
zap regen all
ReneJosefsen May 12, 2025
57dcb5b
Addressed some review comments
ReneJosefsen May 13, 2025
9475c8c
Address additional review comments
ReneJosefsen May 13, 2025
4c75865
Update src/app/clusters/soil-measurement-server/soil-measurement-serv…
ReneJosefsen May 13, 2025
f21673b
Addressed review feedback
ReneJosefsen May 20, 2025
10d1803
Reworked SetSimulatedSoilMoisture handling
ReneJosefsen May 27, 2025
568b595
Added check to only change and report on value changes and address re…
ReneJosefsen May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6940,6 +6940,19 @@ cluster RadonConcentrationMeasurement = 1071 {
readonly attribute int16u clusterRevision = 65533;
}

/** This cluster provides an interface to soil measurement functionality, including configuration and provision of notifications of soil measurements. */
provisional cluster SoilMeasurement = 1072 {
revision 1;

readonly attribute MeasurementAccuracyStruct soilMoistureMeasurementLimits = 0;
readonly attribute nullable percent soilMoistureMeasuredValue = 1;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;
}

/** This cluster provides an interface for managing low power mode on a device that supports the Wake On LAN protocol. */
cluster WakeOnLan = 1283 {
revision 1;
Expand Down Expand Up @@ -9660,6 +9673,16 @@ endpoint 1 {
ram attribute clusterRevision default = 3;
}

server cluster SoilMeasurement {
callback attribute soilMoistureMeasurementLimits;
callback attribute soilMoistureMeasuredValue;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0;
callback attribute clusterRevision;
}

server cluster WakeOnLan {
ram attribute MACAddress;
ram attribute featureMap default = 0;
Expand Down
123 changes: 123 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -20776,6 +20776,129 @@
}
]
},
{
"name": "Soil Measurement",
"code": 1072,
"mfgCode": null,
"define": "SOIL_MEASUREMENT_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"attributes": [
{
"name": "SoilMoistureMeasurementLimits",
"code": 0,
"mfgCode": null,
"side": "server",
"type": "MeasurementAccuracyStruct",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "SoilMoistureMeasuredValue",
"code": 1,
"mfgCode": null,
"side": "server",
"type": "percent",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AcceptedCommandList",
"code": 65529,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AttributeList",
"code": 65531,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
"mfgCode": null,
"side": "server",
"type": "bitmap32",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
}
]
},
{
"name": "Wake on LAN",
"code": 1283,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app/clusters/soil-measurement-server/soil-measurement-server.h>

namespace chip {
namespace app {
namespace Clusters {
namespace SoilMeasurement {

Instance * GetInstance();

void Shutdown();

} // namespace SoilMeasurement
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <soil-measurement-stub.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::SoilMeasurement;

static const Globals::Structs::MeasurementAccuracyRangeStruct::Type kDefaultSoilMoistureMeasurementLimitsAccuracyRange[] = {
{ .rangeMin = 0, .rangeMax = 100, .percentMax = MakeOptional(static_cast<chip::Percent100ths>(10)) }
};

static const Globals::Structs::MeasurementAccuracyStruct::Type kDefaultSoilMoistureMeasurementLimits = {
.measurementType = Globals::MeasurementTypeEnum::kSoilMoisture,
.measured = true,
.minMeasuredValue = 0,
.maxMeasuredValue = 100,
.accuracyRanges = DataModel::List<const Globals::Structs::MeasurementAccuracyRangeStruct::Type>(
kDefaultSoilMoistureMeasurementLimitsAccuracyRange)
};

namespace {
static std::unique_ptr<Instance> gSoilMeasurementInstance;
} // namespace

Instance * SoilMeasurement::GetInstance()
{
return gSoilMeasurementInstance.get();
}

void SoilMeasurement::Shutdown()
{
VerifyOrDie(gSoilMeasurementInstance);
gSoilMeasurementInstance->Shutdown();
gSoilMeasurementInstance.reset(nullptr);
}

void emberAfSoilMeasurementClusterInitCallback(EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(!gSoilMeasurementInstance);

gSoilMeasurementInstance = std::make_unique<Instance>(endpointId);
if (gSoilMeasurementInstance)
{
gSoilMeasurementInstance->Init(kDefaultSoilMoistureMeasurementLimits);
}
}
45 changes: 45 additions & 0 deletions examples/all-clusters-app/linux/AllClustersCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <oven-modes.h>
#include <oven-operational-state-delegate.h>
#include <rvc-modes.h>
#include <soil-measurement-stub.h>

#include <memory>
#include <string>
Expand Down Expand Up @@ -567,6 +568,29 @@ void AllClustersAppCommandHandler::HandleCommand(intptr_t context)
ChipLogError(NotSpecified, "Failed to store configuration version:%d", configurationVersion);
}
}
else if (name == "SetSimulatedSoilMoisture")
{
EndpointId endpoint = static_cast<EndpointId>(self->mJsonValue["EndpointId"].asUInt());
Json::Value jsonSoilMoisture = self->mJsonValue["SoilMoistureValue"];
DataModel::Nullable<Percent> soilMoistureMeasuredValue;

if (endpoint != 1)
{
ChipLogError(NotSpecified, "Invalid EndpointId to set Soil Moisture value.");
return;
}

if (jsonSoilMoisture.isNull())
{
soilMoistureMeasuredValue.SetNull();
}
else
{
soilMoistureMeasuredValue.SetNonNull(static_cast<uint8_t>(self->mJsonValue["SoilMoistureValue"].asUInt()));
}

self->OnSoilMoistureChange(endpoint, soilMoistureMeasuredValue);
}
else
{
ChipLogError(NotSpecified, "Unhandled command '%s': this should never happen", name.c_str());
Expand Down Expand Up @@ -929,6 +953,27 @@ void AllClustersAppCommandHandler::OnAirQualityChange(uint32_t aNewValue)
}
}

void AllClustersAppCommandHandler::OnSoilMoistureChange(EndpointId endpointId, DataModel::Nullable<Percent> soilMoisture)
{
SoilMeasurement::Instance * soilMeasurementInstance = SoilMeasurement::GetInstance();

if (soilMoisture.IsNull())
{
ChipLogDetail(NotSpecified, "Set SoilMoisture value to null");
}
else if (soilMoisture.Value() > 100)
{
ChipLogDetail(NotSpecified, "Invalid SoilMoisture value");
return;
}
else
{
ChipLogDetail(NotSpecified, "Set SoilMoisture value to %u", soilMoisture.Value());
}

soilMeasurementInstance->SetSoilMeasuredValue(soilMoisture);
}

void AllClustersAppCommandHandler::HandleSetOccupancyChange(EndpointId endpointId, uint8_t newOccupancyValue)
{
BitMask<chip::app::Clusters::OccupancySensing::OccupancyBitmap> currentOccupancy;
Expand Down
5 changes: 5 additions & 0 deletions examples/all-clusters-app/linux/AllClustersCommandDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class AllClustersAppCommandHandler
*/
void OnAirQualityChange(uint32_t aEnum);

/**
* Should be called when it is necessary to change the measured moisture value.
*/
void OnSoilMoistureChange(chip::EndpointId endpointId, chip::app::DataModel::Nullable<chip::Percent> soilMoisture);

/**
* Should be called when it is necessary to change the operational state as a manual operation.
*/
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/rvc-operational-state-delegate-impl.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/software-diagnostics-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/soil-measurement-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp",
Expand Down
15 changes: 15 additions & 0 deletions src/app/clusters/soil-measurement-server/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2025 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
group("soil-measurement-server") {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2025 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is the equivalent to app_config_dependent_sources.gni
TARGET_SOURCES(
${APP_TARGET}
PRIVATE
"${CLUSTER_DIR}/soil-measurement-server.cpp"
"${CLUSTER_DIR}/soil-measurement-server.h"
)
Loading
Loading