Skip to content

Commit 011062d

Browse files
samples: matter: Fix temperaure units in temperature sensor
The temperature value must be multiplied by 100 to get the proper Matter unit. Signed-off-by: Arkadiusz Balys <[email protected]>
1 parent 6c97f93 commit 011062d

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

samples/matter/temperature_sensor/README.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ After building the sample and programming it to your development kit, complete t
147147
.. note::
148148
The following steps use the CHIP Tool controller as an example.
149149

150+
The temperature measurement value is multiplied by 100 to achieve the resolution of 0.01 degrees Celsius.
151+
For example, 1252 means 12.52 degrees Celsius.
152+
150153
.. tabs::
151154

152155
.. group-tab:: nRF52 and nRF53 DKs
@@ -180,7 +183,7 @@ After building the sample and programming it to your development kit, complete t
180183
.. code-block:: console
181184
182185
[1755081048.320] [99348:99350] [TOO] Endpoint: 1 Cluster: 0x0000_0402 Attribute 0x0000_0000 DataVersion: 1994139940
183-
[1755081048.320] [99348:99350] [TOO] MeasuredValue: 12
186+
[1755081048.320] [99348:99350] [TOO] MeasuredValue: 1200
184187
185188
.. group-tab:: nRF54 DKs
186189

@@ -200,7 +203,7 @@ After building the sample and programming it to your development kit, complete t
200203
.. code-block:: console
201204
202205
[1755081048.320] [99348:99350] [TOO] Endpoint: 1 Cluster: 0x0000_0402 Attribute 0x0000_0000 DataVersion: 1994139940
203-
[1755081048.320] [99348:99350] [TOO] MeasuredValue: 9
206+
[1755081048.320] [99348:99350] [TOO] MeasuredValue: 900
204207
205208
#. Wait some time, for example 30 s, and read the measured temperature again using the same command as before:
206209

@@ -213,7 +216,7 @@ After building the sample and programming it to your development kit, complete t
213216
.. code-block:: console
214217
215218
[1755081048.320] [99348:99350] [TOO] Endpoint: 1 Cluster: 0x0000_0402 Attribute 0x0000_0000 DataVersion: 1994139940
216-
[1755081048.320] [99348:99350] [TOO] MeasuredValue: 12
219+
[1755081048.320] [99348:99350] [TOO] MeasuredValue: 1200
217220
218221
.. _matter_temperature_sensor_sample_remote_control:
219222

samples/matter/temperature_sensor/src/app_task.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ class AppTask {
2626

2727
static constexpr chip::EndpointId kTemperatureSensorEndpointId = 1;
2828

29+
/* Defined by cluster temperature measured value = 100 x temperature in degC with resolution of
30+
* 0.01 degC. */
2931
void UpdateTemperatureMeasurement()
3032
{
3133
/* Linear temperature increase that is wrapped around to min value after reaching the max value. */
3234
if (mCurrentTemperature < mTemperatureSensorMaxValue) {
33-
mCurrentTemperature++;
35+
mCurrentTemperature += kTemperatureMeasurementStep;
3436
} else {
3537
mCurrentTemperature = mTemperatureSensorMinValue;
3638
}
@@ -42,7 +44,8 @@ class AppTask {
4244
CHIP_ERROR Init();
4345
k_timer mTimer;
4446

45-
static constexpr uint16_t kTemperatureMeasurementIntervalMs = 10000;
47+
static constexpr uint16_t kTemperatureMeasurementIntervalMs = 10000; /* 10 seconds */
48+
static constexpr uint16_t kTemperatureMeasurementStep = 100; /* 1 degree Celsius */
4649

4750
static void UpdateTemperatureTimeoutCallback(k_timer *timer);
4851

samples/matter/temperature_sensor/src/default_zap/temperature_sensor.matter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,8 +2470,8 @@ endpoint 1 {
24702470

24712471
server cluster TemperatureMeasurement {
24722472
ram attribute measuredValue;
2473-
ram attribute minMeasuredValue default = -20;
2474-
ram attribute maxMeasuredValue default = 20;
2473+
ram attribute minMeasuredValue default = -2000;
2474+
ram attribute maxMeasuredValue default = 2000;
24752475
callback attribute generatedCommandList;
24762476
callback attribute acceptedCommandList;
24772477
callback attribute attributeList;

samples/matter/temperature_sensor/src/default_zap/temperature_sensor.zap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4594,7 +4594,7 @@
45944594
"storageOption": "RAM",
45954595
"singleton": 0,
45964596
"bounded": 0,
4597-
"defaultValue": "-20",
4597+
"defaultValue": "-2000",
45984598
"reportable": 1,
45994599
"minInterval": 1,
46004600
"maxInterval": 65534,
@@ -4610,7 +4610,7 @@
46104610
"storageOption": "RAM",
46114611
"singleton": 0,
46124612
"bounded": 0,
4613-
"defaultValue": "20",
4613+
"defaultValue": "2000",
46144614
"reportable": 1,
46154615
"minInterval": 1,
46164616
"maxInterval": 65534,

samples/matter/temperature_sensor/src/default_zap/zap-generated/endpoint_config.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@
558558
/* Endpoint: 1, Cluster: Temperature Measurement (server) */ \
559559
{ ZAP_EMPTY_DEFAULT(), 0x00000000, 2, ZAP_TYPE(TEMPERATURE), ZAP_ATTRIBUTE_MASK(NULLABLE) }, /* MeasuredValue \
560560
*/ \
561-
{ ZAP_SIMPLE_DEFAULT(-20), 0x00000001, 2, ZAP_TYPE(TEMPERATURE), ZAP_ATTRIBUTE_MASK(NULLABLE) }, /* MinMeasuredValue \
562-
*/ \
563-
{ ZAP_SIMPLE_DEFAULT(20), 0x00000002, 2, ZAP_TYPE(TEMPERATURE), ZAP_ATTRIBUTE_MASK(NULLABLE) }, /* MaxMeasuredValue \
564-
*/ \
561+
{ ZAP_SIMPLE_DEFAULT(-2000), 0x00000001, 2, ZAP_TYPE(TEMPERATURE), \
562+
ZAP_ATTRIBUTE_MASK(NULLABLE) }, /* MinMeasuredValue */ \
563+
{ ZAP_SIMPLE_DEFAULT(2000), 0x00000002, 2, ZAP_TYPE(TEMPERATURE), \
564+
ZAP_ATTRIBUTE_MASK(NULLABLE) }, /* MaxMeasuredValue */ \
565565
{ ZAP_SIMPLE_DEFAULT(0), 0x0000FFFC, 4, ZAP_TYPE(BITMAP32), 0 }, /* FeatureMap */ \
566566
{ ZAP_SIMPLE_DEFAULT(4), 0x0000FFFD, 2, ZAP_TYPE(INT16U), 0 }, /* ClusterRevision */ \
567567
}

0 commit comments

Comments
 (0)