-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zigbee: Improve the sleep sketch with regard to energy requirements #10746
Comments
Have added before |
I will be able to test the consumption at the start of new year again to check if there is anything that can help. |
What you can do that can help with optimizing stuff is to provide a pcap file from Wireshark, to see what is happening at that time. If there are some transmissions going on in the peaks. Otherwise for now there is nothing you can set/select to make it more power efficient. |
Btw the energy consumption in the deep sleep is probably related to the board design. I can't tell what board I used if it was C6 or H2 Espressifs devout, but in deep sleep the power consumption was 9,8 uA. That's a big difference. |
My Wireshark setup is not working, haven't found time to find out what happen... About spikes: what I see in the Gateway logs is, that looks like a routing problem after rejoin (get messages like
Why it is not possible to save all session information in RTC RAM and use it after reboot from deep sleep mode (if valid)?
without any additional settings? like pin setting to analog input or disable anything? |
No additional settings, I am just using the sleepy example how its written.
So there is no need for
I will need to investigate this, if there is anything that can help. But the stuff is saved in Zigbee partitions, and it should be recalled. But the device still has to reconnect to the network.
If you have some time, would b nice to have the logs from the Wireshark.
I can ask about this, but for sure more informations would be needed (WireShark traffic). |
But the "rejoin process" should be other and much faster. |
Cannot confirm my thoughts.... the routing errors was something else... In Wireshark see only short Zigbee time. So the other code before need so much time for "something"... This difference is interesting, but not the top important thing.... |
The difference is probably the deep sleep (we use) vs light sleep (they use). |
@P-R-O-C-H-Y Light sleep is not a solution for ESP32 - too high sleeping current. |
@michapr Would you be able to do some timeline (I can do it also, but it would help a lot if you can) to see the times from debug log and the packets from Wireshark to have them side by side to really see, the "nothing" happen in any of those logs and the spikes(peaks) are there? I can then report it and discuss more deeply with the Zigbee team. Don't forget to select the Zigbee ED debug libs :) |
Used the sample sketch above. Debug log:
Wireshark: |
@P-R-O-C-H-Y Are here any news about the ZBOSS procedure? What happens here during this time? Thanks! |
@michapr No news yet, once I have anything I will let you know :) Just thinking out loud, possible solution would be to add support for light sleep to the library and then use the Arduino as a component in IDF or build custom libs, where the freertos tickless mode would be enabled. |
I'd a cheap temp sensor a while ago and it mostly chooses a bulb as router but the bulb was not reachable for some months. Zigbee2mqtt map showed that the sensor uses another router after some time but the battery drained every 2 months. After powering the bulb again the battery holds a year. So long story short, could it be the case the device has to find another router after wakeup? |
I've played around with this Zigbee example and determined that there's some kind of quirk (bug?) when calling esp_deep_sleep_start(); from a function. I see the same high current behavior you reported. I moved esp_deep_sleep_start(); to the main loop and I see the expected about 19 uA during deep sleep. I also made a few other changes to optimize deep sleep power saving. It works pretty well But, I have a few open issues to solve:
During operation
During enrollment:
My version
Sleep Power Consumption One-hour Average Home Assistant Zigbee device page |
@def1149 - can you please show the power usage (chart from PPK) for the active process for your device? Would be interesting to compare it to my H2 |
I'm using the Adafruit Feather ESP32-C6 which has a MAX17048 battery charger/monitor chip that I'm now using to measure the battery voltage and percent remaining since my previous post. https://www.adafruit.com/product/5933 Wake-up temp check cycle without a Zigbee connection. Wake-up temp check cycle with a Zigbee connection |
It's the same what I got with C6. about sensor - any good low power I2C sensor will be fine... @P-R-O-C-H-Y - still no answer from ZBOSS team? Does it make sense for me to contact them - will I get an answer? |
I'm using the TMP36 analog temperature sensor or a DS18B20 depending on the use case. The DS18B20 is better if you need a long connection lead. I found out why I had to re-join network after making changes. I had set erase flash before upload. It seems that the Arduino Zigbee library functions save some network configuration on the data partion it creates. If that gets erased, you have to rejoin the network. I erase flash the first time I program a device then I reset not to erase flash. Now I don't have to keep rejoining after making changes. |
@def1149 - about erase flash - it is well known that you have to do it this way. You can often read about it here ;) About sensor - DS18B20 is only good for long distance, but it take too much time (and energy) in most cases for battery devices. And the accuracy is not so good either... |
After setting Core Debug to None I've minimized power use. Wake up for a temperature check w/o making a Zigbee connection: 0.31 seconds vs 2.48 seconds Wake up and report over Zigbee: 3.23 seconds vs 5.48 seconds |
yes,... it's the same about as for my devices (I get about 2850ms) In this discussion we are looking for the spikes before Zigbee communication - see here: #10746 (comment) |
Hi @michapr,
Regarding this issue, if the device is not factory reset, it will register its ZCL model with the stack, restore network information from NVRAM, and scan the network based on the From the figure above, the peaks suggest that the stack is scanning channels 11 to 26—a total of 16 times—which matches the number of peaks. Could you double-check this? If you have access to I will also confirm this issue simultaneously, and any updates will be shared here. |
@xieqinan Thank you for taking the time to find a solution here! Where I can find the I also was thinking about the rejoin and scanning channels, but I didn't receive packets in my Zigbee packet sniffer. If it really is the channel scanning, maybe the selected channel mask is not taken into account? Thanks again! |
@xieqinan @P-R-O-C-H-Y
If you remember, the problem is, that after wakeup from deep sleep the device will scan all channels for the rejoin - and consumes a lot of energy |
@michapr Lets keep this open, I will be testing currently the scanning after rejoin, if that works as expected and link this issue to the PR with the changes :) |
If anyone can give the linked PR a try. and give feedback I would appreciate that :) |
@P-R-O-C-H-Y Can confirm that it is working fine! Thank you for your work! If somebody else want to confirm, would be nice. |
Just to clarify, any example can be used to test that :) just hit the reset button to see the "fast" reconnection |
I have confirmed the PR works. During initial enrollment, all 16 channels are scanned. On restart, or power off and power on, only one channel is scanned. What happens if the channel on the controller is changed? Will the ED perform a full scan? I changed the channel on the controller and the ED will repeatedly |
Thank you for additional info and testing :) I did not cover this scenario. I was testing only if the device gets factory reset, this scenario works. I will take a look and add some function or check if there is any callback available that channel was changed. |
I wanted to write about the same just now :)) as @xieqinan wrote:
Would be nice to realize this too. |
If a device fails to connect it should clear the current channel and rescan for a new channel on the same controller, NOT bind to any controller. That would be secure, |
I think there should be a definable timeout so that a full scan is not carried out immediately after the first connection problems. Or a definable number of failed attempts... |
I agree. Do you think this will be good to handle in user code in check if(!Zigbee.begin())? You can simply add a number of tries + I will add a API to reset the channel scan mask. |
Yes, that works for me. Perfect! " if(!Zigbee.begin())" ?? Wouldn't resetting the channel mask be something that you do after N Zigbee.connected() fails? |
I will check the proper place for sure. Was writing on the phone just the main idea :) but I think the begin is the right place (will check to be sure). |
Same for me - good idea! |
Update on power use. I got an Olimex ESP32-H2 DevKit-LIPO board . If you don't need Wi-Fi and you run on battery then the the H2 is the way to go. I didn't modify the board to remove the regulator and it sleeps at 9.8 uA and sends at 34.2 mA Avg for 565 mS. That time included reading 12-bit analog results from TMP36 temperature 5 times @ 10 mS and averaging the result. You can see the dead time at the end of the report-in is due to waiting to make sure data was delivered before going to sleep. The last 200 mS of activity occurred during the hard-coded 200 mS delay just prior to going to sleep. About 90 mS of delay can be removed if there's some kind of completion status that can be polled before sleeping. Note: The small power peaks @ one minute are the device waking up checking for a temperature change and going back to sleep if the change is less than the defined delta. That strategy saves a lot of power by only reporting when there is a significant change in a sensor value |
@def1149 as @Jason2866 said,:
Please use this only for the discussed issue - it is better for reading and understanding the progress about solving the issue ;) |
Hi @michapr @def1149, I have updated the PR and now it's all working perfectly for me. When I change the network channel, after time outing the Zigbee.Begin() it resets the channel mask to default (all channels) and after reboot it scans all channels. When it joins again it will save the new channel mask, so next reboot it will scan again the "active" channel. Few logs added, so you can track the mask in the logs when testing this:
Can you please test it out again :) With changing the channels in your system to prove its working fine :) Thank you And added a new function that needs to be called before |
Did you update the public repo? |
@def1149 its still a Pull Request. Please checkout the PR or copy the changes. Depends if you use manual version of installation. |
Ahh.yes ... of course |
It looks like this PR was implemented on top of other PRs making the editing of the RC2 base a bit complicated and it's unknown if there may be any dependencies on those previous PRs that are not in the RC2 base. I'll perform the edits and see what happens. Look like we need RC3 🤣 |
No need for RC-3 ;) I have tested the stuff properly and its working great :) so it would be perfect to have it for 3.2.0 release. |
@P-R-O-C-H-Y I'm not available for testing in this time ;) ... until begin of next week |
OK ... I downloaded the PR, replaced the Zigbee files in the local library with PR files, and recompiled my app. I ran several cycles of switching back and forth between channel 11 and channel 13 and watched the power use using the Nordic PPK2. I can see the full scan take place after a channel change and then settle down to a single-channel scan until I change the Zigbee channel again on the controller. Looks good. Thank you @P-R-O-C-H-Y NB: the 3.2.0 update breaks stuff in the Adafruit library (MAX17043) |
Board
ESP32H2
Device Description
Devboard, Supermini
Hardware Configuration
nothing connected
Version
latest development Release Candidate (RC-X)
IDE Name
Arduino IDE
Operating System
Windows 11
Flash frequency
80MHz
PSRAM enabled
no
Upload speed
921600
Description
The device require too much energy in active and sleeping mode.

Sketch
Debug Message
Other Steps to Reproduce
disabled USB CDC, debugging for saving energy.
Have removed the internal temperature procedure and replaced with random value.
Have used Nordic Power Profiler Kit II for measurements with 3.3V power
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: