From e0d18a1430152e4b5eb482133f6e9dd22076fbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Sat, 19 Jul 2025 17:52:00 +0200 Subject: [PATCH 1/8] feat(zigbee): Add cb option for default response message --- .../Zigbee_Temp_Hum_Sensor_Sleepy.ino | 34 +++++++++++++---- libraries/Zigbee/keywords.txt | 2 + libraries/Zigbee/src/ZigbeeEP.cpp | 9 +++++ libraries/Zigbee/src/ZigbeeEP.h | 37 ++++++++++++++++++- libraries/Zigbee/src/ZigbeeHandlers.cpp | 7 ++++ 5 files changed, 80 insertions(+), 9 deletions(-) diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index e9d08d32175..1ee3d4e23b8 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -42,6 +42,9 @@ uint8_t button = BOOT_PIN; ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER); +uint8_t dataToSend = 2; // Temperature and humidity values are reported in same endpoint, so 2 values are reported +bool resend = false; + /************************ Temp sensor *****************************/ void meausureAndSleep() { // Measure temperature sensor value @@ -55,17 +58,34 @@ void meausureAndSleep() { zbTempSensor.setHumidity(humidity); // Report temperature and humidity values - zbTempSensor.report(); + zbTempSensor.report(); // reports temperature and humidity values (if humidity sensor is not added, only temperature is reported) Serial.printf("Reported temperature: %.2f°C, Humidity: %.2f%%\r\n", temperature, humidity); - // Add small delay to allow the data to be sent before going to sleep - delay(100); + // Wait until data was succesfully sent + while(dataToSend != 0){ + if(resend){ + Serial.println("Resending data on failure!"); + resend = false; + dataToSend = 2; + zbTempSensor.report(); // report again + } + } - // Put device to deep sleep + // Put device to deep sleep after data was sent successfully Serial.println("Going to sleep now"); esp_deep_sleep_start(); } +void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status){ + Serial.printf("Response status recieved %s", zbTempSensor.esp_zb_zcl_status_to_name(status)); + if(command == ZB_CMD_REPORT_ATTRIBUTE){ + switch (status){ + case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break; + case ESP_ZB_ZCL_STATUS_FAIL: resend = true; break; + default: break;// add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc. + } + } +} /********************* Arduino functions **************************/ void setup() { Serial.begin(115200); @@ -92,6 +112,9 @@ void setup() { // Add humidity cluster to the temperature sensor device with min, max and tolerance values zbTempSensor.addHumiditySensor(0, 100, 1); + // Set callback for default response to handle status of reported data + zbTempSensor.onDefaultResponse(onResponse); + // Add endpoint to Zigbee Core Zigbee.addEndpoint(&zbTempSensor); @@ -116,9 +139,6 @@ void setup() { } Serial.println(); Serial.println("Successfully connected to Zigbee network"); - - // Delay approx 1s (may be adjusted) to allow establishing proper connection with coordinator, needed for sleepy devices - delay(1000); } void loop() { diff --git a/libraries/Zigbee/keywords.txt b/libraries/Zigbee/keywords.txt index 23f3af3bf02..68721c1a66f 100644 --- a/libraries/Zigbee/keywords.txt +++ b/libraries/Zigbee/keywords.txt @@ -47,6 +47,7 @@ zb_power_source_t KEYWORD1 ZigbeeWindowCoveringType KEYWORD1 ZigbeeFanMode KEYWORD1 ZigbeeFanModeSequence KEYWORD1 +zb_cmd_type_t KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -96,6 +97,7 @@ getTime KEYWORD2 getTimezone KEYWORD2 addOTAClient KEYWORD2 clearBoundDevices KEYWORD2 +onDefaultResponse KEYWORD2 # ZigbeeLight + ZigbeeColorDimmableLight onLightChange KEYWORD2 diff --git a/libraries/Zigbee/src/ZigbeeEP.cpp b/libraries/Zigbee/src/ZigbeeEP.cpp index efddbdd0368..67d715c002e 100644 --- a/libraries/Zigbee/src/ZigbeeEP.cpp +++ b/libraries/Zigbee/src/ZigbeeEP.cpp @@ -608,6 +608,15 @@ void ZigbeeEP::removeBoundDevice(zb_device_params_t *device) { log_w("No matching device found for removal"); } +void ZigbeeEP::zbDefaultResponse(const esp_zb_zcl_cmd_default_resp_message_t *message) { + log_v("Default response received for endpoint %d", _endpoint); + log_v("Status code: %s", esp_zb_zcl_status_to_name(message->status_code)); + log_v("Response to command: %d", message->resp_to_cmd); + if (_on_default_response) { + _on_default_response((zb_cmd_type_t)message->resp_to_cmd, message->status_code); + } +} + const char *ZigbeeEP::esp_zb_zcl_status_to_name(esp_zb_zcl_status_t status) { switch (status) { case ESP_ZB_ZCL_STATUS_SUCCESS: return "Success"; diff --git a/libraries/Zigbee/src/ZigbeeEP.h b/libraries/Zigbee/src/ZigbeeEP.h index a3217cbd066..9bae55e36cd 100644 --- a/libraries/Zigbee/src/ZigbeeEP.h +++ b/libraries/Zigbee/src/ZigbeeEP.h @@ -12,6 +12,32 @@ #define ZB_CMD_TIMEOUT 10000 // 10 seconds #define OTA_UPGRADE_QUERY_INTERVAL (1 * 60) // 1 hour = 60 minutes +typedef enum { + ZB_CMD_READ_ATTRIBUTE = 0x00U, /*!< Read attributes command */ + ZB_CMD_READ_ATTRIBUTE_RESPONSE = 0x01U, /*!< Read attributes response command */ + ZB_CMD_WRITE_ATTRIBUTE = 0x02U, /*!< Write attributes foundation command */ + ZB_CMD_WRITE_ATTRIBUTE_UNDIVIDED = 0x03U, /*!< Write attributes undivided command */ + ZB_CMD_WRITE_ATTRIBUTE_RESPONSE = 0x04U, /*!< Write attributes response command */ + ZB_CMD_WRITE_ATTRIBUTE_NO_RESPONSE = 0x05U, /*!< Write attributes no response command */ + ZB_CMD_CONFIGURE_REPORTING = 0x06U, /*!< Configure reporting command */ + ZB_CMD_CONFIGURE_REPORTING_RESPONSE = 0x07U, /*!< Configure reporting response command */ + ZB_CMD_READ_REPORTING_CONFIG = 0x08U, /*!< Read reporting config command */ + ZB_CMD_READ_REPORTING_CONFIG_RESPONSE= 0x09U, /*!< Read reporting config response command */ + ZB_CMD_REPORT_ATTRIBUTE = 0x0aU, /*!< Report attribute command */ + ZB_CMD_DEFAULT_RESPONSE = 0x0bU, /*!< Default response command */ + ZB_CMD_DISCOVER_ATTRIBUTES = 0x0cU, /*!< Discover attributes command */ + ZB_CMD_DISCOVER_ATTRIBUTES_RESPONSE = 0x0dU, /*!< Discover attributes response command */ + ZB_CMD_READ_ATTRIBUTE_STRUCTURED = 0x0eU, /*!< Read attributes structured */ + ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED = 0x0fU, /*!< Write attributes structured */ + ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED_RESPONSE = 0x10U, /*!< Write attributes structured response */ + ZB_CMD_DISCOVER_COMMANDS_RECEIVED = 0x11U, /*!< Discover Commands Received command */ + ZB_CMD_DISCOVER_COMMANDS_RECEIVED_RESPONSE = 0x12U, /*!< Discover Commands Received response command */ + ZB_CMD_DISCOVER_COMMANDS_GENERATED = 0x13U, /*!< Discover Commands Generated command */ + ZB_CMD_DISCOVER_COMMANDS_GENERATED_RESPONSE = 0x14U, /*!< Discover Commands Generated response command */ + ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED = 0x15U, /*!< Discover attributes extended command */ + ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE = 0x16U, /*!< Discover attributes extended response command */ +} zb_cmd_type_t; + #define ZB_ARRAY_LENGHT(arr) (sizeof(arr) / sizeof(arr[0])) #define RGB_TO_XYZ(r, g, b, X, Y, Z) \ @@ -138,6 +164,7 @@ class ZigbeeEP { virtual void zbReadTimeCluster(const esp_zb_zcl_attribute_t *attribute); //already implemented virtual void zbIASZoneStatusChangeNotification(const esp_zb_zcl_ias_zone_status_change_notification_message_t *message) {}; virtual void zbIASZoneEnrollResponse(const esp_zb_zcl_ias_zone_enroll_response_message_t *message) {}; + virtual void zbDefaultResponse(const esp_zb_zcl_cmd_default_resp_message_t *message); //already implemented virtual void addBoundDevice(zb_device_params_t *device) { _bound_devices.push_back(device); @@ -156,16 +183,22 @@ class ZigbeeEP { _on_identify = callback; } + void onDefaultResponse(void (*callback)(zb_cmd_type_t resp_to_cmd, esp_zb_zcl_status_t status)) { + _on_default_response = callback; + } + + // Convert ZCL status to name + const char *esp_zb_zcl_status_to_name(esp_zb_zcl_status_t status); + private: char *_read_manufacturer; char *_read_model; void (*_on_identify)(uint16_t time); + void (*_on_default_response)(zb_cmd_type_t resp_to_cmd, esp_zb_zcl_status_t status); time_t _read_time; int32_t _read_timezone; protected: - // Convert ZCL status to name - const char *esp_zb_zcl_status_to_name(esp_zb_zcl_status_t status); uint8_t _endpoint; esp_zb_ha_standard_devices_t _device_id; diff --git a/libraries/Zigbee/src/ZigbeeHandlers.cpp b/libraries/Zigbee/src/ZigbeeHandlers.cpp index 5d54e459058..b6a2888c59c 100644 --- a/libraries/Zigbee/src/ZigbeeHandlers.cpp +++ b/libraries/Zigbee/src/ZigbeeHandlers.cpp @@ -398,6 +398,13 @@ static esp_err_t zb_cmd_default_resp_handler(const esp_zb_zcl_cmd_default_resp_m "Received default response: from address(0x%x), src_endpoint(%d) to dst_endpoint(%d), cluster(0x%x) with status 0x%x", message->info.src_address.u.short_addr, message->info.src_endpoint, message->info.dst_endpoint, message->info.cluster, message->status_code ); + + // List through all Zigbee EPs and call the callback function, with the message + for (std::list::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) { + if (message->info.dst_endpoint == (*it)->getEndpoint()) { + (*it)->zbDefaultResponse(message); //method zbDefaultResponse is implemented in the common EP class + } + } return ESP_OK; } From 4cbdb444bc3d01ec03163470633ae2b5df085fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Sat, 19 Jul 2025 18:27:26 +0200 Subject: [PATCH 2/8] fix(example): Add timeout and fix spelling --- .../Zigbee_Temp_Hum_Sensor_Sleepy.ino | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index 1ee3d4e23b8..a6740a6756d 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -37,6 +37,7 @@ #define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 55 /* Sleep for 55s will + 5s delay for establishing connection => data reported every 1 minute */ +#define REPORT_TIMEOUT 30000 /* Timeout for reporting data in ms */ uint8_t button = BOOT_PIN; @@ -57,10 +58,14 @@ void meausureAndSleep() { zbTempSensor.setTemperature(temperature); zbTempSensor.setHumidity(humidity); + // Report temperature and humidity values zbTempSensor.report(); // reports temperature and humidity values (if humidity sensor is not added, only temperature is reported) Serial.printf("Reported temperature: %.2f°C, Humidity: %.2f%%\r\n", temperature, humidity); + unsigned long startTime = millis(); + const unsigned long timeout = REPORT_TIMEOUT; + // Wait until data was succesfully sent while(dataToSend != 0){ if(resend){ @@ -69,15 +74,19 @@ void meausureAndSleep() { dataToSend = 2; zbTempSensor.report(); // report again } + if (millis() - startTime >= timeout) { + Serial.println("Report timeout!"); + break; + } } - // Put device to deep sleep after data was sent successfully + // Put device to deep sleep after data was sent successfully or timeout Serial.println("Going to sleep now"); esp_deep_sleep_start(); } void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status){ - Serial.printf("Response status recieved %s", zbTempSensor.esp_zb_zcl_status_to_name(status)); + Serial.printf("Response status received %s\r\n", zbTempSensor.esp_zb_zcl_status_to_name(status)); if(command == ZB_CMD_REPORT_ATTRIBUTE){ switch (status){ case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break; From f10ca9fd534097a3a00cea1f6d1617c0d33ab7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Sat, 19 Jul 2025 22:55:51 +0200 Subject: [PATCH 3/8] feat(zigbee): Add global default response cb option --- .../Zigbee_Temp_Hum_Sensor_Sleepy.ino | 46 ++++++++++++++----- libraries/Zigbee/src/Zigbee.h | 3 ++ libraries/Zigbee/src/ZigbeeCore.cpp | 12 +++++ libraries/Zigbee/src/ZigbeeCore.h | 12 +++++ libraries/Zigbee/src/ZigbeeEP.cpp | 3 +- libraries/Zigbee/src/ZigbeeEP.h | 31 ++----------- libraries/Zigbee/src/ZigbeeHandlers.cpp | 3 ++ libraries/Zigbee/src/ZigbeeTypes.h | 30 ++++++++++++ 8 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 libraries/Zigbee/src/ZigbeeTypes.h diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index a6740a6756d..39f6c6f9b36 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -32,6 +32,8 @@ #include "Zigbee.h" +#define USE_GLOBAL_ON_RESPONSE_CALLBACK 1 // Set to 0 to use local callback specified directly for the endpoint. + /* Zigbee temperature + humidity sensor configuration */ #define TEMP_SENSOR_ENDPOINT_NUMBER 10 @@ -46,6 +48,31 @@ ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER); uint8_t dataToSend = 2; // Temperature and humidity values are reported in same endpoint, so 2 values are reported bool resend = false; +/************************ Callbacks *****************************/ +#if USE_GLOBAL_ON_RESPONSE_CALLBACK +void onGlobalResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster){ + Serial.printf("Global response command: %d, status: %s, endpoint: %d, cluster: 0x%04x\r\n", command, esp_zb_zcl_status_to_name(status), endpoint, cluster); + if((command == ZB_CMD_REPORT_ATTRIBUTE) && (endpoint == TEMP_SENSOR_ENDPOINT_NUMBER)){ + switch (status){ + case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break; + case ESP_ZB_ZCL_STATUS_FAIL: resend = true; break; + default: break;// add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc. + } + } +} +#else +void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status){ + Serial.printf("Response command: %d, status: %s\r\n", command, esp_zb_zcl_status_to_name(status)); + if(command == ZB_CMD_REPORT_ATTRIBUTE){ + switch (status){ + case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break; + case ESP_ZB_ZCL_STATUS_FAIL: resend = true; break; + default: break;// add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc. + } + } +} +#endif + /************************ Temp sensor *****************************/ void meausureAndSleep() { // Measure temperature sensor value @@ -85,16 +112,6 @@ void meausureAndSleep() { esp_deep_sleep_start(); } -void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status){ - Serial.printf("Response status received %s\r\n", zbTempSensor.esp_zb_zcl_status_to_name(status)); - if(command == ZB_CMD_REPORT_ATTRIBUTE){ - switch (status){ - case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break; - case ESP_ZB_ZCL_STATUS_FAIL: resend = true; break; - default: break;// add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc. - } - } -} /********************* Arduino functions **************************/ void setup() { Serial.begin(115200); @@ -121,8 +138,15 @@ void setup() { // Add humidity cluster to the temperature sensor device with min, max and tolerance values zbTempSensor.addHumiditySensor(0, 100, 1); - // Set callback for default response to handle status of reported data + // Set callback for default response to handle status of reported data, there are 2 options. + +#if USE_GLOBAL_ON_RESPONSE_CALLBACK + // Global callback for all endpoints with more params to determine the endpoint and cluster in the callback function. + Zigbee.onGlobalDefaultResponse(onGlobalResponse); +#else + // Callback specified for endpoint zbTempSensor.onDefaultResponse(onResponse); +#endif // Add endpoint to Zigbee Core Zigbee.addEndpoint(&zbTempSensor); diff --git a/libraries/Zigbee/src/Zigbee.h b/libraries/Zigbee/src/Zigbee.h index 65c9e7f0daa..ab94a163f3e 100644 --- a/libraries/Zigbee/src/Zigbee.h +++ b/libraries/Zigbee/src/Zigbee.h @@ -2,6 +2,9 @@ #pragma once +// Common types and functions +#include "ZigbeeTypes.h" + // Core #include "ZigbeeCore.h" #include "ZigbeeEP.h" diff --git a/libraries/Zigbee/src/ZigbeeCore.cpp b/libraries/Zigbee/src/ZigbeeCore.cpp index c49dedb221f..afb26324b1c 100644 --- a/libraries/Zigbee/src/ZigbeeCore.cpp +++ b/libraries/Zigbee/src/ZigbeeCore.cpp @@ -32,6 +32,7 @@ ZigbeeCore::ZigbeeCore() { _scan_duration = 3; // default scan duration _rx_on_when_idle = true; _debug = false; + _global_default_response_cb = nullptr; // Initialize global callback to nullptr if (!lock) { lock = xSemaphoreCreateBinary(); if (lock == NULL) { @@ -792,6 +793,17 @@ const char *ZigbeeCore::getDeviceTypeString(esp_zb_ha_standard_devices_t deviceI } } +void ZigbeeCore::callDefaultResponseCallback(zb_cmd_type_t resp_to_cmd, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster) { + log_v("Global callback called: cmd=%d, status=%s, ep=%d, cluster=0x%04x", resp_to_cmd, esp_zb_zcl_status_to_name(status), endpoint, cluster); + if (_global_default_response_cb) { + log_v("Global callback is set, calling it"); + _global_default_response_cb(resp_to_cmd, status, endpoint, cluster); + log_v("Global callback completed"); + } else { + log_v("Global callback is NOT set"); + } +} + ZigbeeCore Zigbee = ZigbeeCore(); #endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ZigbeeCore.h b/libraries/Zigbee/src/ZigbeeCore.h index 69c91c63ac4..df334e1620d 100644 --- a/libraries/Zigbee/src/ZigbeeCore.h +++ b/libraries/Zigbee/src/ZigbeeCore.h @@ -11,6 +11,7 @@ #include "aps/esp_zigbee_aps.h" #include #include +#include "ZigbeeTypes.h" #include "ZigbeeEP.h" class ZigbeeEP; @@ -103,6 +104,9 @@ class ZigbeeCore { SemaphoreHandle_t lock; bool _debug; + // Global default response callback + void (*_global_default_response_cb)(zb_cmd_type_t resp_to_cmd, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster); + bool zigbeeInit(esp_zb_cfg_t *zb_cfg, bool erase_nvs); static void scanCompleteCallback(esp_zb_zdp_status_t zdo_status, uint8_t count, esp_zb_network_descriptor_t *nwk_descriptor); const char *getDeviceTypeString(esp_zb_ha_standard_devices_t deviceId); @@ -176,6 +180,14 @@ class ZigbeeCore { return _debug; } + // Set global default response callback + void onGlobalDefaultResponse(void (*callback)(zb_cmd_type_t resp_to_cmd, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster)) { + _global_default_response_cb = callback; + } + + // Call global default response callback (for internal use) + void callDefaultResponseCallback(zb_cmd_type_t resp_to_cmd, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster); + // Friend function declaration to allow access to private members friend void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct); friend bool zb_apsde_data_indication_handler(esp_zb_apsde_data_ind_t ind); diff --git a/libraries/Zigbee/src/ZigbeeEP.cpp b/libraries/Zigbee/src/ZigbeeEP.cpp index 67d715c002e..6b63cae0312 100644 --- a/libraries/Zigbee/src/ZigbeeEP.cpp +++ b/libraries/Zigbee/src/ZigbeeEP.cpp @@ -617,7 +617,8 @@ void ZigbeeEP::zbDefaultResponse(const esp_zb_zcl_cmd_default_resp_message_t *me } } -const char *ZigbeeEP::esp_zb_zcl_status_to_name(esp_zb_zcl_status_t status) { +// Global function implementation +const char *esp_zb_zcl_status_to_name(esp_zb_zcl_status_t status) { switch (status) { case ESP_ZB_ZCL_STATUS_SUCCESS: return "Success"; case ESP_ZB_ZCL_STATUS_FAIL: return "Fail"; diff --git a/libraries/Zigbee/src/ZigbeeEP.h b/libraries/Zigbee/src/ZigbeeEP.h index 9bae55e36cd..66af419e0e9 100644 --- a/libraries/Zigbee/src/ZigbeeEP.h +++ b/libraries/Zigbee/src/ZigbeeEP.h @@ -12,32 +12,6 @@ #define ZB_CMD_TIMEOUT 10000 // 10 seconds #define OTA_UPGRADE_QUERY_INTERVAL (1 * 60) // 1 hour = 60 minutes -typedef enum { - ZB_CMD_READ_ATTRIBUTE = 0x00U, /*!< Read attributes command */ - ZB_CMD_READ_ATTRIBUTE_RESPONSE = 0x01U, /*!< Read attributes response command */ - ZB_CMD_WRITE_ATTRIBUTE = 0x02U, /*!< Write attributes foundation command */ - ZB_CMD_WRITE_ATTRIBUTE_UNDIVIDED = 0x03U, /*!< Write attributes undivided command */ - ZB_CMD_WRITE_ATTRIBUTE_RESPONSE = 0x04U, /*!< Write attributes response command */ - ZB_CMD_WRITE_ATTRIBUTE_NO_RESPONSE = 0x05U, /*!< Write attributes no response command */ - ZB_CMD_CONFIGURE_REPORTING = 0x06U, /*!< Configure reporting command */ - ZB_CMD_CONFIGURE_REPORTING_RESPONSE = 0x07U, /*!< Configure reporting response command */ - ZB_CMD_READ_REPORTING_CONFIG = 0x08U, /*!< Read reporting config command */ - ZB_CMD_READ_REPORTING_CONFIG_RESPONSE= 0x09U, /*!< Read reporting config response command */ - ZB_CMD_REPORT_ATTRIBUTE = 0x0aU, /*!< Report attribute command */ - ZB_CMD_DEFAULT_RESPONSE = 0x0bU, /*!< Default response command */ - ZB_CMD_DISCOVER_ATTRIBUTES = 0x0cU, /*!< Discover attributes command */ - ZB_CMD_DISCOVER_ATTRIBUTES_RESPONSE = 0x0dU, /*!< Discover attributes response command */ - ZB_CMD_READ_ATTRIBUTE_STRUCTURED = 0x0eU, /*!< Read attributes structured */ - ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED = 0x0fU, /*!< Write attributes structured */ - ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED_RESPONSE = 0x10U, /*!< Write attributes structured response */ - ZB_CMD_DISCOVER_COMMANDS_RECEIVED = 0x11U, /*!< Discover Commands Received command */ - ZB_CMD_DISCOVER_COMMANDS_RECEIVED_RESPONSE = 0x12U, /*!< Discover Commands Received response command */ - ZB_CMD_DISCOVER_COMMANDS_GENERATED = 0x13U, /*!< Discover Commands Generated command */ - ZB_CMD_DISCOVER_COMMANDS_GENERATED_RESPONSE = 0x14U, /*!< Discover Commands Generated response command */ - ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED = 0x15U, /*!< Discover attributes extended command */ - ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE = 0x16U, /*!< Discover attributes extended response command */ -} zb_cmd_type_t; - #define ZB_ARRAY_LENGHT(arr) (sizeof(arr) / sizeof(arr[0])) #define RGB_TO_XYZ(r, g, b, X, Y, Z) \ @@ -64,6 +38,9 @@ typedef enum { ZB_POWER_SOURCE_BATTERY = 0x03, } zb_power_source_t; +// Global function for converting ZCL status to name +const char *esp_zb_zcl_status_to_name(esp_zb_zcl_status_t status); + /* Zigbee End Device Class */ class ZigbeeEP { public: @@ -188,7 +165,6 @@ class ZigbeeEP { } // Convert ZCL status to name - const char *esp_zb_zcl_status_to_name(esp_zb_zcl_status_t status); private: char *_read_manufacturer; @@ -212,6 +188,7 @@ class ZigbeeEP { zb_power_source_t _power_source; uint8_t _time_status; + // Friend class declaration to allow access to protected members friend class ZigbeeCore; }; diff --git a/libraries/Zigbee/src/ZigbeeHandlers.cpp b/libraries/Zigbee/src/ZigbeeHandlers.cpp index b6a2888c59c..0986056dcd9 100644 --- a/libraries/Zigbee/src/ZigbeeHandlers.cpp +++ b/libraries/Zigbee/src/ZigbeeHandlers.cpp @@ -399,6 +399,9 @@ static esp_err_t zb_cmd_default_resp_handler(const esp_zb_zcl_cmd_default_resp_m message->info.src_address.u.short_addr, message->info.src_endpoint, message->info.dst_endpoint, message->info.cluster, message->status_code ); + // Call global callback if set + Zigbee.callDefaultResponseCallback((zb_cmd_type_t)message->resp_to_cmd, message->status_code, message->info.dst_endpoint, message->info.cluster); + // List through all Zigbee EPs and call the callback function, with the message for (std::list::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) { if (message->info.dst_endpoint == (*it)->getEndpoint()) { diff --git a/libraries/Zigbee/src/ZigbeeTypes.h b/libraries/Zigbee/src/ZigbeeTypes.h new file mode 100644 index 00000000000..8c8a8e29d84 --- /dev/null +++ b/libraries/Zigbee/src/ZigbeeTypes.h @@ -0,0 +1,30 @@ +#pragma once + +#include "esp_zigbee_core.h" + +// Foundation Command Types +typedef enum { + ZB_CMD_READ_ATTRIBUTE = 0x00U, /*!< Read attributes command */ + ZB_CMD_READ_ATTRIBUTE_RESPONSE = 0x01U, /*!< Read attributes response command */ + ZB_CMD_WRITE_ATTRIBUTE = 0x02U, /*!< Write attributes foundation command */ + ZB_CMD_WRITE_ATTRIBUTE_UNDIVIDED = 0x03U, /*!< Write attributes undivided command */ + ZB_CMD_WRITE_ATTRIBUTE_RESPONSE = 0x04U, /*!< Write attributes response command */ + ZB_CMD_WRITE_ATTRIBUTE_NO_RESPONSE = 0x05U, /*!< Write attributes no response command */ + ZB_CMD_CONFIGURE_REPORTING = 0x06U, /*!< Configure reporting command */ + ZB_CMD_CONFIGURE_REPORTING_RESPONSE = 0x07U, /*!< Configure reporting response command */ + ZB_CMD_READ_REPORTING_CONFIG = 0x08U, /*!< Read reporting config command */ + ZB_CMD_READ_REPORTING_CONFIG_RESPONSE= 0x09U, /*!< Read reporting config response command */ + ZB_CMD_REPORT_ATTRIBUTE = 0x0aU, /*!< Report attribute command */ + ZB_CMD_DEFAULT_RESPONSE = 0x0bU, /*!< Default response command */ + ZB_CMD_DISCOVER_ATTRIBUTES = 0x0cU, /*!< Discover attributes command */ + ZB_CMD_DISCOVER_ATTRIBUTES_RESPONSE = 0x0dU, /*!< Discover attributes response command */ + ZB_CMD_READ_ATTRIBUTE_STRUCTURED = 0x0eU, /*!< Read attributes structured */ + ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED = 0x0fU, /*!< Write attributes structured */ + ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED_RESPONSE = 0x10U, /*!< Write attributes structured response */ + ZB_CMD_DISCOVER_COMMANDS_RECEIVED = 0x11U, /*!< Discover Commands Received command */ + ZB_CMD_DISCOVER_COMMANDS_RECEIVED_RESPONSE = 0x12U, /*!< Discover Commands Received response command */ + ZB_CMD_DISCOVER_COMMANDS_GENERATED = 0x13U, /*!< Discover Commands Generated command */ + ZB_CMD_DISCOVER_COMMANDS_GENERATED_RESPONSE = 0x14U, /*!< Discover Commands Generated response command */ + ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED = 0x15U, /*!< Discover attributes extended command */ + ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE = 0x16U, /*!< Discover attributes extended response command */ +} zb_cmd_type_t; From 2e57aa444f9d6c0fb67a2d39c935940ab5482279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Sun, 20 Jul 2025 14:20:00 +0200 Subject: [PATCH 4/8] fix(example): Use task for measure and sleep --- .../Zigbee_Temp_Hum_Sensor_Sleepy.ino | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index 39f6c6f9b36..6926ffec3d3 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -74,7 +74,7 @@ void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status){ #endif /************************ Temp sensor *****************************/ -void meausureAndSleep() { +static void meausureAndSleep(void *arg) { // Measure temperature sensor value float temperature = temperatureRead(); @@ -93,6 +93,7 @@ void meausureAndSleep() { unsigned long startTime = millis(); const unsigned long timeout = REPORT_TIMEOUT; + Serial.printf("Waiting for data report to be confirmed \r\n"); // Wait until data was succesfully sent while(dataToSend != 0){ if(resend){ @@ -105,6 +106,8 @@ void meausureAndSleep() { Serial.println("Report timeout!"); break; } + Serial.printf("."); + delay(50); // 50ms delay to avoid busy-waiting } // Put device to deep sleep after data was sent successfully or timeout @@ -172,6 +175,9 @@ void setup() { } Serial.println(); Serial.println("Successfully connected to Zigbee network"); + + // Start Temperature sensor reading task + xTaskCreate(meausureAndSleep, "temp_sensor_update", 2048, NULL, 10, NULL); } void loop() { @@ -194,7 +200,5 @@ void loop() { } } } - - // Call the function to measure temperature and put the device to sleep - meausureAndSleep(); + delay(100); } From 68e253fc340aa89faad4ad2cd5e6c20dffff2189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Sun, 20 Jul 2025 14:21:18 +0200 Subject: [PATCH 5/8] fix(zigbee): Remove debug logs --- libraries/Zigbee/src/ZigbeeCore.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libraries/Zigbee/src/ZigbeeCore.cpp b/libraries/Zigbee/src/ZigbeeCore.cpp index afb26324b1c..bf652642ac1 100644 --- a/libraries/Zigbee/src/ZigbeeCore.cpp +++ b/libraries/Zigbee/src/ZigbeeCore.cpp @@ -794,13 +794,8 @@ const char *ZigbeeCore::getDeviceTypeString(esp_zb_ha_standard_devices_t deviceI } void ZigbeeCore::callDefaultResponseCallback(zb_cmd_type_t resp_to_cmd, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster) { - log_v("Global callback called: cmd=%d, status=%s, ep=%d, cluster=0x%04x", resp_to_cmd, esp_zb_zcl_status_to_name(status), endpoint, cluster); if (_global_default_response_cb) { - log_v("Global callback is set, calling it"); _global_default_response_cb(resp_to_cmd, status, endpoint, cluster); - log_v("Global callback completed"); - } else { - log_v("Global callback is NOT set"); } } From fa7d6a4e46240d9daffd479e3823c8262e9ca631 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 12:12:17 +0000 Subject: [PATCH 6/8] ci(pre-commit): Apply automatic fixes --- .../Zigbee_Temp_Hum_Sensor_Sleepy.ino | 49 +++++++++---------- libraries/Zigbee/src/ZigbeeEP.h | 5 +- libraries/Zigbee/src/ZigbeeTypes.h | 46 ++++++++--------- 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index 6926ffec3d3..7f8a3dbac49 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -32,7 +32,7 @@ #include "Zigbee.h" -#define USE_GLOBAL_ON_RESPONSE_CALLBACK 1 // Set to 0 to use local callback specified directly for the endpoint. +#define USE_GLOBAL_ON_RESPONSE_CALLBACK 1 // Set to 0 to use local callback specified directly for the endpoint. /* Zigbee temperature + humidity sensor configuration */ #define TEMP_SENSOR_ENDPOINT_NUMBER 10 @@ -45,29 +45,29 @@ uint8_t button = BOOT_PIN; ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER); -uint8_t dataToSend = 2; // Temperature and humidity values are reported in same endpoint, so 2 values are reported -bool resend = false; +uint8_t dataToSend = 2; // Temperature and humidity values are reported in same endpoint, so 2 values are reported +bool resend = false; /************************ Callbacks *****************************/ #if USE_GLOBAL_ON_RESPONSE_CALLBACK -void onGlobalResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster){ - Serial.printf("Global response command: %d, status: %s, endpoint: %d, cluster: 0x%04x\r\n", command, esp_zb_zcl_status_to_name(status), endpoint, cluster); - if((command == ZB_CMD_REPORT_ATTRIBUTE) && (endpoint == TEMP_SENSOR_ENDPOINT_NUMBER)){ - switch (status){ +void onGlobalResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster) { + Serial.printf("Global response command: %d, status: %s, endpoint: %d, cluster: 0x%04x\r\n", command, esp_zb_zcl_status_to_name(status), endpoint, cluster); + if ((command == ZB_CMD_REPORT_ATTRIBUTE) && (endpoint == TEMP_SENSOR_ENDPOINT_NUMBER)) { + switch (status) { case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break; - case ESP_ZB_ZCL_STATUS_FAIL: resend = true; break; - default: break;// add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc. + case ESP_ZB_ZCL_STATUS_FAIL: resend = true; break; + default: break; // add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc. } } } #else -void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status){ +void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status) { Serial.printf("Response command: %d, status: %s\r\n", command, esp_zb_zcl_status_to_name(status)); - if(command == ZB_CMD_REPORT_ATTRIBUTE){ - switch (status){ + if (command == ZB_CMD_REPORT_ATTRIBUTE) { + switch (status) { case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break; - case ESP_ZB_ZCL_STATUS_FAIL: resend = true; break; - default: break;// add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc. + case ESP_ZB_ZCL_STATUS_FAIL: resend = true; break; + default: break; // add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc. } } } @@ -85,9 +85,8 @@ static void meausureAndSleep(void *arg) { zbTempSensor.setTemperature(temperature); zbTempSensor.setHumidity(humidity); - // Report temperature and humidity values - zbTempSensor.report(); // reports temperature and humidity values (if humidity sensor is not added, only temperature is reported) + zbTempSensor.report(); // reports temperature and humidity values (if humidity sensor is not added, only temperature is reported) Serial.printf("Reported temperature: %.2f°C, Humidity: %.2f%%\r\n", temperature, humidity); unsigned long startTime = millis(); @@ -95,19 +94,19 @@ static void meausureAndSleep(void *arg) { Serial.printf("Waiting for data report to be confirmed \r\n"); // Wait until data was succesfully sent - while(dataToSend != 0){ - if(resend){ - Serial.println("Resending data on failure!"); - resend = false; - dataToSend = 2; - zbTempSensor.report(); // report again + while (dataToSend != 0) { + if (resend) { + Serial.println("Resending data on failure!"); + resend = false; + dataToSend = 2; + zbTempSensor.report(); // report again } if (millis() - startTime >= timeout) { Serial.println("Report timeout!"); break; } Serial.printf("."); - delay(50); // 50ms delay to avoid busy-waiting + delay(50); // 50ms delay to avoid busy-waiting } // Put device to deep sleep after data was sent successfully or timeout @@ -176,8 +175,8 @@ void setup() { Serial.println(); Serial.println("Successfully connected to Zigbee network"); - // Start Temperature sensor reading task - xTaskCreate(meausureAndSleep, "temp_sensor_update", 2048, NULL, 10, NULL); + // Start Temperature sensor reading task + xTaskCreate(meausureAndSleep, "temp_sensor_update", 2048, NULL, 10, NULL); } void loop() { diff --git a/libraries/Zigbee/src/ZigbeeEP.h b/libraries/Zigbee/src/ZigbeeEP.h index 66af419e0e9..23217407003 100644 --- a/libraries/Zigbee/src/ZigbeeEP.h +++ b/libraries/Zigbee/src/ZigbeeEP.h @@ -141,7 +141,7 @@ class ZigbeeEP { virtual void zbReadTimeCluster(const esp_zb_zcl_attribute_t *attribute); //already implemented virtual void zbIASZoneStatusChangeNotification(const esp_zb_zcl_ias_zone_status_change_notification_message_t *message) {}; virtual void zbIASZoneEnrollResponse(const esp_zb_zcl_ias_zone_enroll_response_message_t *message) {}; - virtual void zbDefaultResponse(const esp_zb_zcl_cmd_default_resp_message_t *message); //already implemented + virtual void zbDefaultResponse(const esp_zb_zcl_cmd_default_resp_message_t *message); //already implemented virtual void addBoundDevice(zb_device_params_t *device) { _bound_devices.push_back(device); @@ -165,7 +165,7 @@ class ZigbeeEP { } // Convert ZCL status to name - + private: char *_read_manufacturer; char *_read_model; @@ -175,7 +175,6 @@ class ZigbeeEP { int32_t _read_timezone; protected: - uint8_t _endpoint; esp_zb_ha_standard_devices_t _device_id; esp_zb_endpoint_config_t _ep_config; diff --git a/libraries/Zigbee/src/ZigbeeTypes.h b/libraries/Zigbee/src/ZigbeeTypes.h index 8c8a8e29d84..5025f90db7c 100644 --- a/libraries/Zigbee/src/ZigbeeTypes.h +++ b/libraries/Zigbee/src/ZigbeeTypes.h @@ -4,27 +4,27 @@ // Foundation Command Types typedef enum { - ZB_CMD_READ_ATTRIBUTE = 0x00U, /*!< Read attributes command */ - ZB_CMD_READ_ATTRIBUTE_RESPONSE = 0x01U, /*!< Read attributes response command */ - ZB_CMD_WRITE_ATTRIBUTE = 0x02U, /*!< Write attributes foundation command */ - ZB_CMD_WRITE_ATTRIBUTE_UNDIVIDED = 0x03U, /*!< Write attributes undivided command */ - ZB_CMD_WRITE_ATTRIBUTE_RESPONSE = 0x04U, /*!< Write attributes response command */ - ZB_CMD_WRITE_ATTRIBUTE_NO_RESPONSE = 0x05U, /*!< Write attributes no response command */ - ZB_CMD_CONFIGURE_REPORTING = 0x06U, /*!< Configure reporting command */ - ZB_CMD_CONFIGURE_REPORTING_RESPONSE = 0x07U, /*!< Configure reporting response command */ - ZB_CMD_READ_REPORTING_CONFIG = 0x08U, /*!< Read reporting config command */ - ZB_CMD_READ_REPORTING_CONFIG_RESPONSE= 0x09U, /*!< Read reporting config response command */ - ZB_CMD_REPORT_ATTRIBUTE = 0x0aU, /*!< Report attribute command */ - ZB_CMD_DEFAULT_RESPONSE = 0x0bU, /*!< Default response command */ - ZB_CMD_DISCOVER_ATTRIBUTES = 0x0cU, /*!< Discover attributes command */ - ZB_CMD_DISCOVER_ATTRIBUTES_RESPONSE = 0x0dU, /*!< Discover attributes response command */ - ZB_CMD_READ_ATTRIBUTE_STRUCTURED = 0x0eU, /*!< Read attributes structured */ - ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED = 0x0fU, /*!< Write attributes structured */ - ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED_RESPONSE = 0x10U, /*!< Write attributes structured response */ - ZB_CMD_DISCOVER_COMMANDS_RECEIVED = 0x11U, /*!< Discover Commands Received command */ - ZB_CMD_DISCOVER_COMMANDS_RECEIVED_RESPONSE = 0x12U, /*!< Discover Commands Received response command */ - ZB_CMD_DISCOVER_COMMANDS_GENERATED = 0x13U, /*!< Discover Commands Generated command */ - ZB_CMD_DISCOVER_COMMANDS_GENERATED_RESPONSE = 0x14U, /*!< Discover Commands Generated response command */ - ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED = 0x15U, /*!< Discover attributes extended command */ + ZB_CMD_READ_ATTRIBUTE = 0x00U, /*!< Read attributes command */ + ZB_CMD_READ_ATTRIBUTE_RESPONSE = 0x01U, /*!< Read attributes response command */ + ZB_CMD_WRITE_ATTRIBUTE = 0x02U, /*!< Write attributes foundation command */ + ZB_CMD_WRITE_ATTRIBUTE_UNDIVIDED = 0x03U, /*!< Write attributes undivided command */ + ZB_CMD_WRITE_ATTRIBUTE_RESPONSE = 0x04U, /*!< Write attributes response command */ + ZB_CMD_WRITE_ATTRIBUTE_NO_RESPONSE = 0x05U, /*!< Write attributes no response command */ + ZB_CMD_CONFIGURE_REPORTING = 0x06U, /*!< Configure reporting command */ + ZB_CMD_CONFIGURE_REPORTING_RESPONSE = 0x07U, /*!< Configure reporting response command */ + ZB_CMD_READ_REPORTING_CONFIG = 0x08U, /*!< Read reporting config command */ + ZB_CMD_READ_REPORTING_CONFIG_RESPONSE = 0x09U, /*!< Read reporting config response command */ + ZB_CMD_REPORT_ATTRIBUTE = 0x0aU, /*!< Report attribute command */ + ZB_CMD_DEFAULT_RESPONSE = 0x0bU, /*!< Default response command */ + ZB_CMD_DISCOVER_ATTRIBUTES = 0x0cU, /*!< Discover attributes command */ + ZB_CMD_DISCOVER_ATTRIBUTES_RESPONSE = 0x0dU, /*!< Discover attributes response command */ + ZB_CMD_READ_ATTRIBUTE_STRUCTURED = 0x0eU, /*!< Read attributes structured */ + ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED = 0x0fU, /*!< Write attributes structured */ + ZB_CMD_WRITE_ATTRIBUTE_STRUCTURED_RESPONSE = 0x10U, /*!< Write attributes structured response */ + ZB_CMD_DISCOVER_COMMANDS_RECEIVED = 0x11U, /*!< Discover Commands Received command */ + ZB_CMD_DISCOVER_COMMANDS_RECEIVED_RESPONSE = 0x12U, /*!< Discover Commands Received response command */ + ZB_CMD_DISCOVER_COMMANDS_GENERATED = 0x13U, /*!< Discover Commands Generated command */ + ZB_CMD_DISCOVER_COMMANDS_GENERATED_RESPONSE = 0x14U, /*!< Discover Commands Generated response command */ + ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED = 0x15U, /*!< Discover attributes extended command */ ZB_CMD_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE = 0x16U, /*!< Discover attributes extended response command */ -} zb_cmd_type_t; +} zb_cmd_type_t; From ef1b19e065c13a038dc7607acd7e900e5a706e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Jul 2025 14:22:34 +0200 Subject: [PATCH 7/8] fix(example): Add retry and fix typo --- .../Zigbee_Temp_Hum_Sensor_Sleepy.ino | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index 7f8a3dbac49..bd024d8ebab 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -39,7 +39,7 @@ #define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 55 /* Sleep for 55s will + 5s delay for establishing connection => data reported every 1 minute */ -#define REPORT_TIMEOUT 30000 /* Timeout for reporting data in ms */ +#define REPORT_TIMEOUT 1000 /* Timeout for response from coordinator in ms */ uint8_t button = BOOT_PIN; @@ -93,8 +93,10 @@ static void meausureAndSleep(void *arg) { const unsigned long timeout = REPORT_TIMEOUT; Serial.printf("Waiting for data report to be confirmed \r\n"); - // Wait until data was succesfully sent - while (dataToSend != 0) { + // Wait until data was successfully sent + int tries = 0; + const int maxTries = 3; + while (dataToSend != 0 && tries < maxTries) { if (resend) { Serial.println("Resending data on failure!"); resend = false; @@ -102,8 +104,11 @@ static void meausureAndSleep(void *arg) { zbTempSensor.report(); // report again } if (millis() - startTime >= timeout) { - Serial.println("Report timeout!"); - break; + Serial.println("\nReport timeout! Report Again"); + dataToSend = 2; + zbTempSensor.report(); // report again + startTime = millis(); + tries++; } Serial.printf("."); delay(50); // 50ms delay to avoid busy-waiting From b749553d5f0287d5b42417f2b6e4be9475bbe22b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 12:23:14 +0000 Subject: [PATCH 8/8] ci(pre-commit): Apply automatic fixes --- .../Zigbee_Temp_Hum_Sensor_Sleepy.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index bd024d8ebab..54c085fbfea 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -39,7 +39,7 @@ #define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 55 /* Sleep for 55s will + 5s delay for establishing connection => data reported every 1 minute */ -#define REPORT_TIMEOUT 1000 /* Timeout for response from coordinator in ms */ +#define REPORT_TIMEOUT 1000 /* Timeout for response from coordinator in ms */ uint8_t button = BOOT_PIN; @@ -106,7 +106,7 @@ static void meausureAndSleep(void *arg) { if (millis() - startTime >= timeout) { Serial.println("\nReport timeout! Report Again"); dataToSend = 2; - zbTempSensor.report(); // report again + zbTempSensor.report(); // report again startTime = millis(); tries++; }