espressif / esp-matter

Espressif's SDK for Matter
Apache License 2.0
706 stars 161 forks source link

creating an Sleepy End Device (SED) (CON-467) #366

Closed glennmullerar closed 9 months ago

glennmullerar commented 1 year ago

Hello,

Hello,

I would like to create a SED. In the Matter specification it is indicated that we have to change the value of the field SLEEPY_IDLE_INTERVAL or SLEEPY_ACTIVE_INTERVAL depending on the mode we want to use. However, I couldn't find anything in the sdkconfig and in the esp-matter files (esp-matter/components). Is it possible to do this or is it a feature that will come later.

Most probably I did not look in the right place.

Thanks in advance for your answer.

chshu commented 1 year ago

@glennmullerar It's configurable by CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL and CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, the detailed description about these two parameters are here:

https://github.com/project-chip/connectedhomeip/blob/master/src/messaging/ReliableMessageProtocolConfig.h#L52

Could you modify the default values and have a test, let us know if it works for you. We will make it configurable via IDF menuconfig.

glennmullerar commented 1 year ago

Thank you for your answer.

I see that by changing the value the number of steps at the time of the build changes.

However, is there a chip-tool or other command that would allow to know if it is well known as SED by the other devices in the network?

chshu commented 1 year ago

It could be achieved by the new ICD (Intermittently Connected Devices) feature, and there is a clientmonitoring cluster cmd can be used by chip-tool.

But the feature is currently not supported in esp-matter yet, since the feature is still under developing, we will add the support in short future. Could you let us know which SoC are you using, Wi-Fi or Thread?

glennmullerar commented 1 year ago

Thanks for the answer, so the best solution is to wait. Do you have any idea of a release date? The aim is to reduce the power consumption of a WiFi device.

marciogranzotto commented 1 year ago

I'm trying to make a SED with ESP32-H2 using thread. Is that not supported yet as well? @chshu

chshu commented 1 year ago

@marciogranzotto The H2 sleep mode is not supported yet (IDF and esp-matter), will keep you posted.

Gonta01 commented 1 year ago

What about ESP32C6? Is it possible to create Thread Sleep End Device on ESP32C6 basis?

marciogranzotto commented 1 year ago

@chshu is it posible with the C6?

chshu commented 1 year ago

The aim is to reduce the power consumption of a WiFi device. @glennmullerar If it's a Wi-Fi device, you don't need to wait for the ICD feature, you can just enable the Wi-Fi power save mode (example).

chshu commented 1 year ago

@Gonta01 @marciogranzotto To enable the Thread Sleepy End Device on H2 and C6 for Matter application, the following two tasks need to be done:

We target to have the two features ready by the end of July.

LinJiaDeng commented 1 year ago

Hello @chshu, I'm doing a research about Matter for my final project and I was testing the power consumption of the esp32-c3 with Matter examples (Light and Light Switch) using WI-FI. The result amazed me because it was in mA order when typically these devices consumptions are around µA. I attach a screencapture below of my power analyzer.

ESP_SWITCH_21 (Light Switch example)

Is it possible to make these examples (at least the Light Switch example) an Sleepy End Device?

caipiblack commented 1 year ago

I’m’also looking for this feature in WiFi and Thread.

I want to see the average power consumption we can expect with esp32-c6 in wifi and thread as sleepy end device.

The objective is to compare nRF52 vs ESP32-C6.

I prefer the esp ecosystem but high power consumption will not be acceptable for my application.

marciogranzotto commented 1 year ago

@chshu I see that the Light Sleep support for Thread in esp-idf is already implemented. Is there any news about the ICD/SED feature in esp-matter?

Looking forward for it so I can get my product working!

chshu commented 1 year ago

@LinJiaDeng @caipiblack @marciogranzotto The Thread light sleep on H2 and C6 are all supported in ESP-IDF now, you may first refer to the H2 datasheet for some power consumption data, and evaluate the H2 / C6 power consumption using this example: https://github.com/espressif/esp-idf/tree/master/examples/openthread/ot_sleepy_device.

We are actively adding the ICD support to esp-matter, will posted here once it's ready.

marciogranzotto commented 1 year ago

@chshu any news? If there's anything I can help with on the implementation, I would be happy to

chshu commented 1 year ago

