-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Can't re-enable WiFi after ESP.deepSleep(uS, WAKE_RF_DISABLED) ? #3072
Comments
#644 mentions using: |
No, unfortunately there isn't. If you ask it to do a deep sleep reset and wake up with RF disabled, RF is going to be exactly that — disabled. |
OK, is there a fast way to test the RF disabled/enabled state? So my code can distinguish between my 'normal' REASON_DEEP_SLEEP_AWAKE, and when it comes awake from a brief deep sleep used to enable the RF? |
Writing a flag into RTC memory prior to going into deep sleep is probably the easiest way. ESP8266 SDK doesn't provide a function to query RF state. |
Thanks, that seems to be working nicely. |
Just noticed this line in Esp.h:
can't I use __get_rf_mode() to read the current RF state? |
This is what I'm searching for. I was using LUA scripts on Nodemcu, but it eats alot of battery. |
How does one call __get_rf_mode() in an ino file? |
Not sure about a .ino file. In a .cpp file you could do this: |
I've discovered a workable solution in a gist This is the best solution I have found so far (source: GitHub gist) The two functions below are all you need to toggle your WiFi chip. The huge advantage of using these is that they work without having to invoke an Mind you, if you have already done an
|
The code above does not compile verbatim. Arduino IDE complains about line 19 "'WifiOff' was not declared in this scope"... |
@2000jago Yup, I wrote |
@pfabri I can confirm (on wemos D1 mini) this does indeed work and it works well. Thank you sir! |
Would be nice to add those functions to the core ESP.h class |
hello friends, I have done the following and I disconnected the WiFi, low consumption, still running all processes and then connect the Wifi again it increases the power consumption and works normally void desc() WiFi.mode(WIFI_OFF); the high delay was very important. void conectar() |
else
return; |
hi, has anyone tested the power usage while in sleep mode? i'm getting 3mA and can't go lower. 3mA is too much for my purpose. thanks! |
Does your module have an LED? is it on? If so, that's likely your power drain. |
Regarding the original post, I tried every trick I could think of, and I have to agree with igrr about whether you can re-enable WiFi after ESP.deepSleep(time, WAKE_RF_DISABLED)
|
Closing in view of previous comment. |
I have spent many many hours trying to fix this until I came across this (closed) issue. Please @igrr and team can you add to the documentation a warning about using WAKE_RF_DISABLED and the tip about using WAKE_RF_DEFAULT to get things up and running again? |
@amadeuspzs Please make your proposal in a PR. |
Actually I found another solution, which I've successfully tested. The trick is after waking from
Source: https://www.bakke.online/index.php/2017/05/21/reducing-wifi-power-consumption-on-esp8266-part-2/ |
Yep, works fine to wake the modem after ESP.deepSleep(timeus, WAKE_RF_DISABLED), thanks for finding that! Looks like you still pay the piper once you turn the modem on: There has GOT to be a way to fake it out so that it doesn't do that RF_CAL every time. If you're off by a couple dBm output power, do you really care?? I suspect it's stored in the system area of the RTC RAM, so I'll so snooping there to see if I can decode what changes after an RF_CAL. If you can do it once then save it to the user section of RTC RAM, you could probably copy it back before you turn the modem on. Maybe system_phy_set_powerup_option() will do it. I'll do a PR to add the modem wake up to the docs. I've a suspicion @torntrousers might find this of interest. ;-) edit: Sorry Anthony, I tried every trick I could find in the SDK API book plus the ones from here and I couldn't keep the modem from doing an RF_CAL every time I turned the modem back on. Unless someone else has suggestions, I'm not seeing a benefit in doing WAKE_RF_DISABLED unless you don't want the modem at all. WAKE_NO_RF_CAL is probably a better option, power-wise. |
Does not work for me, maybe something has changed in the code? |
Seems to still work for me. Maybe we have different versions? |
Hmm, or maybe not. It's a bit unpredictable. Sometimes after using the workaround (below), the ESP8266 will consume 40 mA (not the expected 70 mA), and the connection will fail.
After it gets in this weird state, the only way to fix it is to hard power cycle the ESP8266, or call |
Basic Infos
Hardware
Hardware: WeMos D1 mini
Core Version: v2.2.0
Description
My sketch spends most of its time in deep sleep, just using the WiFi when it first powers up. This works fine from a full power-cycle, but not if is reset (reset button, or new sketch uploaded over serial). In that case I can't seem to switch the WiFi back on? I presume the RF is disabled from the deep sleep, even through a reset, and WiFi.mode(WIFI_STA) isn't enough to switch it back on?
I get:
Settings in IDE
Module: WeMos D1 R2 & mini
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: SERIAL
Reset Method: ?ck / nodemcu?
Sketch
NB: I'm using WiFi.setAutoConnect(false)/setAutoReconnect because otherwise the board was always trying to connect to the WiFi immediately upon waking from deep sleep, even if WiFi.disconnect(), WiFi.mode(WIFI_OFF) and WAKE_RF_DISABLED had been called.
The text was updated successfully, but these errors were encountered: