Skip to content
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

Merged
merged 69 commits into from
Feb 2, 2020
Merged
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
0c870ae
add Low-Power demo
Tech-TX Jan 6, 2020
fd1c366
add Low-Power demo
Tech-TX Jan 6, 2020
b912664
add Low-Power demo, remove OTA and add WiFi timeout
Tech-TX Jan 9, 2020
287bc2d
add Low-Power demo
Tech-TX Jan 6, 2020
7ea68d8
add Low-Power demo
Tech-TX Jan 6, 2020
f77a2c5
add Low-Power demo, remove OTA and add WiFi timeout
Tech-TX Jan 9, 2020
387e30d
add Low-Power demo, remove OTA and add WiFi timeout
Tech-TX Jan 9, 2020
0db9254
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 9, 2020
3f3ab30
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 10, 2020
df75200
add Low-Power demo
Tech-TX Jan 10, 2020
ab30950
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 10, 2020
11f1931
add Low-Power demo
Tech-TX Jan 10, 2020
7d6a03b
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 10, 2020
2003ef4
add Low-Power demo
Tech-TX Jan 10, 2020
acf3cec
add Low-Power demo
Tech-TX Jan 10, 2020
2f2c508
add Low-Power demo
Tech-TX Jan 11, 2020
47b73a2
add Low-Power demo
Tech-TX Jan 11, 2020
36a8dbb
add Low-Power demo
Tech-TX Jan 11, 2020
7178362
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 11, 2020
5d16fca
add Low-Power demo
Tech-TX Jan 12, 2020
7a74da2
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 12, 2020
aa4feb2
add Low-Power demo
Tech-TX Jan 12, 2020
8f4448d
add Low-Power demo
Tech-TX Jan 12, 2020
b8e42e4
add Low-Power demo
Tech-TX Jan 12, 2020
068f4bd
add Low-Power demo
Tech-TX Jan 12, 2020
3118de5
add Low-Power demo
Tech-TX Jan 12, 2020
ac40b6e
add Low-Power demo
Tech-TX Jan 12, 2020
662b1f2
add Low-Power demo
Tech-TX Jan 13, 2020
5695626
add Low-Power demo
Tech-TX Jan 16, 2020
7627080
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 17, 2020
7b0e515
add Low-Power demo
Tech-TX Jan 17, 2020
a41c381
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 17, 2020
b93c2e3
add Low-Power demo
Tech-TX Jan 17, 2020
f4d00c6
add Low-Power demo
Tech-TX Jan 18, 2020
841fa1b
add Low-Power demo
Tech-TX Jan 18, 2020
efe55a0
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 18, 2020
ebc2b0a
add Low-Power demo
Tech-TX Jan 22, 2020
c9c073a
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 22, 2020
222b9e8
add Low-Power demo
Tech-TX Jan 25, 2020
9ef40f8
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 25, 2020
3ffb8ec
add Low-Power demo
Tech-TX Jan 26, 2020
b902ed2
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 26, 2020
6ff566d
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 26, 2020
c8a5955
add Low-Power demo
Tech-TX Jan 26, 2020
d9ea100
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 26, 2020
431f5dc
add Low-Power demo
Tech-TX Jan 28, 2020
9597a12
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 28, 2020
7d3ee8d
add Low-Power demo
Tech-TX Jan 28, 2020
701634e
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 28, 2020
b618e6c
add Low-Power demo
Tech-TX Jan 29, 2020
3292f9b
add Low-Power demo
Tech-TX Jan 29, 2020
1e80279
add Low-Power demo
Tech-TX Jan 29, 2020
93a527b
add Low-Power demo
Tech-TX Jan 29, 2020
6018d0b
add Low-Power demo
Tech-TX Jan 30, 2020
55d95e2
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 30, 2020
b990e59
add Low-Power demo
Tech-TX Jan 31, 2020
c107c43
add Low-Power demo
Tech-TX Jan 31, 2020
fecacfd
add Low-Power demo
Tech-TX Jan 31, 2020
601a5ae
add Low-Power demo
Tech-TX Jan 31, 2020
a3ddde1
add Low-Power demo
Tech-TX Jan 31, 2020
535d483
add Low-Power demo
Tech-TX Jan 31, 2020
3775b1b
add Low-Power demo
Tech-TX Feb 1, 2020
56cb239
add Low-Power demo
Tech-TX Feb 1, 2020
c26ce4a
add Low-Power demo
Tech-TX Feb 1, 2020
a76ec12
add Low-Power demo
Tech-TX Feb 1, 2020
a79f48c
add Low-Power demo
Tech-TX Feb 1, 2020
ee4c701
add Low-Power demo
Tech-TX Feb 1, 2020
d378102
add Low-Power demo
Tech-TX Feb 1, 2020
df1a494
Merge branch 'master' into add_Low-Power_demo
Tech-TX Feb 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add Low-Power demo
Tech-TX committed Jan 9, 2020
commit 7ea68d82d4bb8f1836dd86355349df8d4f1330b0
40 changes: 20 additions & 20 deletions libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino
Original file line number Diff line number Diff line change
@@ -39,11 +39,11 @@
#define DEBUG_PRINT(x)
#endif

