-
Notifications
You must be signed in to change notification settings - Fork 13.3k
add Low-Power demo #6989
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
add Low-Power demo #6989
Changes from 1 commit
0c870ae
fd1c366
b912664
287bc2d
7ea68d8
f77a2c5
387e30d
0db9254
3f3ab30
df75200
ab30950
11f1931
7d6a03b
2003ef4
acf3cec
2f2c508
47b73a2
36a8dbb
7178362
5d16fca
7a74da2
aa4feb2
8f4448d
b8e42e4
068f4bd
3118de5
ac40b6e
662b1f2
5695626
7627080
7b0e515
a41c381
b93c2e3
f4d00c6
841fa1b
efe55a0
ebc2b0a
c9c073a
222b9e8
9ef40f8
3ffb8ec
b902ed2
6ff566d
c8a5955
d9ea100
431f5dc
9597a12
7d3ee8d
701634e
b618e6c
3292f9b
1e80279
93a527b
6018d0b
55d95e2
b990e59
c107c43
fecacfd
601a5ae
a3ddde1
535d483
3775b1b
56cb239
c26ce4a
a76ec12
a79f48c
ee4c701
d378102
df1a494
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ The table below is an expanded version of Table 1.1 from the Low-Power Solutions | |
| Avg Current DTIM = 10 | 15.2 mA | | (0.55 mA) | | | | ||
|
||
Notes: | ||
|
||
(1) setting a sleep time of 0 for Deep Sleep turns off the RTC, requiring an external RESET to wake it | ||
|
||
(2) due to a bug in SDK 2, the minimum current will never be less than 2 mA and is frequently 15 mA between DTIM beacons | ||
|
@@ -45,43 +46,43 @@ The Average Current with different DTIM settings is unverified, and will likely | |
|
||
### Test 1 - Unconfigured modem | ||
|
||
This is typical for programs that don't use WiFi, and is a high current drain of at least 67 mA continuous. | ||
This is typical for programs that don't use WiFi, and is a high current drain of at least 67 mA continuous. This isn't a test as much as it sets a baseline or reference point for comparing the power savings. You can stop any time the CPU is halted or the LED is blinking to measure the current. | ||
|
||
### Test 2 - Automatic Modem Sleep | ||
|
||
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 it. The only time the modem sleeps is when you spend a long time in delay(), with delay times over 50mS. The LED blinks more slowly during this test as it's doing delay(350) to get the modem to sleep. While in delay() your sketch isn't doing anything worthwhile. Average current during long delay()s is 15 mA minimum. Without the delay() the average current is 67 mA with short spikes above 250 mA as transmissions occur. When the WiFi has traffic (even a couple of pings), the modem can turn on for over 2 seconds continuous at 67 mA, and it may stay on for a second after the traffic. In a high traffic environment you won't get any power savings with either of the 2 Automatic modes. Automatic Modem Sleep turns on 7-8 seconds after an active connection is established. | ||
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 it. The only time the modem sleeps is when you spend a long time in delay(), with delay times over 50mS. The LED blinks more slowly during this test as it's doing delay(350) to get the modem to sleep. While in delay() your sketch isn't doing anything worthwhile. Average current during a long delay() is 15 mA minimum. Without the delay() the average current is 67 mA with short spikes above 250 mA as transmissions occur. When the WiFi has traffic (even a couple of pings), the modem can turn on for over 2 seconds continuous at 67 mA, and it may stay on for a second after the traffic. In a high traffic environment you won't get any power savings with either of the 2 Automatic modes. Automatic Modem Sleep turns on 7-8 seconds after an active connection is established. | ||
|
||
### Test 3 - Forced Modem Sleep | ||
|
||
Turns off the modem (losing the connection), and dropping the current by 50 mA. This uses the WiFi library function. It's good if there is a long interval with no expected WiFi traffic, as you can do other things while only drawing 15 mA. | ||
Turns off the modem (losing the connection), and reducing the current by 50 mA. This test uses the WiFi library function. It's good if there is a long interval with no expected WiFi traffic, as you can do other things while only drawing 15 mA. | ||
|
||
### Test 4 - Automatic Light Sleep | ||
|
||
Like Automatic Modem Sleep, with the same restrictions. Once configured it's immediately active when a connection is established. During periods of long delay() the average current can drop to ~2 mA. In a network with sparse traffic you might get something near 2-5 mA average current. The LED blinks more slowly during this test as it's doing delay(350) to get the modem to sleep. | ||
|
||
### Test 5 - Forced Light Sleep | ||
|
||
Similar to Deep Sleep, but without the timer. The chip sleeps at 0.4 mA current until it is woken by an external interrupt. The only allowed interrupts are high level and low level; edge interrupts won't work. If you have a design that needs to be woken frequently (more often than every 2 seconds) then you should consider using Forced Light Sleep. For sleep periods longer than 2 seconds, Deep Sleep will be more efficient. The chip wakes after an interrupt in about 5.1mS. | ||
Similar to Deep Sleep, but without the timer. The chip sleeps at 0.4 mA current until it is woken by an external interrupt. The only allowed interrupts are high level and low level; edge interrupts won't work. If you have a design that needs to be woken frequently (more often than every 2 seconds) then you should consider using Forced Light Sleep. For sleep periods longer than 2 seconds, Deep Sleep will be more efficient. The chip wakes after an interrupt in about 5.1 mS, but WiFi was turned off to enter Forced Light Sleep so you may need to re-initialize it. | ||
|
||
### Test 6 - Deep Sleep, wake with RF_DEFAULT | ||
|
||
In Deep Sleep almost everything is turned off, and the chip draws ~20 uA. If you have D0/GPIO16 connected to RST, you can use the RTC timer to wake the chip up at a timed interval. You can also wake it with an external RESET. Waking with RF_DEFAULT means it will do an RFCAL if it needs to. These first two Deep Sleep tests use the standard Deep Sleep function, so the WiFi connection is closed and the modem turned off, which takes about 270mS before Deep Sleep begins. Deep Sleep ends with a RESET, and the boot time after that is around 120mS. Any Deep Sleep less than ~2 seconds is wasting power due to the modem shut-off and boot time, and Forced Light Sleep will be a better choice as it recovers in 5.1mS from the previous state. | ||
In Deep Sleep almost everything is turned off, and the chip draws ~ 20 uA. If you have D0/GPIO16 connected to RST, you can use the RTC timer to wake the chip up at a timed interval. You can also wake it with an external RESET. Waking with RF_DEFAULT means it will do an RFCAL if it needs to. Doing ESP.deepSleep(time) without the mode variable uses this wake mode. These first two Deep Sleep tests use the standard Deep Sleep function, so the WiFi connection is closed and the modem turned off, which takes about 270 mS before the Deep Sleep will begin. Deep Sleep ends with a RESET, and the boot time after that is ~ 120 mS. Any Deep Sleep less than ~ 2 seconds is wasting power due to the modem shut-off and boot time, and Forced Light Sleep will be a better choice as it recovers in 5.1 mS from the previous state. | ||
|
||
### Test 7 - Deep Sleep, wake with RFCAL | ||
|
||
Identical to the test above, but the modem does a power calibration when booting. In normal use, most people would do WAKE_RF_DEFAULT instead to minimize the extra RFCAL power burst if it's not needed. | ||
Identical to the test above, but the modem does an RF power calibration when booting. In normal use, most people would do WAKE_RF_DEFAULT instead to minimize the extra RFCAL power burst if it's not needed. | ||
|
||
### Test 8 - Deep Sleep Instant, wake with NO_RFCAL | ||
|
||
This variation doesn't do an automatic RF calibration, so power requirements will be slightly less. Additionally, *most* of the time it immediately goes into Deep Sleep without turning off the modem (that's the INSTANT part). There's another bug in SDK 2, and the SDK functions the WiFi-class calls occasionally do a modem shut-down before Deep Sleep; it's not always Instant. When it doesn't do the modem shut-down it saves an extra 270mS of power. | ||
This variation doesn't do an automatic RF calibration on return, so power requirements will be slightly less. Additionally, *most* of the time it immediately goes into Deep Sleep without turning off the modem (that's the INSTANT part). There's another bug in SDK 2, and the SDK functions the WiFi-class calls occasionally do a modem shut-down before Deep Sleep; it's not always Instant. When it doesn't do the modem shut-down it saves an extra 270mS of power. | ||
|
||
### Test 9 - Deep Sleep Instant, wake with RF_DISABLED | ||
|
||
This last variation also uses Deep Sleep Instant, but it wakes up with the modem disabled so current after Deep Sleep is only 15 mA. Each of the 4 WAKE styles has their own use, depending on what you need. | ||
|
||
--- | ||
|
||
All of the Deep Sleep modes end with a RESET, so you must re-initialize everything. You can store *some* information in the RTC memory to survive a Deep Sleep reset, which was done in this demo to illustrate it. See the **RTCUserMemory** example for more on this feature. | ||
All of the Deep Sleep modes end with a RESET, so you must re-initialize everything. You can store *some* information in the RTC memory to survive a Deep Sleep reset, which was done in this demo to illustrate the RTC memory. See the **RTCUserMemory** example for more information on this feature. | ||
|
||
The maximum Deep Sleep interval is 71.58 minutes (2^32 -1 microseconds), although the actual interval may be something less than that. | ||
|
||
|
@@ -92,7 +93,7 @@ If you need a longer sleep period than 72 minutes, you can pass zero as the time | |
|
||
### Lower Power without the WiFi library: | ||
|
||
If all you want to do is reduce power for a sketch that doesn't need WiFi, add these SDK 2 functions to your code: | ||
If all you want to do is reduce power for a sketch that doesn't need WiFi, add these SDK 2 functions anywhere in your code: | ||
```c | ||
wifi_station_disconnect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are these functions to be added by the user? setup()? there is also preinit(), which allows doing things much earlier. I believe there is already an example included where wifi is disabled in preinit. Does doing that improve on this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't see the other example (doing the same thing). I haven't looked at any examples that weren't of immediate interest. I saw several people on forums and elsewhere attempting this and failing, instead. That's why I added it to the README. You can include that chunk anywhere, all it does it turn off the modem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no timeout on the WiFi connection, and none on the pushbutton waits. Those are the only two waits I know of offhand. If it never connects, turn on the debug option and see why the WiFi failed. As far as never pushing the button goes, ummm... how simple ARE kids nowadays? The bottom line on the serial monitor says "press the button to continue" each time it stops. Half of the tests need an active WiFi connection, so I don't really want to fail into the code with nothing more than a warning on the monitor that all hell has broken loose on WiFi so we're running half-functional. Maybe I should be more explicit that it needs an active WiFi connection to run the tests... I never tried without here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just forced a WiFi fail and continued on into the code: both of the Automatic tests fail as there's no WiFi connection: neither one ever went into low-power mode. If I put in a timeout on WiFi, I'll need to add additional checks in to skip those two tests in the event of WiFi failure. The other tests ran OK. Aren't 99% of people buying the ESP8266 because they want WiFi? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OTA is gutted out, and a 30 second timeout on WiFi added. If it fails connection it skips the two 'Automatic' tests as they won't do anything. They won't fail or anything, but they won't work without an active connection. CRC32 integration is the last step I'm working on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, hopefully it passes the style check THIS time around. 😝 |
||
wifi_set_opmode(NULL_MODE); | ||
|
@@ -101,7 +102,7 @@ If all you want to do is reduce power for a sketch that doesn't need WiFi, add t | |
wifi_fpm_do_sleep(0xFFFFFFF); | ||
delay(1); | ||
``` | ||
That allows you to shut down the modem *without* loading the WiFi library, dropping your average current by 50 mA, or around 1/5th of the initial power. You have to add it as shown preferably in setup(), although the delay() can be longer. It doesn't time out at 71 minutes, as you might think from the (0xFFFFFFF). The Forced Modem Sleep test does the same thing with a WiFi library call that essentially encapsulates the code above. | ||
That allows you to shut down the modem *without* loading the WiFi library, dropping your average current by 50 mA, or around 1/5th of the initial power. You have to add it as shown (preferably in setup()), although the delay() can be longer. It doesn't time out at 71 minutes, as you might think from the (0xFFFFFFF). The Forced Modem Sleep test does the same thing with a WiFi library call that essentially encapsulates the code above. | ||
|
||
You can also use the Deep Sleep modes without loading the WiFi library, as they use ESP API functions. The tests above try to bring the WiFi up to show you the differences after the 4 reset modes. | ||
You can also use the Deep Sleep modes without loading the WiFi library, as they use ESP API functions. The Deep Sleep tests above try to bring the WiFi up to show you the differences after the 4 reset modes. With the WiFi turned off you always get an instant Deep Sleep. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would get replaced by the RTCData::writeToRTC() method, declared and defined within the class at the start of the sketch.