nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
weather_station.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef WEATHER_STATION_H
8#define WEATHER_STATION_H
9
10#include <zcl/zb_zcl_temp_measurement_addons.h>
11
12#include "sensor.h"
13
14/* Zigbee Cluster Library 4.4.2.2.1.1: MeasuredValue = 100x temperature in degrees Celsius */
15#define ZCL_TEMPERATURE_MEASUREMENT_MEASURED_VALUE_MULTIPLIER 100
16/* Zigbee Cluster Library 4.5.2.2.1.1: MeasuredValue = 10x pressure in kPa */
17#define ZCL_PRESSURE_MEASUREMENT_MEASURED_VALUE_MULTIPLIER 10
18/* Zigbee Cluster Library 4.7.2.1.1: MeasuredValue = 100x water content in % */
19#define ZCL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_MULTIPLIER 100
20
21/* Measurements ranges scaled for attribute values */
22#define WEATHER_STATION_ATTR_TEMP_MIN ( \
23 SENSOR_TEMP_CELSIUS_MIN * \
24 ZCL_TEMPERATURE_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
25#define WEATHER_STATION_ATTR_TEMP_MAX ( \
26 SENSOR_TEMP_CELSIUS_MAX * \
27 ZCL_TEMPERATURE_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
28#define WEATHER_STATION_ATTR_TEMP_TOLERANCE ( \
29 SENSOR_TEMP_CELSIUS_TOLERANCE * \
30 ZCL_TEMPERATURE_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
31#define WEATHER_STATION_ATTR_PRESSURE_MIN ( \
32 SENSOR_PRESSURE_KPA_MIN * \
33 ZCL_PRESSURE_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
34#define WEATHER_STATION_ATTR_PRESSURE_MAX ( \
35 SENSOR_PRESSURE_KPA_MAX * \
36 ZCL_PRESSURE_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
37#define WEATHER_STATION_ATTR_PRESSURE_TOLERANCE ( \
38 SENSOR_PRESSURE_KPA_TOLERANCE * \
39 ZCL_PRESSURE_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
40#define WEATHER_STATION_ATTR_HUMIDITY_MIN ( \
41 SENSOR_HUMIDITY_PERCENT_MIN * \
42 ZCL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
43#define WEATHER_STATION_ATTR_HUMIDITY_MAX ( \
44 SENSOR_HUMIDITY_PERCENT_MAX * \
45 ZCL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
46#define WEATHER_STATION_ATTR_HUMIDITY_TOLERANCE ( \
47 SENSOR_HUMIDITY_PERCENT_TOLERANCE * \
48 ZCL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_MULTIPLIER)
49
50/* Number chosen for the single endpoint provided by weather station */
51#define WEATHER_STATION_ENDPOINT_NB 42
52
53/* Temperature sensor device version */
54#define ZB_HA_DEVICE_VER_TEMPERATURE_SENSOR 0
55/* Basic, identify, temperature, pressure, humidity */
56#define ZB_HA_WEATHER_STATION_IN_CLUSTER_NUM 5
57/* Identify */
58#define ZB_HA_WEATHER_STATION_OUT_CLUSTER_NUM 1
59
60/* Temperature, pressure, humidity */
61#define ZB_HA_WEATHER_STATION_REPORT_ATTR_COUNT 3
62
63#define ZB_HA_DECLARE_WEATHER_STATION_CLUSTER_LIST( \
64 cluster_list_name, \
65 basic_attr_list, \
66 identify_client_attr_list, \
67 identify_server_attr_list, \
68 temperature_measurement_attr_list, \
69 pressure_measurement_attr_list, \
70 humidity_measurement_attr_list \
71 ) \
72 zb_zcl_cluster_desc_t cluster_list_name[] = \
73 { \
74 ZB_ZCL_CLUSTER_DESC( \
75 ZB_ZCL_CLUSTER_ID_BASIC, \
76 ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \
77 (basic_attr_list), \
78 ZB_ZCL_CLUSTER_SERVER_ROLE, \
79 ZB_ZCL_MANUF_CODE_INVALID \
80 ), \
81 ZB_ZCL_CLUSTER_DESC( \
82 ZB_ZCL_CLUSTER_ID_IDENTIFY, \
83 ZB_ZCL_ARRAY_SIZE(identify_server_attr_list, zb_zcl_attr_t), \
84 (identify_server_attr_list), \
85 ZB_ZCL_CLUSTER_SERVER_ROLE, \
86 ZB_ZCL_MANUF_CODE_INVALID \
87 ), \
88 ZB_ZCL_CLUSTER_DESC( \
89 ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, \
90 ZB_ZCL_ARRAY_SIZE(temperature_measurement_attr_list, zb_zcl_attr_t), \
91 (temperature_measurement_attr_list), \
92 ZB_ZCL_CLUSTER_SERVER_ROLE, \
93 ZB_ZCL_MANUF_CODE_INVALID \
94 ), \
95 ZB_ZCL_CLUSTER_DESC( \
96 ZB_ZCL_CLUSTER_ID_PRESSURE_MEASUREMENT, \
97 ZB_ZCL_ARRAY_SIZE(pressure_measurement_attr_list, zb_zcl_attr_t), \
98 (pressure_measurement_attr_list), \
99 ZB_ZCL_CLUSTER_SERVER_ROLE, \
100 ZB_ZCL_MANUF_CODE_INVALID \
101 ), \
102 ZB_ZCL_CLUSTER_DESC( \
103 ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT, \
104 ZB_ZCL_ARRAY_SIZE(humidity_measurement_attr_list, zb_zcl_attr_t), \
105 (humidity_measurement_attr_list), \
106 ZB_ZCL_CLUSTER_SERVER_ROLE, \
107 ZB_ZCL_MANUF_CODE_INVALID \
108 ), \
109 ZB_ZCL_CLUSTER_DESC( \
110 ZB_ZCL_CLUSTER_ID_IDENTIFY, \
111 ZB_ZCL_ARRAY_SIZE(identify_client_attr_list, zb_zcl_attr_t), \
112 (identify_client_attr_list), \
113 ZB_ZCL_CLUSTER_CLIENT_ROLE, \
114 ZB_ZCL_MANUF_CODE_INVALID \
115 ), \
116 }
117
118#define ZB_ZCL_DECLARE_WEATHER_STATION_DESC( \
119 ep_name, \
120 ep_id, \
121 in_clust_num, \
122 out_clust_num) \
123 ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \
124 ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \
125 { \
126 ep_id, \
127 ZB_AF_HA_PROFILE_ID, \
128 ZB_HA_TEMPERATURE_SENSOR_DEVICE_ID, \
129 ZB_HA_DEVICE_VER_TEMPERATURE_SENSOR, \
130 0, \
131 in_clust_num, \
132 out_clust_num, \
133 { \
134 ZB_ZCL_CLUSTER_ID_BASIC, \
135 ZB_ZCL_CLUSTER_ID_IDENTIFY, \
136 ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, \
137 ZB_ZCL_CLUSTER_ID_PRESSURE_MEASUREMENT, \
138 ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT, \
139 ZB_ZCL_CLUSTER_ID_IDENTIFY, \
140 } \
141 }
142
143#define ZB_HA_DECLARE_WEATHER_STATION_EP(ep_name, ep_id, cluster_list) \
144 ZB_ZCL_DECLARE_WEATHER_STATION_DESC( \
145 ep_name, \
146 ep_id, \
147 ZB_HA_WEATHER_STATION_IN_CLUSTER_NUM, \
148 ZB_HA_WEATHER_STATION_OUT_CLUSTER_NUM); \
149 ZBOSS_DEVICE_DECLARE_REPORTING_CTX( \
150 reporting_info##ep_name, \
151 ZB_HA_WEATHER_STATION_REPORT_ATTR_COUNT); \
152 ZB_AF_DECLARE_ENDPOINT_DESC( \
153 ep_name, \
154 ep_id, \
155 ZB_AF_HA_PROFILE_ID, \
156 0, \
157 NULL, \
158 ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), \
159 cluster_list, \
160 (zb_af_simple_desc_1_1_t *)&simple_desc_##ep_name, \
161 ZB_HA_WEATHER_STATION_REPORT_ATTR_COUNT, reporting_info##ep_name, 0, NULL)
162
164 zb_int16_t measure_value;
167 zb_uint16_t tolerance;
168};
169
171 zb_int16_t measure_value;
174};
175
177 zb_zcl_basic_attrs_t basic_attr;
178 zb_zcl_identify_attrs_t identify_attr;
179 zb_zcl_temp_measurement_attrs_t temp_attrs;
182};
183
192
202
209
216
223
224#endif /* WEATHER_STATION_H */
zb_zcl_identify_attrs_t identify_attr
Definition: weather_station.h:178
struct zb_zcl_humidity_measurement_attrs_t humidity_attrs
Definition: weather_station.h:181
zb_zcl_basic_attrs_t basic_attr
Definition: weather_station.h:177
struct zb_zcl_pressure_measurement_attrs_t pres_attrs
Definition: weather_station.h:180
zb_zcl_temp_measurement_attrs_t temp_attrs
Definition: weather_station.h:179
Definition: weather_station.h:176
zb_int16_t measure_value
Definition: weather_station.h:171
zb_int16_t max_measure_value
Definition: weather_station.h:173
zb_int16_t min_measure_value
Definition: weather_station.h:172
Definition: weather_station.h:170
zb_int16_t measure_value
Definition: weather_station.h:164
zb_int16_t max_measure_value
Definition: weather_station.h:166
zb_int16_t min_measure_value
Definition: weather_station.h:165
zb_uint16_t tolerance
Definition: weather_station.h:167
Definition: weather_station.h:163
int weather_station_update_pressure(void)
Updates ZCL pressure attribute using value obtained during last weather check.
int weather_station_update_temperature(void)
Updates ZCL temperature attribute using value obtained during last weather check.
int weather_station_update_humidity(void)
Updates ZCL relative humidity attribute using value obtained during last weather check.
int weather_station_check_weather(void)
Updates internal measurements performed by sensor.
int weather_station_init(void)
Initializes HW sensor used for performing measurements.