#define WAKE_UP_PIN D3 // GPIO0, can also force a serial flash upload with RESET
#define WAKE_UP_PIN 0 // D3/GPIO0, can also force a serial flash upload with RESET

// un-comment one of the two lines below for your LED connection
#define LED D1 // external LED for modules with built-in LEDs so it doesn't add to the current
//#define LED D4 // GPIO2 LED for ESP-01,07 modules; D4 is LED_BUILTIN on most other modules
#define LED 5 // D1/GPIO5 external LED for modules with built-in LEDs so it doesn't add to the current
//#define LED 2 // D4/GPIO2 LED for ESP-01,07 modules; D4 is LED_BUILTIN on most other modules

ADC_MODE(ADC_VCC); // allows us to monitor the internal VCC level; it varies with WiFi load
// don't connect anything to the analog input pin(s)!
@@ -69,7 +69,7 @@ struct {
byte data[4]; // the last byte stores the reset count
} rtcData;

byte resetLoop = 0; // keeps track of the number of Deep Sleep tests / resets
byte resetCount = 0; // keeps track of the number of Deep Sleep tests / resets
String resetCause = "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resetCause isn't needed, the line should be removed. You are declaring it inside setup(), and using it only there, so that local declaration is enough.

Copy link
Contributor Author

@Tech-TX Tech-TX Jan 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'd forgotten I moved that whole thing inside of setup(). Removed.

