Turn WIFI Off On ESP8266 Boards

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
jmwright
Posts: 12
Joined: Tue Nov 29, 2016 2:57 am

Turn WIFI Off On ESP8266 Boards

Post by jmwright » Sun Dec 04, 2016 3:52 am

Is there a way to turn the WIFI off on 8266 boards using MicroPython? Turning the WIFI off when using Arduino is discussed here: https://github.com/esp8266/Arduino/issues/644

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Turn WIFI Off On ESP8266 Boards

Post by mcauser » Wed Dec 07, 2016 12:40 pm

Is this what you are after?

Code: Select all

import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(False)
ap_if = network.WLAN(network.AP_IF)
ap_if.active(False)
http://docs.micropython.org/en/latest/e ... networking
http://docs.micropython.org/en/latest/e ... sleep-mode

jmwright
Posts: 12
Joined: Tue Nov 29, 2016 2:57 am

Re: Turn WIFI Off On ESP8266 Boards

Post by jmwright » Wed Dec 07, 2016 9:05 pm

Yes, thank you mcauser. At least with the Arduino, it sounds like sometimes the 8266's WIFI capability isn't shut down properly and still continues to draw full power. I'll need to double check to see if that happens with this board.

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Turn WIFI Off On ESP8266 Boards

Post by kfricke » Wed Dec 07, 2016 10:08 pm

Only the interfaces are deactivated. There is no reduction in RF power usage implemented as far as i do understand from the source code.

jmwright
Posts: 12
Joined: Tue Nov 29, 2016 2:57 am

Re: Turn WIFI Off On ESP8266 Boards

Post by jmwright » Wed Dec 07, 2016 10:17 pm

Ok, thanks. The power reduction is the main thing I'd like to have.

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Turn WIFI Off On ESP8266 Boards

Post by mcauser » Thu Dec 08, 2016 12:12 am

The radio can be disabled using sleep modes and deep sleep.
http://docs.micropython.org/en/latest/e ... y/esp.html

Get / set sleep modes. SLEEP_MODEM is the default.
This wraps wifi_set_sleep_type() in the SDK.

Code: Select all

>>> import esp
>>> esp.sleep_type()
2
>>> esp.SLEEP_MODEM
2
>>> esp.sleep_type(esp.SLEEP_NONE)
sleep disable
>>> esp.sleep_type()
0
>>> esp.sleep_type(esp.SLEEP_MODEM)
sleep enabled,type: 2
>>> esp.sleep_type(esp.SLEEP_LIGHT)
sleep enabled,type: 1
Sleep until the reset button is pressed.
These wrap system_deep_sleep_set_option() and system_deep_sleep() in the SDK.

Code: Select all

>>> import esp
>>> esp.deepsleep()
Sleep for 2 seconds (2,000,000us) then wake.
You need to have GPIO16 connected to RST for the board to wake.

Code: Select all

>>> import esp
>>> esp.deepsleep(2000000)
After waking, you can check the reset cause.

Code: Select all

>>> import machine
>>> machine.reset_cause()
5
>>> machine.DEEPSLEEP_RESET
5
Mode info on sleep modes: http://www.espressif.com/sites/default/ ... s_en_0.pdf

jmwright
Posts: 12
Joined: Tue Nov 29, 2016 2:57 am

Re: Turn WIFI Off On ESP8266 Boards

Post by jmwright » Thu Dec 08, 2016 1:23 am

Awesome, thank you. That's very helpful.

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Turn WIFI Off On ESP8266 Boards

Post by kfricke » Thu Dec 08, 2016 7:51 am

I did recon that the OP wanted to have the CPU be active and only the WiFi be powered down completely.
Browsing the ESP documentation's I have seen that the ESP can be booted this way by juggling with some registers.

jmwright
Posts: 12
Joined: Tue Nov 29, 2016 2:57 am

Re: Turn WIFI Off On ESP8266 Boards

Post by jmwright » Thu Dec 08, 2016 3:05 pm

A friend just sent me this link with a very similar discussion.

viewtopic.php?t=1927

Post Reply