From 684a9312e6e117cefc67ade4da7d9f0b700dc020 Mon Sep 17 00:00:00 2001 From: iranl Date: Wed, 5 Mar 2025 11:45:11 +0100 Subject: [PATCH 01/15] fix(bt): Compile error on ESP32-P4 (#11035) * fix(bt): Fix compile error on ESP32-P4 * fix(bt): Fix compile error on ESP32-P4 --- cores/esp32/esp32-hal-misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 02871872f83..50e2973d27a 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -25,7 +25,7 @@ #include "esp_ota_ops.h" #endif //CONFIG_APP_ROLLBACK_ENABLE #include "esp_private/startup_internal.h" -#ifdef CONFIG_BT_ENABLED +#if defined(CONFIG_BT_ENABLED) && SOC_BT_SUPPORTED #include "esp_bt.h" #endif //CONFIG_BT_ENABLED #include @@ -305,7 +305,7 @@ void initArduino() { if (err) { log_e("Failed to initialize NVS! Error: %u", err); } -#ifdef CONFIG_BT_ENABLED +#if defined(CONFIG_BT_ENABLED) && SOC_BT_SUPPORTED if (!btInUse()) { esp_bt_controller_mem_release(ESP_BT_MODE_BTDM); } From 9e2f75564127a9853f80f3eb637b264406cb2f30 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 5 Mar 2025 08:33:20 -0300 Subject: [PATCH 02/15] test(i2c): Add test to scan bus (#11022) * test(i2c): Add test to scan bus * test(i2c): Add scan test with wifi running * fix(i2c): Simplify test --- tests/validation/i2c_master/i2c_master.ino | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/validation/i2c_master/i2c_master.ino b/tests/validation/i2c_master/i2c_master.ino index 3c7b2d9824a..9b4cc508a35 100644 --- a/tests/validation/i2c_master/i2c_master.ino +++ b/tests/validation/i2c_master/i2c_master.ino @@ -5,6 +5,11 @@ #include #include #include +#include +#include +#include + +#include "sdkconfig.h" /* DS1307 functions */ @@ -24,6 +29,9 @@ static uint8_t read_month = 0; static uint16_t read_year = 0; static int peek_data = -1; +const char *ssid = "Wokwi-GUEST"; +const char *password = ""; + const auto BCD2DEC = [](uint8_t num) -> uint8_t { return ((num / 16 * 10) + (num % 16)); }; @@ -245,6 +253,42 @@ void test_api() { Wire.flush(); } +bool device_found() { + uint8_t err; + + for (uint8_t address = 1; address < 127; ++address) { + Wire.beginTransmission(address); + err = Wire.endTransmission(); + log_d("Address: 0x%02X, Error: %d", address, err); + if (err == 0) { + log_i("Found device at address: 0x%02X", address); + } else if (address == DS1307_ADDR) { + log_e("Failed to find DS1307"); + return false; + } + } + + return true; +} + +void scan_bus() { + TEST_ASSERT_TRUE(device_found()); +} + +#if SOC_WIFI_SUPPORTED +void scan_bus_with_wifi() { + // delete old config + WiFi.disconnect(true, true, 1000); + delay(1000); + WiFi.begin(ssid, password); + delay(5000); + bool found = device_found(); + WiFi.disconnect(true, true, 1000); + + TEST_ASSERT_TRUE(found); +} +#endif + /* Main */ void setup() { @@ -258,6 +302,10 @@ void setup() { log_d("Starting tests"); UNITY_BEGIN(); + RUN_TEST(scan_bus); +#if SOC_WIFI_SUPPORTED + RUN_TEST(scan_bus_with_wifi); +#endif RUN_TEST(rtc_set_time); RUN_TEST(rtc_run_clock); RUN_TEST(change_clock); From fb5f11b638b377398e6320d48065e8515248d527 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Fri, 7 Mar 2025 19:00:58 -0300 Subject: [PATCH 03/15] feat(matter): necessary changes to insights version for esp_matter (#11042) * feat(matter): necessary changes to insights version for esp_matter * feat(rainmaker): update RainMaker version to 1.5.2 --- idf_component.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/idf_component.yml b/idf_component.yml index 94a69caec2f..967c4ecf0f6 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -69,7 +69,7 @@ dependencies: espressif/network_provisioning: version: "1.0.2" espressif/esp_rainmaker: - version: "1.5.0" + version: "1.5.2" rules: - if: "target not in [esp32c2, esp32p4]" espressif/rmaker_common: @@ -77,16 +77,16 @@ dependencies: rules: - if: "target not in [esp32c2, esp32p4]" espressif/esp_insights: - version: "1.0.1" + version: "1.2.2" rules: - if: "target not in [esp32c2, esp32p4]" # New version breaks esp_insights 1.0.1 espressif/esp_diag_data_store: - version: "1.0.1" + version: "1.0.2" rules: - if: "target not in [esp32c2, esp32p4]" espressif/esp_diagnostics: - version: "1.0.2" + version: "1.2.1" rules: - if: "target not in [esp32c2, esp32p4]" espressif/cbor: From efb02d30ac1b863490a9de49374b18890e84b1f3 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sun, 9 Mar 2025 08:20:59 -0300 Subject: [PATCH 04/15] feat(gpio): allows mixing digital and analog read/write operations (#11016) * feat(gpio): allows mixing digital and analog read/write operations * fix(gpio): simple mistake in calling __pinMode() fnuction * fix(gpio): simple mistake in calling __pinMode() fnuction * feat(gpio): update the log message to tell the solution for the error. * feat(gpio): warn user about digitalRead() used with non GPIO pin * fix(gpio): wrong peripheral manager test case --- cores/esp32/esp32-hal-gpio.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index b11636daf81..c681be077b3 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -173,7 +173,7 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) { if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) { gpio_set_level((gpio_num_t)pin, val); } else { - log_e("IO %i is not set as GPIO.", pin); + log_e("IO %i is not set as GPIO. Execute digitalMode(%i, OUTPUT) first.", pin, pin); } } @@ -182,14 +182,12 @@ extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin) { if (pin == RGB_BUILTIN) { return RGB_BUILTIN_storage; } -#endif - - if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) { - return gpio_get_level((gpio_num_t)pin); - } else { - log_e("IO %i is not set as GPIO.", pin); - return 0; +#endif // RGB_BUILTIN + // This work when the pin is set as GPIO and in INPUT mode. For all other pin functions, it may return inconsistent response + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL) { + log_w("IO %i is not set as GPIO. digitalRead() may return an inconsistent value."); } + return gpio_get_level((gpio_num_t)pin); } static void ARDUINO_ISR_ATTR __onPinInterrupt(void *arg) { From 4677ea6ad82d3bb78bec9b10edbe2745fe5a0fc0 Mon Sep 17 00:00:00 2001 From: Oli Date: Mon, 10 Mar 2025 11:53:43 +0000 Subject: [PATCH 05/15] Fix to issue #11044 (#11064) Fix to a copy-paste error that causes a Guru Meditation crash with Zigbee Analog Example. --- libraries/Zigbee/src/ep/ZigbeeAnalog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp b/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp index 9d1b53fd310..b6d581450aa 100644 --- a/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp @@ -105,7 +105,7 @@ void ZigbeeAnalog::setAnalogInputReporting(uint16_t min_interval, uint16_t max_i memset(&reporting_info, 0, sizeof(esp_zb_zcl_reporting_info_t)); reporting_info.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV; reporting_info.ep = _endpoint; - reporting_info.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + reporting_info.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT; reporting_info.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE; reporting_info.attr_id = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID; reporting_info.u.send_info.min_interval = min_interval; From 8575d04ab54789bac24ebe3a1c6428a8246ac897 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 10 Mar 2025 21:19:22 +0200 Subject: [PATCH 06/15] fix(eth): Fix RMII Ethernet not being able to be restarted (#11048) --- libraries/Ethernet/src/ETH.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index bf63de8724d..f347616c340 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -271,8 +271,8 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i eth_mac_config.sw_reset_timeout_ms = 1000; eth_mac_config.rx_task_stack_size = _task_stack_size; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config, ð_mac_config); - if (mac == NULL) { + _mac = esp_eth_mac_new_esp32(&mac_config, ð_mac_config); + if (_mac == NULL) { log_e("esp_eth_mac_new_esp32 failed"); return false; } @@ -281,26 +281,25 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i phy_config.phy_addr = phy_addr; phy_config.reset_gpio_num = _pin_power; - esp_eth_phy_t *phy = NULL; switch (type) { #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) - case ETH_PHY_GENERIC: phy = esp_eth_phy_new_generic(&phy_config); break; + case ETH_PHY_GENERIC: _phy = esp_eth_phy_new_generic(&phy_config); break; #endif - case ETH_PHY_LAN8720: phy = esp_eth_phy_new_lan87xx(&phy_config); break; - case ETH_PHY_TLK110: phy = esp_eth_phy_new_ip101(&phy_config); break; - case ETH_PHY_RTL8201: phy = esp_eth_phy_new_rtl8201(&phy_config); break; - case ETH_PHY_DP83848: phy = esp_eth_phy_new_dp83848(&phy_config); break; - case ETH_PHY_KSZ8041: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; - case ETH_PHY_KSZ8081: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; + case ETH_PHY_LAN8720: _phy = esp_eth_phy_new_lan87xx(&phy_config); break; + case ETH_PHY_TLK110: _phy = esp_eth_phy_new_ip101(&phy_config); break; + case ETH_PHY_RTL8201: _phy = esp_eth_phy_new_rtl8201(&phy_config); break; + case ETH_PHY_DP83848: _phy = esp_eth_phy_new_dp83848(&phy_config); break; + case ETH_PHY_KSZ8041: _phy = esp_eth_phy_new_ksz80xx(&phy_config); break; + case ETH_PHY_KSZ8081: _phy = esp_eth_phy_new_ksz80xx(&phy_config); break; default: log_e("Unsupported PHY %d", type); break; } - if (phy == NULL) { + if (_phy == NULL) { log_e("esp_eth_phy_new failed"); return false; } _eth_handle = NULL; - esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); + esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(_mac, _phy); ret = esp_eth_driver_install(ð_config, &_eth_handle); if (ret != ESP_OK) { log_e("Ethernet driver install failed: %d", ret); From eeb6a26ed1e25e723b9660986567ddd1c174d27c Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 10 Mar 2025 21:19:46 +0200 Subject: [PATCH 07/15] fix(wifi): Disable properly LR mode if it was enabled before (#11052) * fix(wifi): Disable properly LR mode if it was enabled before * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- libraries/WiFi/src/WiFiGeneric.cpp | 70 ++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 40e3b12c687..aa994963514 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -308,7 +308,7 @@ bool wifiLowLevelInit(bool persistent) { esp_err_t err = esp_wifi_init(&cfg); if (err) { - log_e("esp_wifi_init %d", err); + log_e("esp_wifi_init 0x%x: %s", err, esp_err_to_name(err)); lowLevelInitDone = false; return lowLevelInitDone; } @@ -375,7 +375,7 @@ static bool espWiFiStart() { esp_err_t err = esp_wifi_start(); if (err != ESP_OK) { _esp_wifi_started = false; - log_e("esp_wifi_start %d", err); + log_e("esp_wifi_start 0x%x: %s", err, esp_err_to_name(err)); return _esp_wifi_started; } return _esp_wifi_started; @@ -389,7 +389,7 @@ static bool espWiFiStop() { _esp_wifi_started = false; err = esp_wifi_stop(); if (err) { - log_e("Could not stop WiFi! %d", err); + log_e("Could not stop WiFi! 0x%x: %s", err, esp_err_to_name(err)); _esp_wifi_started = true; return false; } @@ -478,7 +478,7 @@ int WiFiGenericClass::setChannel(uint8_t primary, wifi_second_chan_t secondary) ret = esp_wifi_get_country(&country); if (ret != ESP_OK) { - log_e("Failed to get country info"); + log_e("Failed to get country info 0x%x: %s", ret, esp_err_to_name(ret)); return ret; } @@ -492,7 +492,7 @@ int WiFiGenericClass::setChannel(uint8_t primary, wifi_second_chan_t secondary) ret = esp_wifi_set_channel(primary, secondary); if (ret != ESP_OK) { - log_e("Failed to set channel"); + log_e("Failed to set channel 0x%x: %s", ret, esp_err_to_name(ret)); return ret; } @@ -562,13 +562,13 @@ bool WiFiGenericClass::mode(wifi_mode_t m) { if (((m & WIFI_MODE_STA) != 0) && ((cm & WIFI_MODE_STA) == 0)) { err = esp_netif_set_hostname(esp_netifs[ESP_IF_WIFI_STA], NetworkManager::getHostname()); if (err) { - log_e("Could not set hostname! %d", err); + log_e("Could not set hostname! 0x%x: %s", err, esp_err_to_name(err)); return false; } } err = esp_wifi_set_mode(m); if (err) { - log_e("Could not set mode! %d", err); + log_e("Could not set mode! 0x%x: %s", err, esp_err_to_name(err)); return false; } @@ -585,17 +585,44 @@ bool WiFiGenericClass::mode(wifi_mode_t m) { if (m & WIFI_MODE_STA) { err = esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_LR); if (err != ESP_OK) { - log_e("Could not enable long range on STA! %d", err); + log_e("Could not enable long range on STA! 0x%x: %s", err, esp_err_to_name(err)); return false; } } if (m & WIFI_MODE_AP) { err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_LR); if (err != ESP_OK) { - log_e("Could not enable long range on AP! %d", err); + log_e("Could not enable long range on AP! 0x%x: %s", err, esp_err_to_name(err)); return false; } } + } else { +#if CONFIG_SOC_WIFI_HE_SUPPORT +#define WIFI_PROTOCOL_DEFAULT (WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX) +#else +#define WIFI_PROTOCOL_DEFAULT (WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N) +#endif + uint8_t current_protocol = 0; + if (m & WIFI_MODE_STA) { + err = esp_wifi_get_protocol(WIFI_IF_STA, ¤t_protocol); + if (err == ESP_OK && current_protocol == WIFI_PROTOCOL_LR) { + log_v("Disabling long range on STA"); + err = esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_DEFAULT); + if (err != ESP_OK) { + log_e("Could not disable long range on STA! 0x%x: %s", err, esp_err_to_name(err)); + } + } + } + if (m & WIFI_MODE_AP) { + err = esp_wifi_get_protocol(WIFI_IF_AP, ¤t_protocol); + if (err == ESP_OK && current_protocol == WIFI_PROTOCOL_LR) { + log_v("Disabling long range on AP"); + err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_DEFAULT); + if (err != ESP_OK) { + log_e("Could not disable long range on AP! 0x%x: %s", err, esp_err_to_name(err)); + } + } + } } if (!espWiFiStart()) { return false; @@ -683,8 +710,9 @@ bool WiFiGenericClass::setSleep(wifi_ps_type_t sleepType) { if (sleepType != _sleepEnabled) { _sleepEnabled = sleepType; if (WiFi.STA.started()) { - if (esp_wifi_set_ps(_sleepEnabled) != ESP_OK) { - log_e("esp_wifi_set_ps failed!"); + esp_err_t err = esp_wifi_set_ps(_sleepEnabled); + if (err != ESP_OK) { + log_e("esp_wifi_set_ps failed!: 0x%x: %s", err, esp_err_to_name(err)); return false; } } @@ -748,8 +776,9 @@ bool WiFiGenericClass::initiateFTM(uint8_t frm_count, uint16_t burst_period, uin memcpy(ftmi_cfg.resp_mac, mac, 6); } // Request FTM session with the Responder - if (ESP_OK != esp_wifi_ftm_initiate_session(&ftmi_cfg)) { - log_e("Failed to initiate FTM session"); + esp_err_t err = esp_wifi_ftm_initiate_session(&ftmi_cfg); + if (ESP_OK != err) { + log_e("Failed to initiate FTM session: 0x%x: %s", err, esp_err_to_name(err)); return false; } return true; @@ -768,8 +797,9 @@ bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2 esp_phy_ant_gpio_config_t wifi_ant_io; - if (ESP_OK != esp_phy_get_ant_gpio(&wifi_ant_io)) { - log_e("Failed to get antenna configuration"); + esp_err_t err = esp_phy_get_ant_gpio(&wifi_ant_io); + if (ESP_OK != err) { + log_e("Failed to get antenna configuration: 0x%x: %s", err, esp_err_to_name(err)); return false; } @@ -778,8 +808,9 @@ bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2 wifi_ant_io.gpio_cfg[1].gpio_num = gpio_ant2; wifi_ant_io.gpio_cfg[1].gpio_select = 1; - if (ESP_OK != esp_phy_set_ant_gpio(&wifi_ant_io)) { - log_e("Failed to set antenna GPIO configuration"); + err = esp_phy_set_ant_gpio(&wifi_ant_io); + if (ESP_OK != err) { + log_e("Failed to set antenna GPIO configuration: 0x%x: %s", err, esp_err_to_name(err)); return false; } @@ -827,8 +858,9 @@ bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2 } set_ant: - if (ESP_OK != esp_phy_set_ant(&ant_config)) { - log_e("Failed to set antenna configuration"); + err = esp_phy_set_ant(&ant_config); + if (ESP_OK != err) { + log_e("Failed to set antenna configuration: 0x%x: %s", err, esp_err_to_name(err)); return false; } #endif From bf5265c7d8330d741993bc977c7eb1bfcf8716e1 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 10 Mar 2025 21:20:07 +0200 Subject: [PATCH 08/15] feat(eth): Add setters for negotiation, speed and duplex modes (#11053) * feat(eth): Add setters for negotiation, speed and duplex modes * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- libraries/Ethernet/src/ETH.cpp | 37 +++++++++++++++++++++++++++++++++- libraries/Ethernet/src/ETH.h | 8 +++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index f347616c340..542a7e2a218 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -1009,6 +1009,18 @@ bool ETHClass::fullDuplex() const { return (link_duplex == ETH_DUPLEX_FULL); } +bool ETHClass::setFullDuplex(bool on) { + if (_eth_handle == NULL) { + return false; + } + eth_duplex_t link_duplex = on ? ETH_DUPLEX_FULL : ETH_DUPLEX_HALF; + esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_DUPLEX_MODE, &link_duplex); + if (err != ESP_OK) { + log_e("Failed to set duplex mode: 0x%x: %s", err, esp_err_to_name(err)); + } + return err == ESP_OK; +} + bool ETHClass::autoNegotiation() const { if (_eth_handle == NULL) { return false; @@ -1018,6 +1030,17 @@ bool ETHClass::autoNegotiation() const { return auto_nego; } +bool ETHClass::setAutoNegotiation(bool on) { + if (_eth_handle == NULL) { + return false; + } + esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_AUTONEGO, &on); + if (err != ESP_OK) { + log_e("Failed to set auto negotiation: 0x%x: %s", err, esp_err_to_name(err)); + } + return err == ESP_OK; +} + uint32_t ETHClass::phyAddr() const { if (_eth_handle == NULL) { return 0; @@ -1027,7 +1050,7 @@ uint32_t ETHClass::phyAddr() const { return phy_addr; } -uint8_t ETHClass::linkSpeed() const { +uint16_t ETHClass::linkSpeed() const { if (_eth_handle == NULL) { return 0; } @@ -1036,6 +1059,18 @@ uint8_t ETHClass::linkSpeed() const { return (link_speed == ETH_SPEED_10M) ? 10 : 100; } +bool ETHClass::setLinkSpeed(uint16_t speed) { + if (_eth_handle == NULL) { + return false; + } + eth_speed_t link_speed = (speed == 10) ? ETH_SPEED_10M : ETH_SPEED_100M; + esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_SPEED, &link_speed); + if (err != ESP_OK) { + log_e("Failed to set link speed: 0x%x: %s", err, esp_err_to_name(err)); + } + return err == ESP_OK; +} + // void ETHClass::getMac(uint8_t* mac) // { // if(_eth_handle != NULL && mac != NULL){ diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index cbddac065b9..891863e34bf 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -192,8 +192,14 @@ class ETHClass : public NetworkInterface { // ETH Handle APIs bool fullDuplex() const; - uint8_t linkSpeed() const; + bool setFullDuplex(bool on); + + uint16_t linkSpeed() const; + bool setLinkSpeed(uint16_t speed); //10 or 100 + bool autoNegotiation() const; + bool setAutoNegotiation(bool on); + uint32_t phyAddr() const; esp_eth_handle_t handle() const; From 665d6f8e8d2dec4e2ea7835d02d2033c9c5c788f 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, 10 Mar 2025 20:20:34 +0100 Subject: [PATCH 09/15] fix(zigbee): Use correct attributeID in setAnalogInputReporting (#11065) --- libraries/Zigbee/src/ep/ZigbeeAnalog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp b/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp index b6d581450aa..92cfaa09da6 100644 --- a/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp @@ -107,7 +107,7 @@ void ZigbeeAnalog::setAnalogInputReporting(uint16_t min_interval, uint16_t max_i reporting_info.ep = _endpoint; reporting_info.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT; reporting_info.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE; - reporting_info.attr_id = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID; + reporting_info.attr_id = ESP_ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID; reporting_info.u.send_info.min_interval = min_interval; reporting_info.u.send_info.max_interval = max_interval; reporting_info.u.send_info.def_min_interval = min_interval; From 2276f0b79401ffd63f7719975461dd0c5f68155a 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, 10 Mar 2025 20:21:00 +0100 Subject: [PATCH 10/15] fix(zigbee): Add manuf_code to report attribure commands (#11066) --- .../Zigbee_Temp_Hum_Sensor_Sleepy.ino | 4 ++-- libraries/Zigbee/src/ep/ZigbeeAnalog.cpp | 1 + libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp | 1 + libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp | 1 + libraries/Zigbee/src/ep/ZigbeeOccupancySensor.cpp | 1 + libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp | 1 + libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp | 2 ++ 7 files changed, 9 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 60bd784cca9..65df4b02957 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 @@ -125,8 +125,8 @@ void loop() { int startTime = millis(); while (digitalRead(button) == LOW) { delay(50); - if ((millis() - startTime) > 3000) { - // If key pressed for more than 3secs, factory reset Zigbee and reboot + if ((millis() - startTime) > 10000) { + // If key pressed for more than 10secs, factory reset Zigbee and reboot Serial.println("Resetting Zigbee to factory and rebooting in 1s."); delay(1000); Zigbee.factoryReset(); diff --git a/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp b/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp index 92cfaa09da6..417eeb6d98c 100644 --- a/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp @@ -93,6 +93,7 @@ void ZigbeeAnalog::reportAnalogInput() { report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT; report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); diff --git a/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp index f7c0a19bc78..2718d9275c2 100644 --- a/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp @@ -85,6 +85,7 @@ void ZigbeeCarbonDioxideSensor::report() { report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_MEASUREMENT; report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); diff --git a/libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp index d8fea88342e..11fbf7c906b 100644 --- a/libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp @@ -79,6 +79,7 @@ void ZigbeeFlowSensor::report() { report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_FLOW_MEASUREMENT; report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); diff --git a/libraries/Zigbee/src/ep/ZigbeeOccupancySensor.cpp b/libraries/Zigbee/src/ep/ZigbeeOccupancySensor.cpp index 830e4397137..31a1f7e90e1 100644 --- a/libraries/Zigbee/src/ep/ZigbeeOccupancySensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeOccupancySensor.cpp @@ -49,6 +49,7 @@ void ZigbeeOccupancySensor::report() { report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING; report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); diff --git a/libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp b/libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp index 44e3eace610..21456a51511 100644 --- a/libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp @@ -75,6 +75,7 @@ void ZigbeePressureSensor::report() { report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_PRESSURE_MEASUREMENT; report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); diff --git a/libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp index c3991593422..b3ff03f0a6b 100644 --- a/libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp @@ -74,6 +74,7 @@ void ZigbeeTempSensor::reportTemperature() { report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); @@ -116,6 +117,7 @@ void ZigbeeTempSensor::reportHumidity() { report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT; report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); From e680e7b538026a88616b8247a8909e10fcc64843 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 10 Mar 2025 16:21:25 -0300 Subject: [PATCH 11/15] fix(matter): removes a few matter 1.4 / IDF 5.4 compilation warning messages (#11067) * fix(matter): uninitialized fields warning * fix(matter): uninitialized fields warning --- libraries/Matter/src/MatterEndpoints/MatterColorLight.h | 4 ++-- .../Matter/src/MatterEndpoints/MatterEnhancedColorLight.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Matter/src/MatterEndpoints/MatterColorLight.h b/libraries/Matter/src/MatterEndpoints/MatterColorLight.h index b896afa9b7a..99449addd50 100644 --- a/libraries/Matter/src/MatterEndpoints/MatterColorLight.h +++ b/libraries/Matter/src/MatterEndpoints/MatterColorLight.h @@ -66,8 +66,8 @@ class MatterColorLight : public MatterEndPoint { protected: bool started = false; - bool onOffState = false; // default initial state is off, but it can be changed by begin(bool) - espHsvColor_t colorHSV = {0}; // default initial color HSV is black, but it can be changed by begin(bool, espHsvColor_t) + bool onOffState = false; // default initial state is off, but it can be changed by begin(bool) + espHsvColor_t colorHSV = {0, 0, 0}; // default initial color HSV is black, but it can be changed by begin(bool, espHsvColor_t) EndPointOnOffCB _onChangeOnOffCB = NULL; EndPointRGBColorCB _onChangeColorCB = NULL; EndPointCB _onChangeCB = NULL; diff --git a/libraries/Matter/src/MatterEndpoints/MatterEnhancedColorLight.h b/libraries/Matter/src/MatterEndpoints/MatterEnhancedColorLight.h index ff6e69e3e65..a4baef968a4 100644 --- a/libraries/Matter/src/MatterEndpoints/MatterEnhancedColorLight.h +++ b/libraries/Matter/src/MatterEndpoints/MatterEnhancedColorLight.h @@ -91,7 +91,7 @@ class MatterEnhancedColorLight : public MatterEndPoint { bool started = false; bool onOffState = false; // default initial state is off, but it can be changed by begin(bool) uint8_t brightnessLevel = 0; // default initial brightness is 0, but it can be changed by begin(bool, uint8_t) - espHsvColor_t colorHSV = {0}; // default initial color HSV is black, but it can be changed by begin(bool, uint8_t, espHsvColor_t) + espHsvColor_t colorHSV = {0, 0, 0}; // default initial color HSV is black, but it can be changed by begin(bool, uint8_t, espHsvColor_t) uint16_t colorTemperatureLevel = 0; // default initial color temperature is 0, but it can be changed by begin(bool, uint8_t, espHsvColor_t, uint16_t) EndPointOnOffCB _onChangeOnOffCB = NULL; EndPointBrightnessCB _onChangeBrightnessCB = NULL; From d9dbc4af41efdceb958aa05925f0eeacec679d78 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 10 Mar 2025 17:00:34 -0300 Subject: [PATCH 12/15] fix(matter): examples must set pin to Digital Mode after analogWrite() and before digitalWrite() (#11070) * fix(matter): itshall set digital mode before digitalWrite * fix(matter): example must set pin in digital mode before writting * fix(matter): example shall set digital mode before writing * fix(matter): digitalMode necessary before digitalWrite(LOW) * fix(matter): example must set digital mode after analogwrite * fix(matter): wrong copy paste * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- .../Matter/examples/MatterColorLight/MatterColorLight.ino | 4 ++++ .../examples/MatterDimmableLight/MatterDimmableLight.ino | 4 ++++ .../MatterEnhancedColorLight/MatterEnhancedColorLight.ino | 4 ++++ libraries/Matter/examples/MatterFan/MatterFan.ino | 4 ++++ .../MatterTemperatureLight/MatterTemperatureLight.ino | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/libraries/Matter/examples/MatterColorLight/MatterColorLight.ino b/libraries/Matter/examples/MatterColorLight/MatterColorLight.ino index dd1724f602d..f3e45887576 100644 --- a/libraries/Matter/examples/MatterColorLight/MatterColorLight.ino +++ b/libraries/Matter/examples/MatterColorLight/MatterColorLight.ino @@ -60,6 +60,10 @@ bool setLightState(bool state, espHsvColor_t colorHSV) { analogWrite(ledPin, colorHSV.v); #endif } else { +#ifndef RGB_BUILTIN + // after analogWrite(), it is necessary to set the GPIO to digital mode first + pinMode(ledPin, OUTPUT); +#endif digitalWrite(ledPin, LOW); } // store last HSV Color and OnOff state for when the Light is restarted / power goes off diff --git a/libraries/Matter/examples/MatterDimmableLight/MatterDimmableLight.ino b/libraries/Matter/examples/MatterDimmableLight/MatterDimmableLight.ino index cb8b8b6f17f..79751905c20 100644 --- a/libraries/Matter/examples/MatterDimmableLight/MatterDimmableLight.ino +++ b/libraries/Matter/examples/MatterDimmableLight/MatterDimmableLight.ino @@ -56,6 +56,10 @@ bool setLightState(bool state, uint8_t brightness) { analogWrite(ledPin, brightness); #endif } else { +#ifndef RGB_BUILTIN + // after analogWrite(), it is necessary to set the GPIO to digital mode first + pinMode(ledPin, OUTPUT); +#endif digitalWrite(ledPin, LOW); } // store last Brightness and OnOff state for when the Light is restarted / power goes off diff --git a/libraries/Matter/examples/MatterEnhancedColorLight/MatterEnhancedColorLight.ino b/libraries/Matter/examples/MatterEnhancedColorLight/MatterEnhancedColorLight.ino index bd2d13899ca..8e12581fdf2 100644 --- a/libraries/Matter/examples/MatterEnhancedColorLight/MatterEnhancedColorLight.ino +++ b/libraries/Matter/examples/MatterEnhancedColorLight/MatterEnhancedColorLight.ino @@ -64,6 +64,10 @@ bool setLightState(bool state, espHsvColor_t colorHSV, uint8_t brighteness, uint analogWrite(ledPin, colorHSV.v); #endif } else { +#ifndef RGB_BUILTIN + // after analogWrite(), it is necessary to set the GPIO to digital mode first + pinMode(ledPin, OUTPUT); +#endif digitalWrite(ledPin, LOW); } // store last HSV Color and OnOff state for when the Light is restarted / power goes off diff --git a/libraries/Matter/examples/MatterFan/MatterFan.ino b/libraries/Matter/examples/MatterFan/MatterFan.ino index 1094126a843..705aa4853da 100644 --- a/libraries/Matter/examples/MatterFan/MatterFan.ino +++ b/libraries/Matter/examples/MatterFan/MatterFan.ino @@ -49,6 +49,10 @@ void fanDCMotorDrive(bool fanState, uint8_t speedPercent) { // drive the Fan DC motor if (fanState == false) { // turn off the Fan +#ifndef RGB_BUILTIN + // after analogWrite(), it is necessary to set the GPIO to digital mode first + pinMode(dcMotorPin, OUTPUT); +#endif digitalWrite(dcMotorPin, LOW); } else { // set the Fan speed diff --git a/libraries/Matter/examples/MatterTemperatureLight/MatterTemperatureLight.ino b/libraries/Matter/examples/MatterTemperatureLight/MatterTemperatureLight.ino index b814ba89704..d46427591ab 100644 --- a/libraries/Matter/examples/MatterTemperatureLight/MatterTemperatureLight.ino +++ b/libraries/Matter/examples/MatterTemperatureLight/MatterTemperatureLight.ino @@ -66,6 +66,10 @@ bool setLightState(bool state, uint8_t brightness, uint16_t temperature_Mireds) analogWrite(ledPin, brightness); #endif } else { +#ifndef RGB_BUILTIN + // after analogWrite(), it is necessary to set the GPIO to digital mode first + pinMode(ledPin, OUTPUT); +#endif digitalWrite(ledPin, LOW); } // store last Brightness and OnOff state for when the Light is restarted / power goes off From e8a243c1db973b5cdd68949c1dfc8c8bfd11c887 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 10 Mar 2025 17:18:12 -0300 Subject: [PATCH 13/15] fix(network): fixes a macro name conflict warning (#11068) * fix(network): fixes a macro name conflict warning * feat(networking): removed local maco definition in favor of IDF one --- libraries/Network/src/NetworkClient.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/Network/src/NetworkClient.cpp b/libraries/Network/src/NetworkClient.cpp index da83597d2c6..89411a42453 100644 --- a/libraries/Network/src/NetworkClient.cpp +++ b/libraries/Network/src/NetworkClient.cpp @@ -23,7 +23,11 @@ #include #include -#define IN6_IS_ADDR_V4MAPPED(a) ((((__const uint32_t *)(a))[0] == 0) && (((__const uint32_t *)(a))[1] == 0) && (((__const uint32_t *)(a))[2] == htonl(0xffff))) +// It is already defined in IDF as: +//#define IN6_IS_ADDR_V4MAPPED(a) ip6_addr_isipv4mappedipv6((ip6_addr_t*)(a)) +//#define ip6_addr_isipv4mappedipv6(ip6addr) (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL))) +// Keeping as a memory of the change. +//#define _IN6_IS_ADDR_V4MAPPED(a) ((((__const uint32_t *)(a))[0] == 0) && (((__const uint32_t *)(a))[1] == 0) && (((__const uint32_t *)(a))[2] == htonl(0xffff))) #define WIFI_CLIENT_DEF_CONN_TIMEOUT_MS (3000) #define WIFI_CLIENT_MAX_WRITE_RETRY (10) From bda7c4811728e538b4ea393a5be148cbb614daed Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Tue, 11 Mar 2025 00:26:18 +0200 Subject: [PATCH 14/15] IDF release/v5.4 d4aa25a3 (#11060) IDF release/v5.4 d4aa25a3 --- package/package_esp32_index.template.json | 68 +++++++++++------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index 5a37e95930a..249ab43acc6 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -42,7 +42,7 @@ { "packager": "esp32", "name": "esp32-arduino-libs", - "version": "idf-release_v5.4-bcb3c32d-v1" + "version": "idf-release_v5.4-d4aa25a3-v1" }, { "packager": "esp32", @@ -95,63 +95,63 @@ "tools": [ { "name": "esp32-arduino-libs", - "version": "idf-release_v5.4-bcb3c32d-v1", + "version": "idf-release_v5.4-d4aa25a3-v1", "systems": [ { "host": "i686-mingw32", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "checksum": "SHA-256:2ab7a8565d4eadd805c1d00c9a1550292d3287dc43efa166d7ad3ba5322344bb", - "size": "345570903" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "checksum": "SHA-256:81101d580ebafb78f71bd494f4f5162fd829279d18634282c0f8f95c9e928335", + "size": "350941396" }, { "host": "x86_64-mingw32", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "checksum": "SHA-256:2ab7a8565d4eadd805c1d00c9a1550292d3287dc43efa166d7ad3ba5322344bb", - "size": "345570903" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "checksum": "SHA-256:81101d580ebafb78f71bd494f4f5162fd829279d18634282c0f8f95c9e928335", + "size": "350941396" }, { "host": "arm64-apple-darwin", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "checksum": "SHA-256:2ab7a8565d4eadd805c1d00c9a1550292d3287dc43efa166d7ad3ba5322344bb", - "size": "345570903" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "checksum": "SHA-256:81101d580ebafb78f71bd494f4f5162fd829279d18634282c0f8f95c9e928335", + "size": "350941396" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "checksum": "SHA-256:2ab7a8565d4eadd805c1d00c9a1550292d3287dc43efa166d7ad3ba5322344bb", - "size": "345570903" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "checksum": "SHA-256:81101d580ebafb78f71bd494f4f5162fd829279d18634282c0f8f95c9e928335", + "size": "350941396" }, { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "checksum": "SHA-256:2ab7a8565d4eadd805c1d00c9a1550292d3287dc43efa166d7ad3ba5322344bb", - "size": "345570903" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "checksum": "SHA-256:81101d580ebafb78f71bd494f4f5162fd829279d18634282c0f8f95c9e928335", + "size": "350941396" }, { "host": "i686-pc-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "checksum": "SHA-256:2ab7a8565d4eadd805c1d00c9a1550292d3287dc43efa166d7ad3ba5322344bb", - "size": "345570903" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "checksum": "SHA-256:81101d580ebafb78f71bd494f4f5162fd829279d18634282c0f8f95c9e928335", + "size": "350941396" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "checksum": "SHA-256:2ab7a8565d4eadd805c1d00c9a1550292d3287dc43efa166d7ad3ba5322344bb", - "size": "345570903" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "checksum": "SHA-256:81101d580ebafb78f71bd494f4f5162fd829279d18634282c0f8f95c9e928335", + "size": "350941396" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-bcb3c32d-v1.zip", - "checksum": "SHA-256:2ab7a8565d4eadd805c1d00c9a1550292d3287dc43efa166d7ad3ba5322344bb", - "size": "345570903" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-d4aa25a3-v1.zip", + "checksum": "SHA-256:81101d580ebafb78f71bd494f4f5162fd829279d18634282c0f8f95c9e928335", + "size": "350941396" } ] }, From 07d6a5a0d2f774bd7b004b1bc647d601199a0489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Wed, 12 Mar 2025 14:38:09 +0100 Subject: [PATCH 15/15] feat(Zigbee): Adding Zigbee Wind speed sensor endpoint (#10455) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create ZigbeeWindSpeedSensor.h * Create ZigbeeWindSpeedSensor.cpp * Update ZigbeeWindSpeedSensor.cpp * Update ZigbeeWindSpeedSensor.cpp * Create ZigbeeWindSpeedSensor.ino * Update ZigbeeWindSpeedSensor.ino * Update ZigbeeWindSpeedSensor.ino * Create ci.json * Rename ZigbeeWindSpeedSensor.ino to Zigbee_Wind_Speed_Sensor.ino * Rename ci.json to ci.json * Update CMakeLists.txt * Update Zigbee_Wind_Speed_Sensor.ino * Update Zigbee_Wind_Speed_Sensor.ino * Update Zigbee_Wind_Speed_Sensor.ino * Update ZigbeeWindSpeedSensor.cpp * Update ZigbeeWindSpeedSensor.cpp Use ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID device id * feat(zigbee): Add windspeed sensor endpoint * Update Zigbee.h Add ZigbeeWindSpeedSensor.h * update example * add missing sdkconfig include * add readme * ci(pre-commit): Apply automatic fixes * Update README.md --------- Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- CMakeLists.txt | 1 + .../Zigbee_Wind_Speed_Sensor/README.md | 60 +++++++++ .../Zigbee_Wind_Speed_Sensor.ino | 119 ++++++++++++++++++ .../examples/Zigbee_Wind_Speed_Sensor/ci.json | 7 ++ libraries/Zigbee/src/Zigbee.h | 1 + .../Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp | 98 +++++++++++++++ .../Zigbee/src/ep/ZigbeeWindSpeedSensor.h | 56 +++++++++ 7 files changed, 342 insertions(+) create mode 100644 libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/README.md create mode 100644 libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/Zigbee_Wind_Speed_Sensor.ino create mode 100644 libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/ci.json create mode 100644 libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp create mode 100644 libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 32d17e5f68d..d2a9162a9ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -298,6 +298,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS libraries/Zigbee/src/ep/ZigbeeAnalog.cpp libraries/Zigbee/src/ep/ZigbeeRangeExtender.cpp libraries/Zigbee/src/ep/ZigbeeGateway.cpp + libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp ) set(ARDUINO_LIBRARY_BLE_SRCS diff --git a/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/README.md b/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/README.md new file mode 100644 index 00000000000..826c7666e6b --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/README.md @@ -0,0 +1,60 @@ +# Zigbee Wind Speed Sensor Integration with HomeAssistant ZHA + +This guide provides a workaround for integrating a Zigbee Wind Speed Sensor with HomeAssistant using the ZHA integration. Since the wind speed cluster is not natively supported, we will use the ZHA Toolkit from HACS to read the wind speed attribute and store it in a helper variable. +## Alternative Option: Creating a Custom Quirk + +For advanced users, a more robust solution is to create a custom quirk for your Zigbee Wind Speed Sensor. This approach involves writing a custom device handler that directly supports the wind speed cluster, providing a more seamless integration with HomeAssistant. + +Creating a custom quirk can be complex and requires familiarity with Python and the Zigbee protocol. However, it offers greater flexibility and control over your device's behavior. + +For more information and guidance on creating custom quirks, visit the [ZHA Device Handlers repository](https://github.com/zigpy/zha-device-handlers/). + +## Prerequisites + +- HomeAssistant installed and running +- Zigbee Wind Speed Sensor paired with HomeAssistant ZHA +- HACS (Home Assistant Community Store) installed. For more information, visit [HACS](https://hacs.xyz) + +## Steps + +### 1. Install ZHA Toolkit + +1. Open HomeAssistant. +2. Navigate to HACS > Integrations. +3. Search for "ZHA Toolkit - Service for advanced Zigbee Usage" and install it. For more information, visit the [ZHA Toolkit repository](https://github.com/mdeweerd/zha-toolkit). +4. Restart HomeAssistant to apply changes. + +### 2. Create a Helper Variable + +1. Go to Configuration -> Devices & Services -> Helpers. +2. Click on "Add Helper" and select "Number". +3. Name the helper (e.g., `wind_speed`), set the minimum and maximum values, and save it. + +### 3. Create an Automation + +1. Go to Configuration > Automations & Scenes. +2. Click on "Add Automation" and choose "Start with an empty automation". +3. Set a name for the automation (e.g., `Read Wind Speed`). +4. Add a trigger: + - Trigger Type: Time Pattern + - Every: 30 seconds +5. Add an action (Then do): + - Action Type: ZHA Toolkit: Read Attribute + - Setup the action: + ```yaml + action: zha_toolkit.attr_read + metadata: {} + data: + ieee: f0:f5:bd:ff:fe:0e:61:30 #set device IEEE address + endpoint: 10 #set windspeed device endpoint + cluster: 1035 #use this windspeed cluster + attribute: 0 #read measurement value + state_id: input_number.wind_speed #save to created helper variable + state_value_template: value/100 #use correct value format (convert u16 to float) + ``` +6. Save the automation. + +## Conclusion + +By following these steps, you can successfully integrate your Zigbee Wind Speed Sensor with HomeAssistant using the ZHA integration and ZHA Toolkit. The wind speed readings will be updated every 30 seconds and stored in the helper variable for use in your HomeAssistant setup. +The helper variable `wind_speed` is now an entity in HomeAssistant. You can use this entity to display the wind speed on your dashboard or in other automations. diff --git a/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/Zigbee_Wind_Speed_Sensor.ino b/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/Zigbee_Wind_Speed_Sensor.ino new file mode 100644 index 00000000000..1c24df9a091 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/Zigbee_Wind_Speed_Sensor.ino @@ -0,0 +1,119 @@ +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @brief This example demonstrates Zigbee windspeed sensor. + * + * The example demonstrates how to use Zigbee library to create a end device wind speed sensor. + * The wind speed sensor is a Zigbee end device, which is controlled by a Zigbee coordinator. + * + * Proper Zigbee mode must be selected in Tools->Zigbee mode + * and also the correct partition scheme must be selected in Tools->Partition Scheme. + * + * Please check the README.md for instructions and more detailed description. + * + * Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/) + */ + +#ifndef ZIGBEE_MODE_ED +#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode" +#endif + +#include "Zigbee.h" + +#define BUTTON_PIN 9 //Boot button for C6/H2 +#define WIND_SPEED_SENSOR_ENDPOINT_NUMBER 10 + +ZigbeeWindSpeedSensor zbWindSpeedSensor = ZigbeeWindSpeedSensor(WIND_SPEED_SENSOR_ENDPOINT_NUMBER); + +/************************ WindSpeed sensor *****************************/ +static void windspeed_sensor_value_update(void *arg) { + for (;;) { + // Read wind speed sensor value (simulated now by temperature sensor) + float windspeed = temperatureRead(); + log_v("Wind speed sensor value: %.2fm/s", windspeed); + // Update windspeed value in Windspeed sensor EP + zbWindSpeedSensor.setWindSpeed(windspeed); + delay(1000); + } +} + +/********************* Arduino functions **************************/ +void setup() { + Serial.begin(115200); + while (!Serial) { + delay(10); + } + + // Init button switch + pinMode(BUTTON_PIN, INPUT); + + // Optional: set Zigbee device name and model + zbWindSpeedSensor.setManufacturerAndModel("Espressif", "ZigbeeWindSpeedSensor"); + + // Set minimum and maximum windspeed measurement value in m/s + zbWindSpeedSensor.setMinMaxValue(0, 50); + + // Set tolerance for windspeed measurement in m/s (lowest possible value is 0.01 m/s) + zbWindSpeedSensor.setTolerance(1); + + // Add endpoint to Zigbee Core + Zigbee.addEndpoint(&zbWindSpeedSensor); + + Serial.println("Starting Zigbee..."); + // When all EPs are registered, start Zigbee in End Device mode + if (!Zigbee.begin()) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } else { + Serial.println("Zigbee started successfully!"); + } + Serial.println("Connecting to network"); + while (!Zigbee.connected()) { + Serial.print("."); + delay(100); + } + Serial.println(); + + // Start Wind speed sensor reading task + xTaskCreate(windspeed_sensor_value_update, "wind_speed_sensor_update", 2048, NULL, 10, NULL); + + // Set reporting interval for windspeed measurement in seconds, must be called after Zigbee.begin() + // min_interval and max_interval in seconds, delta (WindSpeed change in m/s) + // if min = 1 and max = 0, reporting is sent only when windspeed changes by delta + // if min = 0 and max = 10, reporting is sent every 10 seconds or windspeed changes by delta + // if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of windspeed change + zbWindSpeedSensor.setReporting(1, 0, 1); +} + +void loop() { + // Checking button for factory reset + if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed + // Key debounce handling + delay(100); + int startTime = millis(); + while (digitalRead(BUTTON_PIN) == LOW) { + delay(50); + if ((millis() - startTime) > 3000) { + // If key pressed for more than 3secs, factory reset Zigbee and reboot + Serial.println("Resetting Zigbee to factory and rebooting in 1s."); + delay(1000); + Zigbee.factoryReset(); + } + } + zbWindSpeedSensor.reportWindSpeed(); + } + delay(100); +} diff --git a/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/ci.json b/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/ci.json new file mode 100644 index 00000000000..ceacc367801 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Wind_Speed_Sensor/ci.json @@ -0,0 +1,7 @@ +{ + "fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed", + "requires": [ + "CONFIG_SOC_IEEE802154_SUPPORTED=y", + "CONFIG_ZB_ENABLED=y" + ] +} diff --git a/libraries/Zigbee/src/Zigbee.h b/libraries/Zigbee/src/Zigbee.h index 9ccf1e7d8f2..e5f669ba899 100644 --- a/libraries/Zigbee/src/Zigbee.h +++ b/libraries/Zigbee/src/Zigbee.h @@ -25,3 +25,4 @@ #include "ep/ZigbeeVibrationSensor.h" #include "ep/ZigbeeRangeExtender.h" #include "ep/ZigbeeGateway.h" +#include "ep/ZigbeeWindSpeedSensor.h" diff --git a/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp new file mode 100644 index 00000000000..d93b02adbc3 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp @@ -0,0 +1,98 @@ +#include "ZigbeeWindSpeedSensor.h" +#if CONFIG_ZB_ENABLED + +esp_zb_cluster_list_t *zigbee_wind_speed_sensor_clusters_create(zigbee_wind_speed_sensor_cfg_t *wind_speed_sensor) { + esp_zb_basic_cluster_cfg_t *basic_cfg = wind_speed_sensor ? &(wind_speed_sensor->basic_cfg) : NULL; + esp_zb_identify_cluster_cfg_t *identify_cfg = wind_speed_sensor ? &(wind_speed_sensor->identify_cfg) : NULL; + esp_zb_wind_speed_measurement_cluster_cfg_t *wind_speed_cfg = wind_speed_sensor ? &(wind_speed_sensor->wind_speed_meas_cfg) : NULL; + esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_cluster_list_add_basic_cluster(cluster_list, esp_zb_basic_cluster_create(basic_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(identify_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_wind_speed_measurement_cluster( + cluster_list, esp_zb_wind_speed_measurement_cluster_create(wind_speed_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE + ); + return cluster_list; +} + +// There is no device_id for wind speed sensor, we use a generic one +ZigbeeWindSpeedSensor::ZigbeeWindSpeedSensor(uint8_t endpoint) : ZigbeeEP(endpoint) { + _device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID; + + zigbee_wind_speed_sensor_cfg_t windspeed_sensor_cfg = ZIGBEE_DEFAULT_WIND_SPEED_SENSOR_CONFIG(); + _cluster_list = zigbee_wind_speed_sensor_clusters_create(&windspeed_sensor_cfg); + + _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID, .app_device_version = 0}; +} + +static uint16_t zb_windspeed_to_u16(float windspeed) { + return (uint16_t)(windspeed * 100); +} + +void ZigbeeWindSpeedSensor::setMinMaxValue(float min, float max) { + uint16_t zb_min = zb_windspeed_to_u16(min); + uint16_t zb_max = zb_windspeed_to_u16(max); + esp_zb_attribute_list_t *windspeed_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_WIND_SPEED_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + // + esp_zb_cluster_update_attr(windspeed_measure_cluster, ESP_ZB_ZCL_ATTR_WIND_SPEED_MEASUREMENT_MIN_MEASURED_VALUE_ID, (void *)&zb_min); + esp_zb_cluster_update_attr(windspeed_measure_cluster, ESP_ZB_ZCL_ATTR_WIND_SPEED_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&zb_max); +} + +void ZigbeeWindSpeedSensor::setTolerance(float tolerance) { + // Convert tolerance to ZCL uint16_t + uint16_t zb_tolerance = zb_windspeed_to_u16(tolerance); + esp_zb_attribute_list_t *windspeed_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_WIND_SPEED_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_wind_speed_measurement_cluster_add_attr(windspeed_measure_cluster, ESP_ZB_ZCL_ATTR_WIND_SPEED_MEASUREMENT_TOLERANCE_ID, (void *)&zb_tolerance); +} + +void ZigbeeWindSpeedSensor::setReporting(uint16_t min_interval, uint16_t max_interval, float delta) { + esp_zb_zcl_reporting_info_t reporting_info; + memset(&reporting_info, 0, sizeof(esp_zb_zcl_reporting_info_t)); + reporting_info.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV; + reporting_info.ep = _endpoint; + reporting_info.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_WIND_SPEED_MEASUREMENT; + reporting_info.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE; + reporting_info.attr_id = ESP_ZB_ZCL_ATTR_WIND_SPEED_MEASUREMENT_MEASURED_VALUE_ID; + reporting_info.u.send_info.min_interval = min_interval; + reporting_info.u.send_info.max_interval = max_interval; + reporting_info.u.send_info.def_min_interval = min_interval; + reporting_info.u.send_info.def_max_interval = max_interval; + reporting_info.u.send_info.delta.u16 = (uint16_t)(delta * 100); // Convert delta to ZCL uint16_t + reporting_info.dst.profile_id = ESP_ZB_AF_HA_PROFILE_ID; + reporting_info.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_update_reporting_info(&reporting_info); + esp_zb_lock_release(); +} + +void ZigbeeWindSpeedSensor::setWindSpeed(float windspeed) { + uint16_t zb_windspeed = zb_windspeed_to_u16(windspeed); + log_v("Updating windspeed sensor value..."); + /* Update windspeed sensor measured value */ + log_d("Setting windspeed to %d", zb_windspeed); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_set_attribute_val( + _endpoint, ESP_ZB_ZCL_CLUSTER_ID_WIND_SPEED_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_WIND_SPEED_MEASUREMENT_MEASURED_VALUE_ID, + &zb_windspeed, false + ); + esp_zb_lock_release(); +} + +void ZigbeeWindSpeedSensor::reportWindSpeed() { + /* Send report attributes command */ + esp_zb_zcl_report_attr_cmd_t report_attr_cmd; + report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_WIND_SPEED_MEASUREMENT_MEASURED_VALUE_ID; + report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; + report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_WIND_SPEED_MEASUREMENT; + report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); + esp_zb_lock_release(); + log_v("Wind speed measurement report sent"); +} + +#endif //CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.h b/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.h new file mode 100644 index 00000000000..e091d3ae548 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.h @@ -0,0 +1,56 @@ +/* Class of Zigbee WindSpeed sensor endpoint inherited from common EP class */ + +#pragma once + +#include "soc/soc_caps.h" +#include "sdkconfig.h" +#if CONFIG_ZB_ENABLED + +#include "ZigbeeEP.h" +#include "ha/esp_zigbee_ha_standard.h" + +#define ZIGBEE_DEFAULT_WIND_SPEED_SENSOR_CONFIG() \ + { \ + .basic_cfg = \ + { \ + .zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE, \ + .power_source = ESP_ZB_ZCL_BASIC_POWER_SOURCE_DEFAULT_VALUE, \ + }, \ + .identify_cfg = \ + { \ + .identify_time = ESP_ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE, \ + }, \ + .wind_speed_meas_cfg = { \ + .measured_value = ESP_ZB_ZCL_WIND_SPEED_MEASUREMENT_MEASURED_VALUE_DEFAULT, \ + .min_measured_value = ESP_ZB_ZCL_WIND_SPEED_MEASUREMENT_MIN_MEASURED_VALUE_DEFAULT, \ + .max_measured_value = ESP_ZB_ZCL_WIND_SPEED_MEASUREMENT_MAX_MEASURED_VALUE_DEFAULT, \ + }, \ + } + +typedef struct zigbee_wind_speed_sensor_cfg_s { + esp_zb_basic_cluster_cfg_t basic_cfg; /*!< Basic cluster configuration, @ref esp_zb_basic_cluster_cfg_s */ + esp_zb_identify_cluster_cfg_t identify_cfg; /*!< Identify cluster configuration, @ref esp_zb_identify_cluster_cfg_s */ + esp_zb_wind_speed_measurement_cluster_cfg_t + wind_speed_meas_cfg; /*!< Wind speed measurement cluster configuration, @ref esp_zb_wind_speed_measurement_cluster_cfg_s */ +} zigbee_wind_speed_sensor_cfg_t; + +class ZigbeeWindSpeedSensor : public ZigbeeEP { +public: + ZigbeeWindSpeedSensor(uint8_t endpoint); + ~ZigbeeWindSpeedSensor() {} + + // Set the WindSpeed value in 0,01 m/s + void setWindSpeed(float value); + + // Set the min and max value for the WindSpeed sensor + void setMinMaxValue(float min, float max); + + // Set the tolerance value for the WindSpeed sensor + void setTolerance(float tolerance); + + // Set the reporting interval for WindSpeed measurement in seconds and delta + void setReporting(uint16_t min_interval, uint16_t max_interval, float delta); + void reportWindSpeed(); +}; + +#endif //CONFIG_ZB_ENABLED