@@ -32,12 +32,12 @@ void ZigbeeEP::setVersion(uint8_t version) {
32
32
_ep_config.app_device_version = version;
33
33
}
34
34
35
- void ZigbeeEP::setManufacturerAndModel (const char *name, const char *model) {
35
+ bool ZigbeeEP::setManufacturerAndModel (const char *name, const char *model) {
36
36
// Convert manufacturer to ZCL string
37
37
size_t length = strlen (name);
38
38
if (length > 32 ) {
39
39
log_e (" Manufacturer name is too long" );
40
- return ;
40
+ return false ;
41
41
}
42
42
// Allocate a new array of size length + 2 (1 for the length, 1 for null terminator)
43
43
char *zb_name = new char [length + 2 ];
@@ -53,7 +53,7 @@ void ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) {
53
53
if (length > 32 ) {
54
54
log_e (" Model name is too long" );
55
55
delete[] zb_name;
56
- return ;
56
+ return false ;
57
57
}
58
58
char *zb_model = new char [length + 2 ];
59
59
zb_model[0 ] = static_cast <char >(length);
@@ -62,8 +62,13 @@ void ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) {
62
62
63
63
// Get the basic cluster and update the manufacturer and model attributes
64
64
esp_zb_attribute_list_t *basic_cluster = esp_zb_cluster_list_get_cluster (_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
65
- esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)zb_name);
66
- esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (void *)zb_model);
65
+ esp_err_t ret_manufacturer = esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)zb_name);
66
+ esp_err_t ret_model = esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (void *)zb_model);
67
+ if (ret_manufacturer != ESP_OK || ret_model != ESP_OK) {
68
+ log_e (" Failed to set manufacturer and model" );
69
+ return false ;
70
+ }
71
+ return true ;
67
72
}
68
73
69
74
void ZigbeeEP::setPowerSource (zb_power_source_t power_source, uint8_t battery_percentage) {
@@ -72,6 +77,9 @@ void ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_pe
72
77
73
78
if (power_source == ZB_POWER_SOURCE_BATTERY) {
74
79
// Add power config cluster and battery percentage attribute
80
+ if (battery_percentage > 100 ) {
81
+ battery_percentage = 100 ;
82
+ }
75
83
battery_percentage = battery_percentage * 2 ;
76
84
esp_zb_attribute_list_t *power_config_cluster = esp_zb_zcl_attr_list_create (ESP_ZB_ZCL_CLUSTER_ID_POWER_CONFIG);
77
85
esp_zb_power_config_cluster_add_attr (power_config_cluster, ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID, (void *)&battery_percentage);
@@ -80,20 +88,26 @@ void ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_pe
80
88
_power_source = power_source;
81
89
}
82
90
83
- void ZigbeeEP::setBatteryPercentage (uint8_t percentage) {
91
+ bool ZigbeeEP::setBatteryPercentage (uint8_t percentage) {
84
92
// 100% = 200 in decimal, 0% = 0
85
93
// Convert percentage to 0-200 range
94
+ esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
86
95
if (percentage > 100 ) {
87
96
percentage = 100 ;
88
97
}
89
98
percentage = percentage * 2 ;
90
99
esp_zb_lock_acquire (portMAX_DELAY);
91
- esp_zb_zcl_set_attribute_val (
100
+ ret = esp_zb_zcl_set_attribute_val (
92
101
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_POWER_CONFIG, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID, &percentage,
93
102
false
94
103
);
95
104
esp_zb_lock_release ();
105
+ if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
106
+ log_e (" Failed to set battery percentage" );
107
+ return false ;
108
+ }
96
109
log_v (" Battery percentage updated" );
110
+ return true ;
97
111
}
98
112
99
113
void ZigbeeEP::reportBatteryPercentage () {
@@ -107,9 +121,14 @@ void ZigbeeEP::reportBatteryPercentage() {
107
121
report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC;
108
122
109
123
esp_zb_lock_acquire (portMAX_DELAY);
110
- esp_zb_zcl_report_attr_cmd_req (&report_attr_cmd);
124
+ esp_err_t ret = esp_zb_zcl_report_attr_cmd_req (&report_attr_cmd);
111
125
esp_zb_lock_release ();
126
+ if (ret != ESP_OK) {
127
+ log_e (" Failed to report battery percentage" );
128
+ return false ;
129
+ }
112
130
log_v (" Battery percentage reported" );
131
+ return true ;
113
132
}
114
133
115
134
char *ZigbeeEP::readManufacturer (uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr) {
@@ -260,18 +279,31 @@ void ZigbeeEP::addTimeCluster(tm time, int32_t gmt_offset) {
260
279
esp_zb_cluster_list_add_time_cluster (_cluster_list, time_cluster_client, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE);
261
280
}
262
281
263
- void ZigbeeEP::setTime (tm time) {
282
+ bool ZigbeeEP::setTime (tm time) {
283
+ esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
264
284
time_t utc_time = mktime (&time);
265
285
log_d (" Setting time to %lld" , utc_time);
266
286
esp_zb_lock_acquire (portMAX_DELAY);
267
- esp_zb_zcl_set_attribute_val (_endpoint, ESP_ZB_ZCL_CLUSTER_ID_TIME, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_TIME_TIME_ID, &utc_time, false );
287
+ ret = esp_zb_zcl_set_attribute_val (_endpoint, ESP_ZB_ZCL_CLUSTER_ID_TIME, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_TIME_TIME_ID, &utc_time, false );
268
288
esp_zb_lock_release ();
289
+ if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
290
+ log_e (" Failed to set time" );
291
+ return false ;
292
+ }
293
+ return true ;
269
294
}
270
295
271
- void ZigbeeEP::setTimezone (int32_t gmt_offset) {
296
+ bool ZigbeeEP::setTimezone (int32_t gmt_offset) {
297
+ esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
298
+ log_d (" Setting timezone to %d" , gmt_offset);
272
299
esp_zb_lock_acquire (portMAX_DELAY);
273
- esp_zb_zcl_set_attribute_val (_endpoint, ESP_ZB_ZCL_CLUSTER_ID_TIME, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_TIME_TIME_ZONE_ID, &gmt_offset, false );
300
+ ret = esp_zb_zcl_set_attribute_val (_endpoint, ESP_ZB_ZCL_CLUSTER_ID_TIME, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_TIME_TIME_ZONE_ID, &gmt_offset, false );
274
301
esp_zb_lock_release ();
302
+ if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
303
+ log_e (" Failed to set timezone" );
304
+ return false ;
305
+ }
306
+ return true ;
275
307
}
276
308
277
309
tm ZigbeeEP::getTime (uint8_t endpoint, int32_t short_addr, esp_zb_ieee_addr_t ieee_addr) {
@@ -410,11 +442,11 @@ void ZigbeeEP::addOTAClient(
410
442
uint16_t ota_upgrade_server_addr = 0xffff ;
411
443
uint8_t ota_upgrade_server_ep = 0xff ;
412
444
413
- ESP_ERROR_CHECK ( esp_zb_ota_cluster_add_attr (ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID, (void *)&variable_config) );
414
- ESP_ERROR_CHECK ( esp_zb_ota_cluster_add_attr (ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ADDR_ID, (void *)&ota_upgrade_server_addr) );
415
- ESP_ERROR_CHECK ( esp_zb_ota_cluster_add_attr (ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ENDPOINT_ID, (void *)&ota_upgrade_server_ep) );
445
+ esp_zb_ota_cluster_add_attr (ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID, (void *)&variable_config);
446
+ esp_zb_ota_cluster_add_attr (ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ADDR_ID, (void *)&ota_upgrade_server_addr);
447
+ esp_zb_ota_cluster_add_attr (ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ENDPOINT_ID, (void *)&ota_upgrade_server_ep);
416
448
417
- ESP_ERROR_CHECK ( esp_zb_cluster_list_add_ota_cluster (_cluster_list, ota_cluster, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE) );
449
+ esp_zb_cluster_list_add_ota_cluster (_cluster_list, ota_cluster, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE);
418
450
}
419
451
420
452
static void findOTAServer (esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) {
0 commit comments