8000 add Low-Power demo by Tech-TX · Pull Request #6989 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

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

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
  • Loading branch information
Tech-TX committed Jan 29, 2020
commit 1e80279a465cce71dd6aa6fc2da4acf26201284b
53 changes: 22 additions & 31 deletions libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ IPAddress dns1(0, 0, 0, 0);
IPAddress dns2(0, 0, 0, 0);
uint32_t wifiTimeout = 30E3; // 30 second timeout on the WiFi connection

//#define testPoint 4 // D2/GPIO4 used to track the timing of several test cycles (optional)
//#define TESTPOINT // used to track the timing of several test cycles (optional)
#ifdef TESTPOINT
#define testPointPin 4 // D2/GPIO4, you can use any pin that supports interrupts
#define testPoint_HIGH digitalWrite(testPointPin, HIGH)
#define testPoint_LOW digitalWrite(testPointPin, LOW)
#else
#define testPoint_HIGH
#define testPoint_LOW
#endif

// This structure is stored in RTC memory to save the WiFi state and reset count (number of Deep Sleeps),
// and it reconnects twice as fast as the first connection; it's used extensively in this demo
Expand All @@ -94,10 +102,8 @@ esp8266::polledTimeout::oneShotFastMs altDelay(blinkDelay); // tight loop to si

void wakeupCallback() { // unlike ISRs, you can do a print() from a callback function
wifi_fpm_close(); // disable Light Sleep
#ifdef testPoint
digitalWrite(testPoint, LOW); // testPoint tracks latency from WAKE_UP_PIN LOW to testPoint LOW
#endif
printMillis(); // show time difference across sleep
testPoint_LOW; // testPoint tracks latency from WAKE_UP_PIN LOW to testPoint LOW
printMillis(); // show time difference across sleep; millis is wrong as the CPU eventually stops
Serial.println(F("Woke from Light Sleep - this is the callback"));
}

Expand All @@ -106,9 +112,9 @@ void preinit() {
}

void setup() {
#ifdef testPoint
pinMode(testPoint, OUTPUT); // test point for Light Sleep and Deep Sleep tests
digitalWrite(testPoint, LOW); // Deep Sleep reset doesn't clear GPIOs, testPoint LOW shows boot time
#ifdef TESTPOINT
pinMode(testPointPin, OUTPUT); // test point for Light Sleep and Deep Sleep tests
testPoint_LOW; // Deep Sleep reset doesn't clear GPIOs, testPoint LOW shows boot time
#endif
pinMode(LED, OUTPUT); // activity and status indicator
digitalWrite(LED, LOW); // turn on the LED
Expand Down Expand Up @@ -233,22 +239,19 @@ void runTest5() {
Serial.println(F("Press the button when you are ready to proceed"));
waitPushbutton(true, blinkDelay);
WiFi.mode(WIFI_OFF); // you must turn the modem off; using disconnect won't work
// delay(10);
// delay(10);
digitalWrite(LED, HIGH); // turn the LED off so they know the CPU isn't running
readVoltage(); // read internal VCC
printMillis(); // show time difference across sleep, including Serial.flush();
#ifdef testPoint
digitalWrite(testPoint, HIGH);
// testPoint LOW in callback tracks delay from testPoint HIGH to testPoint LOW
#endif
testPoint_HIGH; // testPoint LOW in callback tracks delay from testPoint HIGH to LOW
extern os_timer_t *timer_list;
timer_list = nullptr; // stop (but don't disable) the 4 OS timers
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
gpio_pin_wakeup_enable(GPIO_ID_PIN(WAKE_UP_PIN), GPIO_PIN_INTR_LOLEVEL); // GPIO wakeup (optional)
// only LOLEVEL or HILEVEL interrupts work, no edge, that's an SDK or CPU limitation
wifi_fpm_set_wakeup_cb(wakeupCallback); // Set wakeup callback (optional)
wifi_fpm_open();
wifi_fpm_do_sleep(10E6); // Sleep Range 10000 ~ 268,435,454 uS (0xFFFFFFE, 2^28-1)
wifi_fpm_do_sleep(10E6); // Sleep Range = 10000 ~ 268,435,454 uS (0xFFFFFFE, 2^28-1)
delay(10e3 + 1); // delay needs to be 1 mS longer than sleep or it only goes into Modem Sleep
Serial.println(F("Woke up!")); // the interrupt callback hits before this is executed
}
Expand All @@ -257,12 +260,8 @@ void runTest6() {
Serial.println(F("\n6th test - Forced Light Sleep, wake with GPIO interrupt"));
Serial.flush();
WiFi.mode(WIFI_OFF); // you must turn the modem off; using disconnect won't work
// delay(10); // testPoint is only low for 18 mS without this delay()
digitalWrite(LED, HIGH); // turn the LED off so they know the CPU isn't running
#ifdef testPoint
digitalWrite(testPoint, HIGH);
// testPoint tracks latency from WAKE_UP_PIN LOW to testPoint LOW in callback
#endif
testPoint_HIGH; // testPoint tracks latency from WAKE_UP_PIN LOW to testPoint LOW in callback
readVoltage(); // read internal VCC
Serial.println(F("CPU going to sleep, pull WAKE_UP_PIN low to wake it (press the switch)"));
printMillis(); // show time difference across sleep
Expand Down Expand Up @@ -291,9 +290,7 @@ void runTest7() {
// and no extended RFCAL as it goes into Deep Sleep
Serial.println(F("going into Deep Sleep now..."));
printMillis(); // show time difference across sleep
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint set HIGH to track Deep Sleep period, cleared at startup()
#endif
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
ESP.deepSleep(10E6, WAKE_RF_DEFAULT); // good night! D0 fires a reset in 10 seconds...
// if you do ESP.deepSleep(0, mode); it needs a RESET to come out of sleep (RTC is disconnected)
// maximum timed Deep Sleep interval = 71.58 minutes with 0xFFFFFFFF
Expand All @@ -311,9 +308,7 @@ void runTest8() {
// and no extended RFCAL as it goes into Deep Sleep
Serial.println(F("going into Deep Sleep now..."));
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn&# 9548 39;t print the whole message
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint set HIGH to track Deep Sleep period, cleared at startup()
#endif
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
ESP.deepSleep(10E6, WAKE_RFCAL); // good night! D0 fires a reset in 10 seconds...
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
}
Expand All @@ -326,9 +321,7 @@ void runTest9() {
WiFi.mode(WIFI_SHUTDOWN, &nv->wss); // Forced Modem Sleep for a more Instant Deep Sleep
Serial.println(F("going into Deep Sleep now..."));
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint set HIGH to track Deep Sleep period, cleared at startup()
#endif
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
ESP.deepSleepInstant(10E6, WAKE_NO_RFCAL); // good night! D0 fires a reset in 10 seconds...
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
}
Expand All @@ -341,9 +334,7 @@ void runTest10() {
//WiFi.mode(WIFI_SHUTDOWN); // Forced Modem Sleep for a more Instant Deep Sleep
Serial.println(F("going into Deep Sleep now..."));
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint set HIGH to track Deep Sleep period, cleared at startup()
#endif
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
ESP.deepSleepInstant(10E6, WAKE_RF_DISABLED); // good night! D0 fires a reset in 10 seconds...
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
}
Expand Down
0