Aircoookie / WLED

Control WS2812B and many more types of digital RGB LEDs with an ESP8266 or ESP32 over WiFi!
https://kno.wled.ge
MIT License
14.57k stars 3.12k forks source link

Bug: Missing delay to activate sleep mode on ESP8266 #1144

Closed c3n closed 3 years ago

c3n commented 4 years ago

According to the ESP8266 docs you need delay(1) or more to enter DTIM-based wifi sleep (light sleep). Uploading the current version to a d1 mini without connecting anything else, the power consumption is very constant at 90mA, even after the 10s sleep timeout (turning LEDs off in web gui doesn't change that).

However if I change wled.cpp in line 89 to: if(offMode)delay(1);else strip.service();

and then turn off the LEDs in the web gui the power consumption jumps between 35mA and 55mA (while the behaviour with LEDs on is unchanged)

I didn't make a pull request because I have no idea what timing limitations I broke with that delay statement

pbolduc commented 4 years ago

According to the ESP8266 docs

It would be useful to link to the documentation so we dont have to go looking for it.

c3n commented 4 years ago

https://blog.creations.de/?p=149 says that you need a delay of at least 1 to go into light sleep while the official docs https://www.espressif.com/sites/default/files/9b-esp8266-low_power_solutions_en_0.pdf just says that the cpu needs to be idle under 3.2.1.

pfeerick commented 4 years ago

I also noticed that the custom D1 Mini setup I just converted over to WLED isn't sleeping - so is staying nice and warm. I can say from personal experience, and following the modem/light sleep issues that arrose the across esp8266-arduino core v2.5.x to v2.7.x that auto light sleep requires a delay to operate, but it doesn't seem to be mentioned in the docs. It is however, specifically menmtioned in the low power example code provided with the core (my emphasis added):

This is the default power saving mode when you have an active WiFi connection. You don't need to add anything to your code to get this mode. The only time the modem sleeps is when your program spends time in delay() frequently in STA mode. Any delay() time works as long as it happens frequently.

https://github.com/esp8266/Arduino/blob/master/libraries/esp8266/examples/LowPowerDemo/README.md#test-2---automatic-modem-sleep

I have also made the above change to my unit, since it only adds a 1ms delay when in the 'power off' mode, so should be of little consequence to the normal operation of the unit. I'll comment back in say a weeks time as to the stability of this change, but for other projects adding a 1ms delay to allow auto modem sleep has done no harm.

pbolduc commented 4 years ago

Do we know if this applies to ESP32 as well?

pfeerick commented 4 years ago

I'm not familiar enough with the ESP32 to comment from experience. lastminuteengineers have an excellent article on the ESP32 sleep modes, and whilst it appears the modem sleep works by sleeping between DTIM beacons like the ESP8266, there is no mention of a delay needed.

But going by the ESP-IDF example on wifi power saving - it looks like it simply needs to be enabled - as it claims there that it is disabled by default. i.e. To enable : esp_wifi_set_ps(WIFI_PS_MIN_MODEM);

But then, when looking at the SDK source code included with the esp32-arduino core, it then says that WIFI_PS_MIN_MODEM is the default?! Now I really am confused!

pfeerick commented 3 years ago

Hey @c3n, have you noticed that the ESP8266 won't stay in modem sleep mode? Mine seems to properly sleep for all of 5-7 seconds and then stays always on. Seems there is too much going on for the modem to keep napping. :(

I thought I'd be clever and integrate it into the 'no wifi sleep' option at the bottom of the wifi settings page, so was actively testing/toggling it on and off, and realised the failure to stay sleepy.

image

c3n commented 3 years ago

Unfortunately I can't test anything for the next 2 weeks, but mine definitely slept a lot longer. That being said, the sleep mode seems a bit sketchy, it's supposed to wait for 10s (I think) before going to sleep which for me it usually (but not always) ignored and went straight to sleep after each web page action

Aircoookie commented 3 years ago

When I was specifically testing modem sleep about a year ago I had my Wemos D1 idling at 20mA, with occasional spikes to 80mA for communication. On ESP32 sleep mode did not seem to work at all, with a constant 120mA of power draw. Looks like I will need to get the power meter and try to look into why the sleep seems to be no longer working...

pfeerick commented 3 years ago

It's supposed to wait for 10 seconds after the initial connection to the AP, due to loss of packets issues if it entered modem sleep immediately after connection. So that sounds right.

I should probably revert to defaults, and start again, maybe turning something on (i.e. Alexa notifications, etc) is keeping it busy. As ~30ma on average was what I was expecting to see, rather than staying at ~140ma all the time.

Edit: Using the 'touch test' measurement method, it actually seems like it did go to sleep overnight.

On Mon, 14 Sep 2020, 10:34 pm c3n, notifications@github.com wrote:

Unfortunately I can't test anything for the next 2 weeks, but mine definitely slept a lot longer. That being said, the sleep mode seems a bit sketchy, it's supposed to wait for 10s (I think) before going to sleep which for me it usually (but not always) ignored and went straight to sleep after each web page action

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Aircoookie/WLED/issues/1144#issuecomment-692022532, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJ66KOI74MPYCTL6UYE6X3SFYEUVANCNFSM4QY4NLXQ .