8000 Extending on the new WiFi-less startup and new power saving APIs in ESP class by dok-net · Pull Request #7979 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Extending on the new WiFi-less startup and new power saving APIs in ESP class #7979

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

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
810fed9
WiFi is off by default anyway.
dok-net Apr 13, 2021
a1ceef3
Set deep sleep resume and powerup RF modes to OFF.
dok-net Apr 15, 2021
9538ef9
Implement forced light sleep in Esp class
dok-net Apr 15, 2021
1ecdfc1
Add low power forced light sleep demo.
dok-net Apr 15, 2021
ef2bc95
Implement auto light sleep and auto modem sleep in Esp class
dok-net Apr 15, 2021
9891613
Add auto sleep mode demo.
dok-net Apr 15, 2021
ea94626
Refactoring MODEM forced sleep code from ESP8266WiFi to core ESP class.
dok-net Apr 16, 2021
7137d0f
Add new Esp class member functions to host test MockEsp.cpp
dok-net Apr 16, 2021
7fea539
API refactoring.
dok-net Apr 16, 2021
446aea7
Missed that there are different functions for auto and force sleep ty…
dok-net Apr 17, 2021
6a07829
DRY
dok-net Apr 17, 2021
49c2ac0
enable callback in forced light sleep example
dok-net Apr 17, 2021
e7864f1
instead of crude manual mangling and no prototypes, put the weak symb…
dok-net Apr 17, 2021
79a7ee8
Example for a forced modem sleep with timeout and callback.
dok-net Apr 18, 2021
788731e
Save 9ms for force MODEM sleep activation.
dok-net Apr 18, 2021
433cd17
Add timer_list debug dump to forced light sleep
dok-net Apr 19, 2021
24efea2
Auto light sleep is all about WiFi and requires a connection to an AP
dok-net Apr 22, 2021
83e70ee
Some comments from memory of what testing revealed. Independent verif…
dok-net Apr 24, 2021
c0326f0
Copyright notices and clarifying introductory comments in example code.
dok-net Apr 25, 2021
7c4879f
Increase delay time to let example actually show measurable times in …
dok-net Apr 25, 2021
01eb942
Remove unintended copy&paste artifact.
dok-net Apr 25, 2021
382f6fd
Reset ISR to edge triggered mode when back from sleep via timeout ins…
dok-net Apr 25, 2021
213a2e0
AttachInterrupt is not available in ISR (IRAM_ATTR), fix crash on stu…
dok-net Apr 25, 2021
56c40f3
SDK needs idle task to perform mode switching. Reset the callback poi…
dok-net Apr 25, 2021
affc7fc
Fix serial bitrate in example.
dok-net Apr 25, 2021
6015cec
Debounce the button GPIO in order to prevent crashes due to IRQ storms.
dok-net Apr 25, 2021
b6e14f6
Add documentation for the new ESP sleep modes to libraries.rst
dok-net Apr 26, 2021
ad454ea
Fix headline in documentation as well.
dok-net Apr 26, 2021
74951fd
By review comment.
dok-net Apr 26, 2021
0a70272
ESP.deepSleep[Instant] refactoring to match the setting of RF mode in…
dok-net Apr 27, 2021
df7e909
More comprehensive description of the usage of forcedLightSleep.
dok-net Apr 28, 2021
1af1380
Be more specific about ForcedLightSleepEnd.
dok-net Apr 28, 2021
a9d9cda
Describe forced light sleep initiation in more detail.
dok-net Apr 28, 2021
e8798ac
Add neverSleep and neverSleepOff to Esp class, use them in core and l…
dok-net May 17, 2021
3fc7d23
Apply suggested style fixes.
dok-net Mar 13, 2022
abd17a7
There may exist code expecting this macro definition to overwrite the…
dok-net Mar 12, 2023
a6d1f73
Merge branch 'master' into wifioff
dok-net Mar 31, 2023
5a2c2db
Merge branch 'master' into wifioff
dok-net Apr 23, 2023
2d1cb1c
Merge branch 'master' into wifioff
dok-net May 13, 2023
9847e1f
Merge branch 'master' into wifioff
dok-net Jun 17, 2023
b8a95de
Reviewer noticed that esp_suspend is part of the core for awhile now …
dok-net Jun 21, 2023
dd6ea93
Implement RAII-patterned token class for ForcedLightSleep begin()/end().
dok-net Jun 24, 2023
6252680
Code style fixes.
8000 dok-net Jun 24, 2023
cd6d155
Merge branch 'master' into wifioff
dok-net Aug 5, 2023
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
Auto light sleep is all about WiFi and requires a connection to an AP
  • Loading branch information