@marciogranzotto The ICD feature itself has been supported in Matter ESP platform (https://github.com/project-chip/connectedhomeip/pull/28359), some sleep tunning work is still under progress, will update here once it's done (target to mid Oct).

pogadlin commented 1 year ago

The aim is to reduce the power consumption of a WiFi device. @glennmullerar If it's a Wi-Fi device, you don't need to wait for the ICD feature, you can just enable the Wi-Fi power save mode (example).

Hi @chshu, I want to check power consumption on ESP32-C6 for Wi-Fi, as you mentioned how to enable Wi-Fi power save mode?
Do i have to change anything in the power save example?

chshu commented 1 year ago

@glennmullerar @marciogranzotto The Matter ICD support on ESP32-H2 is available in esp-matter now, please check the example: https://github.com/espressif/esp-matter/tree/main/examples/sleepy_device

marciogranzotto commented 1 year ago

@chshu just for the H2? what about C6?

flashspys commented 1 year ago

The example does not compile for the C6 out of the box. I was able to make it compiling after I've removed the espressif/mdns and /insights packages and a few other minor h2->c6 renaming. For HomeKit commissioning I had to comment out the BLE Sleep changes. Even though, I'm not 100% sure if the example works as expected. I have a cheap USB power meter that says that my C6 still needs 40mA / 200mW which should be way too high. Light sleep on ESP should take 0.8 mA / 4mW.

Can you tell me how to check which mode the ESP32 is currently in and if this behavior is expected? Furthermore, could you share some power consumption values for the H2?

chshu commented 1 year ago

@marciogranzotto @flashspys Currently the example only supports ESP32-H2 Thread Sleepy device.

C6 Thread is pending on a sleep issue, will be supported once the issue is fixed in IDF. C6 Wi-Fi support will be added later.

marciogranzotto commented 12 months ago

@chshu any news on the C6 sleep issue? Btw, will this be on which version of the IDF? I'm currently developing against release/v5.1

chshu commented 11 months ago

@chshu any news on the C6 sleep issue? Btw, will this be on which version of the IDF? I'm currently developing against release/v5.1

The C6 sleep issue has been fixed in IDF, but some compiling issues (as mentioned in https://github.com/espressif/esp-matter/issues/366#issuecomment-1771792028) depend on some changes in other repos, the fixes are under merging.

We will prepare a patch for your testing soon, you may also evaluate the Matter sleep feature on H2 first.

wqx6 commented 11 months ago

The C6 sleep is supported on the latest IDF master, and the backport changes will be added to v5.1 ASAP. Another question is that there are some managed components in the chip component which has compiling issues when disabling LWIP_IPV4. Here are two patches for the connectedhomeip submodule and esp-matter repo which you can apply to test sleep on ESP32-C6.

0001-connectedhomeip-changes.txt 0001-esp-matter-changes.txt

bskimaaa commented 11 months ago

[Questions about features added to ESP-IDF v5.1] Does this mean that the WIFI sleep (SED, ICD) function is supported in the ESP32C6 Matter project? Does this mean that the Thread sleep function is supported in the ESP32C6 Matter project? Does the ESP32C3 Matter project also support WIFI sleep (SED, ICD) function?

Pips801 commented 11 months ago

[Questions about features added to ESP-IDF v5.1]

Does this mean that the WIFI sleep (SED, ICD) function is supported in the ESP32C6 Matter project?

I can not confirm WiFi sleepy, I will have to try later, but I can confirm that Power Management (PM) and ICD server can be enabled on the c6. Does this mean that the Thread sleep function is supported in the ESP32C6 Matter project?

Yes. After following the patches advised from Espressif, modifying the upstream project chip cmake and idf component files, plus a little bit of tweaking for my project to reenable secure-cert-manager, I was able to make a Matter over Thread Sleepy generic_switch endpoint on the C6 - https://github.com/espressif/esp-matter/assets/5651603/8d2431ba-2cc5-4e57-b3b3-dabd95e6a89f

Does the ESP32C3 Matter project also support WIFI sleep (SED, ICD) function?

I cannot confirm, I don't have a C3, but if WiFi sleep works for the C6 I bet it would work for the C3.

marciogranzotto commented 11 months ago

I also applied the patches, using esp-idf commit a36d8bc742 (release/v5.2) and esp-matter commit 96dc30b (release/v1.2).

However my ESP32-C6-DevKitC-1 keeps crashing when running the sleepy_device example:

Logs (click to expand) ``` Rebooting... ESP-ROM:esp32c6-20220919 Build:Sep 19 2022 rst:0xc (SW_CPU),boot:0xc (SPI_FAST_FLASH_BOOT) SPIWP:0xee mode:DIO, clock div:2 load:0x40875720,len:0x1804 load:0x4086c410,len:0xde0 load:0x4086e610,len:0x2df8 entry 0x4086c41a I (25) boot: ESP-IDF v5.2-beta1-226-ga36d8bc742 2nd stage bootloader I (26) boot: compile time Dec 19 2023 19:37:56 I (27) boot: chip revision: v0.0 I (30) boot.esp32c6: SPI Speed : 80MHz I (34) boot.esp32c6: SPI Mode : DIO I (39) boot.esp32c6: SPI Flash Size : 4MB I (44) boot: Enabling RNG early entropy source... I (49) boot: Partition Table: I (53) boot: ## Label Usage Type ST Offset Length I (60) boot: 0 esp_secure_cert unknown 3f 06 0000d000 00002000 I (68) boot: 1 nvs WiFi data 01 02 00010000 0000c000 I (75) boot: 2 nvs_keys NVS keys 01 04 0001c000 00001000 I (82) boot: 3 otadata OTA data 01 00 0001d000 00002000 I (90) boot: 4 phy_init RF data 01 01 0001f000 00001000 I (97) boot: 5 ota_0 OTA app 00 10 00020000 001e0000 I (105) boot: 6 ota_1 OTA app 00 11 00200000 001e0000 I (112) boot: 7 fctry WiFi data 01 02 003e0000 00006000 I (120) boot: End of partition table I (125) esp_image: segment 0: paddr=00020020 vaddr=42110020 size=38c68h (232552) map I (226) esp_image: segment 1: paddr=00058c90 vaddr=40800000 size=07388h ( 29576) load I (241) esp_image: segment 2: paddr=00060020 vaddr=42000020 size=10399ch (1063324) map I (668) esp_image: segment 3: paddr=001639c4 vaddr=40807388 size=0f284h ( 62084) load I (698) esp_image: segment 4: paddr=00172c50 vaddr=50000000 size=00048h ( 72) load I (708) boot: Loaded app from partition at offset 0x20000 I (709) boot: Disabling RNG early entropy source... I (720) cpu_start: Unicore app W (730) clk: esp_perip_clk_init() has not been implemented yet I (736) cpu_start: Pro cpu start user code I (736) cpu_start: cpu freq: 160000000 Hz I (737) cpu_start: Application information: I (739) cpu_start: Project name: sleepy_device I (745) cpu_start: App version: 1.0 I (749) cpu_start: Compile time: Dec 19 2023 19:50:01 I (755) cpu_start: ELF file SHA256: 66248d460... I (761) cpu_start: ESP-IDF: v5.2-beta1-226-ga36d8bc742 I (767) cpu_start: Min chip rev: v0.0 I (772) cpu_start: Max chip rev: v0.99 I (777) cpu_start: Chip rev: v0.0 I (782) heap_init: Initializing. RAM available for dynamic allocation: I (789) heap_init: At 40828F40 len 000536D0 (333 KiB): RAM I (795) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM I (801) heap_init: At 50000048 len 00003FA0 (15 KiB): RTCRAM I (808) spi_flash: detected chip: generic I (812) spi_flash: flash io: dio W (816) spi_flash: Detected size(8192k) larger than the size in the binary image header(4096k). Using the size in the binary image header. I (830) sleep: Enable automatic switching of GPIO sleep configuration I (837) sleep_clock: System Power, Clock and Reset sleep retention initialization I (845) sleep_clock: Modem Power, Clock and Reset sleep retention initialization I (853) sleep_sys_periph: Interrupt Matrix sleep retention initialization I (860) sleep_sys_periph: HP System sleep retention initialization I (867) sleep_sys_periph: TEE/APM sleep retention initialization I (874) sleep_sys_periph: UART sleep retention initialization I (880) sleep_sys_periph: Timer Group sleep retention initialization I (887) sleep_sys_periph: IO Matrix sleep retention initialization I (894) sleep_sys_periph: SPI Mem sleep retention initialization I (901) sleep_sys_periph: SysTimer sleep retention initialization I (919) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 80, APB_MIN: 40, Light sleep: DISABLED I (919) coexist: coex firmware version: e41c5cb I (923) coexist: coexist rom version 5b8dcfa I (928) main_task: Started on CPU0 I (931) main_task: Calling app_main() I (952) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 160, APB_MIN: 160, Light sleep: ENABLED I (970) chip[DL]: NVS set: chip-counters/reboot-count = 1685 (0x695) I (972) chip[DL]: Real time clock set to 946684800 (0100/00/01 00:00:00 UTC) I (974) BLE_INIT: Using main XTAL as clock source I (976) esp openthread sleep: Enable ieee802154 light sleep, the wake up source is ESP timer I (989) OPENTHREAD: Host connection mode none controller lib commit: [9a23742] W (996) BLE_INIT: BLE modem sleep is enabled I (995) phy_init: phy_version 230,c773401,Oct 30 2023,15:07:16 I (1003) BLE_INIT: Modem BLE MAC retention initialization W (1015) BLE_INIT: Enable light sleep, the wake up source is BLE timer I (1050) phy: libbtbb version: 7243671, Oct 30 2023, 15:07:30 I (1050) btbb_init: btbb sleep retention initialization I (1052) ieee802154: ieee802154 mac sleep retention initialization I (1056) NimBLE: GAP procedure initiated: stop advertising. I (1065) NimBLE: Failed to restore IRKs from store; status=8 I (1071) CHIP[DL]: BLE host-controller synced I (1096) OPENTHREAD: OpenThread attached to netif I(1107) OPENTHREAD:[N] Mle-----------: Role disabled -> detached I (1119) chip[DL]: OpenThread ifconfig up and thread start I (1123) chip[DL]: OpenThread started: OK I (1123) chip[DL]: Setting OpenThread device type to SLEEPY END DEVICE I (1142) OT_STATE: netif up I (1580) chip[DL]: Configuring CHIPoBLE advertising (interval 25 ms, connectable) I (1630) NimBLE: GAP procedure initiated: advertise; I (1631) NimBLE: disc_mode=2 I (1631) NimBLE: adv_channel_map=0 own_addr_type=1 adv_filter_policy=0 adv_itvl_min=40 adv_itvl_max=40 I (1639) NimBLE: BLE assert: line 1420 in function ble_lll_sched_check_remaining_entries, param: 0x1, 0x6000 assert failed: osi_assert_wrapper bt.c:263 (0) Core 0 register dump: MEPC : 0x408004b8 RA : 0x4080d4e2 SP : 0x40816e50 GP : 0x40814864 Stack dump detected 0x408004b8: panic_abort at /Users/marciorodrigues/Olibra/code/matter/esp-idf/components/esp_system/panic.c:472 0x4080d4e2: __ubsan_include at /Users/marciorodrigues/Olibra/code/matter/esp-idf/components/esp_system/ubsan.c:313 TP : 0x40805be4 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130 0x40805be4: r_hal_timer_set_exp_tick.part.0 at hal_timer.c.o:? S0/FP : 0x00000001 S1 : 0x40816f9e A0 : 0x40816ea8 A1 : 0x40815969 A2 : 0x00000001 A3 : 0x00000029 A4 : 0x00000001 A5 : 0x40828000 A6 : 0x0000000c A7 : 0x76757473 S2 : 0x00000099 S3 : 0x40816ea8 S4 : 0x40816ea8 S5 : 0x00000001 S6 : 0x4083dc6c S7 : 0x00000000 S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000 T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938 MSTATUS : 0x00001881 MTVEC : 0x40800001 MCAUSE : 0x00000007 MTVAL : 0x00000000 0x40800001: _vector_table at ??:? MHARTID : 0x00000000 Backtrace: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/marciorodrigues/Olibra/code/matter/.espressif/tools/riscv32-esp-elf-gdb/12.1_20221002/riscv32-esp-elf-gdb/bin/riscv32-esp-elf-gdb-3.9.Awd8AYd panic_abort (details=details@entry=0x40816ea8 "assert failed: osi_assert_wrapper bt.c:263 (0)") at /Users/marciorodrigues/Olibra/code/matter/esp-idf/components/esp_system/panic.c:472 472 *((volatile int *) 0) = 0; // NOLINT(clang-analyzer-core.NullDereference) should be an invalid operation on targets #0 panic_abort (details=details@entry=0x40816ea8 "assert failed: osi_assert_wrapper bt.c:263 (0)") at /Users/marciorodrigues/Olibra/code/matter/esp-idf/components/esp_system/panic.c:472 #1 0x4080d4e2 in esp_system_abort (details=details@entry=0x40816ea8 "assert failed: osi_assert_wrapper bt.c:263 (0)") at /Users/marciorodrigues/Olibra/code/matter/esp-idf/components/esp_system/port/esp_system_chip.c:93 #2 0x4081307c in __assert_func (file=, file@entry=0x42120513 "", line=line@entry=263, func=, func@entry=0x421379ec <__func__.3> "", expr=, expr@entry=0x421180dc "") at /Users/marciorodrigues/Olibra/code/matter/esp-idf/components/newlib/assert.c:81 #3 0x40802b8a in osi_assert_wrapper (ln=, fn=, param1=, param2=) at /Users/marciorodrigues/Olibra/code/matter/esp-idf/components/bt/controller/esp32c6/bt.c:263 #4 0x40804cde in ble_lll_sched_check_remaining_entries () Backtrace stopped: frame did not save the PC ELF file SHA256: 66248d460 ```

Can you please advise?

marciogranzotto commented 11 months ago

@Pips801 could you tell me which commits of the esp-idf and esp-matter you use to achieve C6 Thread sleepy device? I would greatly appreciate it!

Pips801 commented 11 months ago

@Pips801 could you tell me which commits of the esp-idf and esp-matter you use to achieve C6 Thread sleepy device? I would greatly appreciate it!

I will have to go check the build environment, but it is IDF v5.1.1 with the latest matter 1.2 repository for esp-matter.

Can you post your sdkconfig for the sleepy c6? I ended up copying most everything from the Sleepy C2 example code and the C2 sdkcondig.

I did also encounter some sporadic crashes like yours with the Bluetooth stack. One thing that I changed, that may help, was changing CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING from y to n in the sdkconfig for the C6. since the panic happens right at a ble-related function in the ble stack.

marciogranzotto commented 11 months ago

I've tried with both CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING set to y and to n. I also tested the sleepy_device example, and the light example with the sleepy_device changes applied to it.

I keep getting the same crash on ble_lll_sched_check_remaining_entries, which appears to be on the lower lever bluetooth driver of the ESP32-C6.

I also tested with multiple ESP32-C6-DevKits.

I'll try to zip my project later and post it here.

wqx6 commented 11 months ago

Does this mean that the WIFI sleep (SED, ICD) function is supported in the ESP32C6 Matter project?

No, Wi-Fi ICD is still not supported for our platform. In fact, there is no SED for Wi-Fi devices. The Wi-Fi should wake up to keep the connection per 100ms~500ms

Does this mean that the Thread sleep function is supported in the ESP32C6 Matter project?

Yes, the Thread sleep is supported for ESP32C6 for IDF branch release/v5.1(commit id 47c89441c16e0933474c8dc7d8ca9b3f75d2a1da), and you can build the sleepy-device examples for C6 if you have applied the two patches

Does the ESP32C3 Matter project also support WIFI sleep (SED, ICD) function?

No.

wqx6 commented 11 months ago

Can you please advise?

@marciogranzotto @Pips801 Sorry I forgot to add the phy configuration CONFIG_ESP_PHY_MAC_BB_PD=y to the C6's sdkconfig file in the patch file, please add that configuration option and build the example based on IDF release/v5.1(commit id 47c89441c16e0933474c8dc7d8ca9b3f75d2a1da).

marciogranzotto commented 11 months ago

@wqx6 Thanks a lot! That did the trick!

Do you guys have power consumption measurements of the ESP32-C6 in ICD mode?

I see that there is a plot for ESP32-H2 Devkit-C on the examples/sleepy_device/README, but no data about the C6

wqx6 commented 10 months ago

Here is the current picture of C6 with the same default ICD parameters as H2. ESP32-C6 current capture

chshu commented 9 months ago

Hi All, Both H2 and C6 ICD support is ready, please try out this example: https://github.com/espressif/esp-matter/tree/main/examples/icd_app.

Note that the IDF release/v5.1 branch with the commit id 931eaf7320 or later, should be used for C6 sleep.

Kristian8606 commented 5 months ago

@marciogranzotto Did you manage to reduce esp32 consumption, and what values ​​did you measure? My measurements are esp32h2 3mA and esp32c6 9mA this is too much consumption.

caipiblack commented 3 months ago

Hello,

In icd_app readme (https://github.com/espressif/esp-matter/tree/main/examples/icd_app) it say's:

Note: For ESP32-C6, please use ESP-IDF on branch release/v5.1 with the commit id 931eaf7320.

So:

  1. Why do we have to use this specific commit ?
  2. Is it possible to use newer commits ?
  3. What is the real status of icd_app ? Working ?