For whatever reason, I got exceptions if I tried to do multiple reads of ESP.getResetReason() like this:

  Serial.println(ESP.getResetReason());
  if ((ESP.getResetReason() == "External System") || (ESP.getResetReason() == "Power on")) {

I didn't try to hunt it down, as it was a very long stack dump. I've never seen a stack dump that long. That's why I read it once into a string.


const unsigned int blinkDelay = 100; // fast blink rate for the LED when waiting for the user
@@ -91,23 +91,23 @@ void setup() {
Serial.println(resetCause);
if (resetCause == "External System") {
Serial.println(F("I'm awake and starting the low power tests"));
resetLoop = 5;
resetCount = 5;
updateRTC(); // if external reset, wipe the RTC memory and start all over
}

// Read struct from RTC memory
if (ESP.rtcUserMemoryRead(64, (uint32_t*) &rtcData, sizeof(rtcData))) {
uint32_t crcOfData = calculateCRC32((uint8_t*) &rtcData.data[0], sizeof(rtcData.data));
if (crcOfData != rtcData.crc32) { // if the CRC is invalid
resetLoop = 0; // set first test loop since power on or external reset
resetCount = 0; // set first test loop since power on or external reset
} else {
resetLoop = rtcData.data[3]; // read the previous reset count
resetCount = rtcData.data[3]; // read the previous reset count
}
}
} // end of Setup()

void loop() {
if (resetLoop == 0) {
if (resetCount == 0) {
// 1st test - running with WiFi unconfigured, reads ~67 mA minimum
Serial.println(F("\n1st test - running with WiFi unconfigured"));
float volts = ESP.getVcc();
@@ -171,7 +171,7 @@ void loop() {
Serial.println(F("\n6th test - Deep Sleep for 10 seconds, wake with RF_DEFAULT"));
init_WiFi(); // initialize WiFi since we turned it off in the last test
init_OTA();
resetLoop = 1; // advance to the next Deep Sleep test after the reset
resetCount = 1; // advance to the next Deep Sleep test after the reset
updateRTC(); // save the current test state in RTC memory
volts = ESP.getVcc();
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000 );
@@ -192,12 +192,12 @@ void loop() {
}

// 7th test - Deep Sleep for 10 seconds, wake with RFCAL
if (resetLoop < 4) {
if (resetCount < 4) {
init_WiFi(); // need to reinitialize WiFi & OTA due to Deep Sleep resets
init_OTA(); // since we didn't do it in setup() because of the first test
}
if (resetLoop == 1) { // second reset loop since power on
resetLoop = 2; // advance to the next Deep Sleep test after the reset
if (resetCount == 1) { // second reset loop since power on
resetCount = 2; // advance to the next Deep Sleep test after the reset
updateRTC(); // save the current test state in RTC memory
Serial.println(F("\n7th test - in RF_DEFAULT, Deep Sleep for 10 seconds, wake with RFCAL"));
float volts = ESP.getVcc();
@@ -212,8 +212,8 @@ void loop() {
}

// 8th test - Deep Sleep Instant for 10 seconds, wake with NO_RFCAL
if (resetLoop == 2) { // third reset loop since power on
resetLoop = 3; // advance to the next Deep Sleep test after the reset
if (resetCount == 2) { // third reset loop since power on
resetCount = 3; // advance to the next Deep Sleep test after the reset
updateRTC(); // save the current test state in RTC memory
Serial.println(F("\n8th test - in RFCAL, Deep Sleep Instant for 10 seconds, wake with NO_RFCAL"));
float volts = ESP.getVcc();
@@ -228,8 +228,8 @@ void loop() {
}

// 9th test - Deep Sleep Instant for 10 seconds, wake with RF_DISABLED
if (resetLoop == 3) { // fourth reset loop since power on
resetLoop = 4; // advance to the next Deep Sleep test after the reset
if (resetCount == 3) { // fourth reset loop since power on
resetCount = 4; // advance to the next Deep Sleep test after the reset
updateRTC(); // save the current test state in RTC memory
Serial.println(F("\n9th test - in NO_RFCAL, Deep Sleep Instant for 10 seconds, wake with RF_DISABLED"));
float volts = ESP.getVcc();
@@ -243,8 +243,8 @@ void loop() {
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
}

if (resetLoop == 4) {
resetLoop = 5; // start all over
if (resetCount == 4) {
resetCount = 5; // start all over
updateRTC(); // save the current test state in RTC memory
float volts = ESP.getVcc();
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000 );
@@ -299,10 +299,10 @@ uint32_t calculateCRC32(const uint8_t *data, size_t length) {
}

void updateRTC() {
Copy link
Collaborator

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.

rtcData.data[3] = resetLoop; // save the loop count for the next reset
rtcData.data[3] = resetCount; // save the loop count for the next reset
// Update CRC32 of data
rtcData.crc32 = calculateCRC32((uint8_t*) &rtcData.data[0], sizeof(rtcData.data));
if (resetLoop == 5) // wipe the CRC in RTC memory when we're done with all tests
if (resetCount == 5) // wipe the CRC in RTC memory when we're done with all tests
rtcData.crc32 = 0;
// Write struct to RTC memory
ESP.rtcUserMemoryWrite(64, (uint32_t*) &rtcData, sizeof(rtcData));
6 changes: 3 additions & 3 deletions libraries/esp8266/examples/LowPowerDemo/README.md
Original file line number Diff line number Diff line change
@@ -48,11 +48,11 @@ This is typical for programs that don't use WiFi, and is a high current drain of

### 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. However, it's not as wonderful as it may seem, as 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 I'm doing delay(350) to get the modem to sleep. While in delay() your sketch isn't doing anything interesting. 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 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. However, it's not as wonderful as it may seem, as 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 I'm doing delay(350) to get the modem to sleep. While in delay() your sketch isn't doing anything interesting. 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.

### 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 traffic, as you can do other things while only drawing 15 mA.
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.

### Test 4 - Automatic Light Sleep

@@ -68,7 +68,7 @@ In Deep Sleep almost everything is turned off, and the chip draws ~20 uA. If yo

### Test 7 - Deep Sleep, wake with RFCAL

Identical to the test above, but the modem does a power calibration when booting. In normal use, I'd likely do WAKE_RF_DEFAULT instead to save the extra RFCAL power burst if it's not needed.
Identical to the test above, but the modem does a power calibration when booting. In normal use, I'd likely 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