dok-net committed Mar 12, 2023
commit 24efea2f664d8c479eb246875ece3223ab0e92d7
109 changes: 94 additions & 15 deletions libraries/esp8266/examples/AutoSleepDemo/AutoSleepDemo.ino
Original file line number Diff line number Diff line change
@@ -1,25 +1,104 @@
#include <Schedule.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <PolledTimeout.h>
#include <Schedule.h>

#ifndef D5
#define D5 (14)
#endif

// enter your WiFi configuration below
const char* AP_SSID = "SSID"; // your router's SSID here
const char* AP_PASS = "PSK"; // your router's password here

uint32_t timeout = 30E3; // 30 second timeout on the WiFi connection
esp8266::polledTimeout::oneShotMs wifiTimeout(timeout); // 30 second timeout on WiFi connection

ESP8266WebServer server(80);

void handleRoot() {
server.send(200, "text/plain", "hello from esp8266!\r\n");
}

void handleNotFound() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}

void setup() {
Serial.begin(74880);
Serial.begin(74800);
while (!Serial);
delay(100);
Serial.println("AutoLightSleep");
Serial.flush();
}
Serial.println();
WiFi.mode(WIFI_STA);
WiFi.begin(AP_SSID, AP_PASS);
Serial.print(F("connecting to WiFi "));
Serial.println(WiFi.SSID());

void loop() {
delay(10000); // this enters the idle task
wifiTimeout.reset(timeout);
while (((!WiFi.localIP()) || (WiFi.status() != WL_CONNECTED)) && (!wifiTimeout)) {
yield();
}
if ((WiFi.status() != WL_CONNECTED) || !WiFi.localIP()) {
Serial.println(F("WiFi timed out and didn't connect"));
} else {
Serial.println(F("IP address: "));
Serial.println(WiFi.localIP());
}
WiFi.setAutoReconnect(true);

//if (MDNS.begin("esp8266")) {
// Serial.println("MDNS responder started");
//}

server.on("/", handleRoot);

server.on("/on", []() {
tone(D5, 440);
server.send(200, "text/plain", "tone on");
});

server.on("/off", []() {
noTone(D5);
server.send(200, "text/plain", "tone off");
});

Serial.println("entering auto sleep section");
Serial.flush();
ESP.autoLightSleep();
// ESP.autoModemSleep();
server.on("/sleep", []() {
ESP.autoLightSleep();
wifi_fpm_set_wakeup_cb([]() {
schedule_function([]() {
Serial.println("auto light sleep wakeup CB");
});
});
server.send(200, "text/plain", "auto light sleep on");
});

delay(10000); // this enters the idle task with auto light sleep
server.on("/nosleep", []() {
ESP.autoSleepOff();
server.send(200, "text/plain", "sleep off");
});

ESP.autoSleepOff();
Serial.println("left auto sleep section");
Serial.flush();
server.onNotFound(handleNotFound);

server.begin();

Serial.println("HTTP server started");
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
digitalWrite(LED_BUILTIN, LOW);
server.handleClient();
digitalWrite(LED_BUILTIN, HIGH);
delay(1);
}
0