-
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
Turn Wifi on/off #644
Comments
You can put this line at the end of your Arduino sketch to go to sleep for some number of microseconds. In this case 25 seconds total. The way it wakes from sleep is to have a gpio output pin pulse the reset pin of your module. On the Adafruit ESP8266 Huzzah module you would tie gpio16 to rst so it can wake from sleep. Realize this means a total reset so your module will run from powerup reset every time. The nice thing is the module draws something measured in microamps while sleeping. Another good reference for understanding this mode is here: https://www.sparkfun.com/news/1842 Below is the line of code that would work at the end of your Arduino sketch to have the module sleep for 25 seconds and wake from a cold reset if you tie the correct pin for your hardware to the RST input. ESP.deepSleep(25000000, WAKE_RF_DEFAULT); |
Thanks! I'm aware of the deep sleep feature though. I was just wondering if you could just turn off Wifi and have the processor run otherwise normally. |
I don't know. I'm still learning about the ESP8266 myself. |
There is a thing called modem sleep metioned in the sdk doc which does what you want. The only way i've found to enable it though is by doing a deep sleep, eg ESP.deepSleep(1, WAKE_RF_DISABLED), and to re-enable wifi do another ESP.deepSleep(1, WAKE_RF_DEFAULT). So not terrible convenient and if you need to keep track of the wifi state you need to store it in something like RTC memory. I see about 14 milliamps when running with wifi disabled compared with about 70 ma when its enabled but not sending much. |
Thanks @torntrousers, this is how it seems to me too. Just doesn't make sense that the only way to turn wifi on/off would be to go to deep sleep: ) Could this be something that the chip supports but is just missing from the Arduino API? |
to disable WiFi use this: WiFi.mode(WIFI_OFF); but i not now how many mA its save, would be interesting to know. |
@Links2004 yes there seems to be such an option, thanks! I made a Pull Request (#646) for including it in the docs. I didn't make power consumption measurements (yet) to see if it has any effect. However, after doing |
I hadn't heard of WiFi.mode(WIFI_OFF) either. Gave it a try measuring the change in current but i still get about 70milliamps after WiFi.mode(WIFI_OFF) whereas ESP.deepSleep(1, WAKE_RF_DISABLED) gives about 14milliamps on the wakeup, so it seems like WIFI_OFF does not completly switch off the wifi radio. |
Hi, |
it will work. eclipse (no need for keywords.txt) for more power saving use: WiFi.forceSleepBegin(); (only work in git or staring) |
Yes it works, |
Guys
But it stop ESP from running and without any manual reset, my sketch is blocked. Looking inside WiFi code,
and SDK 1.5.1 of 2016 page 49 on
Maybe calling this on
and serial when it happens
Then need to push reset on ESP, you can see "OK!" string does not appears Something I missed or I'm doing wrong ? |
|
@hallard in SDK
|
I've tried the code from this comment http://www.esp8266.com/viewtopic.php?p=39624#p39624:
and it does switch WiFi off and the current use drops to about 14mA.
the current use goes back up to about 70mA but it never successfully connects again. Can anyone show working code for how to switch on and connect again? |
@torntrousers Using example in SDK, I have 15mA, and wifi connection. https://gist.github.com/chaeplin/be4d9ca41a991aa327bb Modem sleep : https://youtu.be/ohOLPcs2aY4 |
Thanks @chaeplin, it looks like its the wifi_station_connect() in your code that gets it connected again, so this works for me:
I wonder shouldn't the wifi_station_connect call be included within the WiFi.begin or WiFi.forceSleepWake function? |
@torntrousers WiFi.begin has wifi_station_connect already. https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L146 |
@igrr
as soon as I solve my GDB problem |
I grabbed gdb from gnutoolchains here for those who're interested. I'm wondering If I can replace the whole ESP8266 toolchain bin directory from Arduino with this one from gnutoolchains ? And following code did the trick (I don't need to enable WiFi back so I didn't tested this part). make sense to call
Thanks to everyone helping me |
@chaeplin interesting, but I can't get it to connect again without the explicit call to wifi_station_connect in my code. Does it work with/without for anyone else? |
@torntrousers Without wifi_station_connect, I can't. |
Hi, I have used WiFi.mode(WIFI_OFF) which turned off my wifi modem. But after that i am creating Access point with same chip but not able to find the SSID. Is there any way to reset the chip or turn on the radio of wifi ? |
For me it works without explicit call to wifi_station_connect.
|
@gosewski : Thanks for the info. I will give it a try and let you know. |
So, to confirm after: The only way to get WiFi working is Would doing this have the same affect (just as low current use on next boot):
|
@matthuisman thanks for sharing this. I had exactly the same problem with Wi-Fi staying disabled after deepSleep and I was looking for an elegant way to turn it back on. Your second suggestion seemed to help. Thanks again. |
Gives me about 30mA supply current, down from 80-90mA (WiFi running but not connected) |
Tried without the delay(1), did not seem to work. Also tried just one call after delay(5000), also did not work. So now I am calling it very loop. i.e.
This seems to work (at least for the last few tests) |
The original issue is answered. Closing. |
Is there an API for turning the WiFI off when it's not needed, to save power?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: