@@ -60,15 +60,12 @@ typedef enum {
60
60
SWITCH_RELEASE_DETECTED,
61
61
} switch_state_t ;
62
62
63
- static switch_func_pair_t button_func_pair[] = {
64
- {GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL}
65
- };
63
+ static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL}};
66
64
67
65
/* Default End Device config */
68
66
#define ESP_ZB_ZED_CONFIG () \
69
67
{ \
70
- .esp_zb_role = ESP_ZB_DEVICE_TYPE_ED, \
71
- .install_code_policy = INSTALLCODE_POLICY_ENABLE, \
68
+ .esp_zb_role = ESP_ZB_DEVICE_TYPE_ED, .install_code_policy = INSTALLCODE_POLICY_ENABLE, \
72
69
.nwk_cfg = { \
73
70
.zed_cfg = \
74
71
{ \
@@ -85,58 +82,58 @@ static switch_func_pair_t button_func_pair[] = {
85
82
{ .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, }
86
83
87
84
/* Zigbee configuration */
88
- #define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */
85
+ #define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */
89
86
#define ED_AGING_TIMEOUT ESP_ZB_ED_AGING_TIMEOUT_64MIN
90
87
#define ED_KEEP_ALIVE 3000 /* 3000 millisecond */
91
88
#define HA_ESP_SENSOR_ENDPOINT 10 /* esp temperature sensor device endpoint, used for temperature measurement */
92
89
#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */
93
90
94
91
/* Temperature sensor configuration */
95
- #define ESP_TEMP_SENSOR_UPDATE_INTERVAL (1 ) /* Local sensor update interval (second) */
96
- #define ESP_TEMP_SENSOR_MIN_VALUE (10 ) /* Local sensor min measured value (degree Celsius) */
97
- #define ESP_TEMP_SENSOR_MAX_VALUE (50 ) /* Local sensor max measured value (degree Celsius) */
92
+ #define ESP_TEMP_SENSOR_UPDATE_INTERVAL (1 ) /* Local sensor update interval (second) */
93
+ #define ESP_TEMP_SENSOR_MIN_VALUE (10 ) /* Local sensor min measured value (degree Celsius) */
94
+ #define ESP_TEMP_SENSOR_MAX_VALUE (50 ) /* Local sensor max measured value (degree Celsius) */
98
95
99
96
/* Attribute values in ZCL string format
100
97
* The string should be started with the length of its own.
101
98
*/
102
- #define MANUFACTURER_NAME " \x0B " " ESPRESSIF"
103
- #define MODEL_IDENTIFIER " \x09 " CONFIG_IDF_TARGET
99
+ #define MANUFACTURER_NAME \
100
+ " \x0B " \
101
+ " ESPRESSIF"
102
+ #define MODEL_IDENTIFIER " \x09 " CONFIG_IDF_TARGET
104
103
105
104
/* ******************** Zigbee functions **************************/
106
- static int16_t zb_temperature_to_s16 (float temp)
107
- {
108
- return (int16_t )(temp * 100 );
105
+ static int16_t zb_temperature_to_s16 (float temp) {
106
+ return (int16_t )(temp * 100 );
109
107
}
110
108
111
- static void esp_zb_buttons_handler (switch_func_pair_t *button_func_pair)
112
- {
113
- if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) {
114
- /* Send report attributes command */
115
- esp_zb_zcl_report_attr_cmd_t report_attr_cmd;
116
- report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
117
- report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID;
118
- report_attr_cmd.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE;
119
- report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT;
120
- report_attr_cmd.zcl_basic_cmd .src_endpoint = HA_ESP_SENSOR_ENDPOINT;
121
-
122
- esp_zb_lock_acquire (portMAX_DELAY);
123
- esp_zb_zcl_report_attr_cmd_req (&report_attr_cmd);
124
- esp_zb_lock_release ();
125
- log_i (" Send 'report attributes' command" );
126
- }
127
- }
109
+ static void esp_zb_buttons_handler (switch_func_pair_t *button_func_pair) {
110
+ if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) {
111
+ /* Send report attributes command */
112
+ esp_zb_zcl_report_attr_cmd_t report_attr_cmd;
113
+ report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
114
+ report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID;
115
+ report_attr_cmd.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE;
116
+ report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT;
117
+ report_attr_cmd.zcl_basic_cmd .src_endpoint = HA_ESP_SENSOR_ENDPOINT;
128
118
129
- static void esp_app_temp_sensor_handler (float temperature)
130
- {
131
- int16_t measured_value = zb_temperature_to_s16 (temperature);
132
- Serial.println (" Updating temperature sensor value..." );
133
- Serial.println (measured_value);
134
- /* Update temperature sensor measured value */
135
119
esp_zb_lock_acquire (portMAX_DELAY);
136
- esp_zb_zcl_set_attribute_val (HA_ESP_SENSOR_ENDPOINT,
137
- ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE,
138
- ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, &measured_value, false );
120
+ esp_zb_zcl_report_attr_cmd_req (&report_attr_cmd);
139
121
esp_zb_lock_release ();
122
+ log_i (" Send 'report attributes' command" );
123
+ }
124
+ }
125
+
126
+ static void esp_app_temp_sensor_handler (float temperature) {
127
+ int16_t measured_value = zb_temperature_to_s16 (temperature);
128
+ Serial.println (" Updating temperature sensor value..." );
129
+ Serial.println (measured_value);
130
+ /* Update temperature sensor measured value */
131
+ esp_zb_lock_acquire (portMAX_DELAY);
132
+ esp_zb_zcl_set_attribute_val (
133
+ HA_ESP_SENSOR_ENDPOINT, ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, &measured_value,
134
+ false
135
+ );
136
+ esp_zb_lock_release ();
140
137
}
141
138
142
139
static void bdb_start_top_level_commissioning_cb (uint8_t mode_mask) {
@@ -160,10 +157,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
160
157
// Start Temperature sensor reading task
161
158
xTaskCreate (temp_sensor_value_update, " temp_sensor_update" , 2048 , NULL , 10 , NULL );
162
159
if (esp_zb_bdb_is_factory_new ()) {
163
- log_i (" Start network steering" );
164
- esp_zb_bdb_start_top_level_commissioning (ESP_ZB_BDB_MODE_NETWORK_STEERING);
160
+ log_i (" Start network steering" );
161
+ esp_zb_bdb_start_top_level_commissioning (ESP_ZB_BDB_MODE_NETWORK_STEERING);
165
162
} else {
166
- log_i (" Device rebooted" );
163
+ log_i (" Device rebooted" );
167
164
}
168
165
} else {
169
166
/* commissioning failed */
@@ -188,30 +185,31 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
188
185
}
189
186
}
190
187
191
- static esp_zb_cluster_list_t *custom_temperature_sensor_clusters_create (esp_zb_temperature_sensor_cfg_t *temperature_sensor)
192
- {
193
- esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create ();
194
- esp_zb_attribute_list_t *basic_cluster = esp_zb_basic_cluster_create (&(temperature_sensor->basic_cfg ));
195
- ESP_ERROR_CHECK (esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)MANUFACTURER_NAME));
196
- ESP_ERROR_CHECK (esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (void *)MODEL_IDENTIFIER));
197
- ESP_ERROR_CHECK (esp_zb_cluster_list_add_basic_cluster (cluster_list, basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE));
198
- ESP_ERROR_CHECK (esp_zb_cluster_list_add_identify_cluster (cluster_list, esp_zb_identify_cluster_create (&(temperature_sensor->identify_cfg )), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE));
199
- ESP_ERROR_CHECK (esp_zb_cluster_list_add_identify_cluster (cluster_list, esp_zb_zcl_attr_list_create (ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY), ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE));
200
- ESP_ERROR_CHECK (esp_zb_cluster_list_add_temperature_meas_cluster (cluster_list, esp_zb_temperature_meas_cluster_create (&(temperature_sensor->temp_meas_cfg )), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE));
201
- return cluster_list;
188
+ static esp_zb_cluster_list_t *custom_temperature_sensor_clusters_create (esp_zb_temperature_sensor_cfg_t *temperature_sensor) {
189
+ esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create ();
190
+ esp_zb_attribute_list_t *basic_cluster = esp_zb_basic_cluster_create (&(temperature_sensor->basic_cfg ));
191
+ ESP_ERROR_CHECK (esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)MANUFACTURER_NAME));
192
+ ESP_ERROR_CHECK (esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (void *)MODEL_IDENTIFIER));
193
+ ESP_ERROR_CHECK (esp_zb_cluster_list_add_basic_cluster (cluster_list, basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE));
194
+ ESP_ERROR_CHECK (
195
+ esp_zb_cluster_list_add_identify_cluster (cluster_list, esp_zb_identify_cluster_create (&(temperature_sensor->identify_cfg )), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)
196
+ );
197
+ ESP_ERROR_CHECK (
198
+ esp_zb_cluster_list_add_identify_cluster (cluster_list, esp_zb_zcl_attr_list_create (ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY), ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE)
199
+ );
200
+ ESP_ERROR_CHECK (esp_zb_cluster_list_add_temperature_meas_cluster (
201
+ cluster_list, esp_zb_temperature_meas_cluster_create (&(temperature_sensor->temp_meas_cfg )), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE
202
+ ));
203
+ return cluster_list;
202
204
}
203
205
204
- static esp_zb_ep_list_t *custom_temperature_sensor_ep_create (uint8_t endpoint_id, esp_zb_temperature_sensor_cfg_t *temperature_sensor)
205
- {
206
- esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create ();
207
- esp_zb_endpoint_config_t endpoint_config = {
208
- .endpoint = endpoint_id,
209
- .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID,
210
- .app_device_id = ESP_ZB_HA_TEMPERATURE_SENSOR_DEVICE_ID,
211
- .app_device_version = 0
212
- };
213
- esp_zb_ep_list_add_ep (ep_list, custom_temperature_sensor_clusters_create (temperature_sensor), endpoint_config);
214
- return ep_list;
206
+ static esp_zb_ep_list_t *custom_temperature_sensor_ep_create (uint8_t endpoint_id, esp_zb_temperature_sensor_cfg_t *temperature_sensor) {
207
+ esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create ();
208
+ esp_zb_endpoint_config_t endpoint_config = {
209
+ .endpoint = endpoint_id, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_TEMPERATURE_SENSOR_DEVICE_ID, .app_device_version = 0
210
+ };
211
+ esp_zb_ep_list_add_ep (ep_list, custom_temperature_sensor_clusters_create (temperature_sensor), endpoint_config);
212
+ return ep_list;
215
213
}
216
214
217
215
static void esp_zb_task (void *pvParameters) {
@@ -228,26 +226,30 @@ static void esp_zb_task(void *pvParameters) {
228
226
229
227
/* Config the reporting info */
230
228
esp_zb_zcl_reporting_info_t reporting_info = {
231
- .direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV,
232
- .ep = HA_ESP_SENSOR_ENDPOINT,
233
- .cluster_id = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT,
234
- .cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE,
235
- .attr_id = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID,
236
- .u = {
237
- .send_info = {
229
+ .direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV,
230
+ .ep = HA_ESP_SENSOR_ENDPOINT,
231
+ .cluster_id = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT,
232
+ .cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE,
233
+ .attr_id = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID,
234
+ .u =
235
+ {
236
+ .send_info =
237
+ {
238
238
.min_interval = 1 ,
239
239
.max_interval = 0 ,
240
- .delta = {
241
- .u16 = 100 ,
242
- },
240
+ .delta =
241
+ {
242
+ .u16 = 100 ,
243
+ },
243
244
.def_min_interval = 1 ,
244
245
.def_max_interval = 0 ,
245
- },
246
+ },
246
247
},
247
- .dst = {
248
+ .dst =
249
+ {
248
250
.profile_id = ESP_ZB_AF_HA_PROFILE_ID,
249
251
},
250
- .manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC,
252
+ .manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC,
251
253
};
252
254
esp_zb_zcl_update_reporting_info (&reporting_info);
253
255
esp_zb_set_primary_network_channel_set (ESP_ZB_PRIMARY_CHANNEL_MASK);
@@ -277,13 +279,12 @@ static void switch_gpios_intr_enabled(bool enabled) {
277
279
}
278
280
279
281
/* *********************** Temp sensor *****************************/
280
- static void temp_sensor_value_update (void *arg)
281
- {
282
- for (;;) {
283
- float tsens_value = temperatureRead ();
284
- esp_app_temp_sensor_handler (tsens_value);
285
- delay (1000 );
286
- }
282
+ static void temp_sensor_value_update (void *arg) {
283
+ for (;;) {
284
+ float tsens_value = temperatureRead ();
285
+ esp_app_temp_sensor_handler (tsens_value);
286
+ delay (1000 );
287
+ }
287
288
}
288
289
289
290
/* ******************** Arduino functions **************************/
0 commit comments