Saving power

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
pythoncoder
Posts: 3121
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Saving power

Post by pythoncoder » Mon Mar 27, 2017 6:02 am

To disable WiFi you need the following:

Code: Select all

import network
ap = network.WLAN(network.AP_IF)
ap.active(False)  # Disable access point
sta_if = network.WLAN(network.STA_IF)
sta_if.active(False)  # Disable station interface
Peter Hinch

User avatar
Roberthh
Posts: 1114
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Saving power

Post by Roberthh » Mon Mar 27, 2017 9:23 am

Without wanting to be pedantic (but being so) it should be noted, that disabling WiFi this way does not reduce power consumption much. It still stays at about 80 mA.

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

Re: Saving power

Post by kfricke » Mon Mar 27, 2017 7:19 pm

The ESP8266 radio can be turned off, but it is not implemented. It is a startup flag and switching this involves rebooting the MCU completely.

mhepp
Posts: 19
Joined: Thu May 28, 2015 5:50 pm

Re: Saving power

Post by mhepp » Thu Jul 13, 2017 2:06 pm

Hi all,

is there an update on this? I can see many applications that do either not need wifi at all, or only for a small fraction of their duty cycle, so reducing power by the various sleep modes does not really help. Think of a sensor that will collect data over an hour or so and post only averages to a server once for each interval.

Martin

swanduron
Posts: 9
Joined: Mon Mar 13, 2017 9:03 am

Re: Saving power

Post by swanduron » Wed Oct 18, 2017 2:17 am

The ESP8266 has provided a deep sleep mode which has been implemented in micropython power management. Please see the document as below:

https://docs.micropython.org/en/latest/ ... rctrl.html

I write a demo for my IoT project, the sensor has a ESP8266 and one DHT22 sensor and the size of sensor's shell only about 60mm * 25mm * 10mm. To avoid the impact of DHT22 result, I put ESP8266 in deep sleep mode every ~70s. Paste code as below, I hope it is useful to you.

In additional, I test this code both in Aruba AP205 and Cisco WLC2504 with 3702i, they can hold the wifi association for this module during deep sleep and ESP8266 can get its network info in 1 second.

CAUTION: Please read below info carefully

The deep-sleep mode will shut down the ESP8266 and all its peripherals, including the WiFi (but not including the real-time-clock, which is used to wake the chip). This drastically reduces current consumption and is a good way to make devices that can run for a while on a battery.
To be able to use the deep-sleep feature you must connect GPIO16 to the reset pin (RST on the Adafruit Feather HUZZAH board).


Code: Select all

import machine
import network
import time
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
rtc.alarm(rtc.ALARM0, 90000)
time.sleep(2)

if machine.reset_cause() == machine.DEEPSLEEP_RESET:
    print('woke from a deep sleep')
else:
    print('power on or hard reset')

sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)

if sta_if.isconnected():
	print('Wireless association is reserved!')
	print(sta_if.ifconfig())
else:
	sta_if.connect('XXXXXXX', 'XXXXXXXX')
	time.sleep(2)
	print(sta_if.ifconfig())


for i in range(10): #for wake test here
	time.sleep(1)
	print('Before deep sleep, system working in [%s] seconds' % i)

print('Prepare to sleep in 2s')
time.sleep(2)
machine.deepsleep()

User avatar
devnull
Posts: 290
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: Saving power

Post by devnull » Sun Oct 21, 2018 11:23 pm

Has there been any change in the ability to completely switch off the wifi radio on the esp8266 ?

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: Saving power

Post by WhiteHare » Mon Oct 22, 2018 1:03 am

Regarding the OP, if you're serious about wanting to run low power, you're better off switching to a platform like, for example, the nRF52, that's designed from the ground up to be low power. Use the ESPx's as gateways instead.

User avatar
devnull
Posts: 290
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: Saving power

Post by devnull » Mon Oct 22, 2018 2:28 am

@WhiteHare - Thanks, I have just ordered a few nRF52840 from seeed for testing.

I see there's a list of things that are working in the nrf port readme, but do you know specifically what is NOT working :-)

I presume that the radio can be completely disabled ?

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: Saving power

Post by WhiteHare » Mon Oct 22, 2018 4:15 am

devnull wrote:
Mon Oct 22, 2018 2:28 am
I presume that the radio can be completely disabled ?
yes.

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: Saving power

Post by WhiteHare » Mon Oct 22, 2018 11:54 am

Of course, depending on what you want to do, there is this (or similar) as a way to save power and still use an ESPx:
https://www.tindie.com/products/kdcircu ... -platform/

So, for instance, if you were making a water leak detector, maybe this would be good enough. In that case it would only need to wake up in the rare event of a water leak and perhaps to give you a heartbeat once every two hours to report on its battery level. The rest of the time it would simply be turned completely OFF (i.e. including full loss of RAM contents), during which time the hardware would be drawing mere nanoamps. It's admittedly a rather brute force way to address the issue, but, meh, if it fits your use case, maybe you'd want to consider it.

Post Reply