Skip to content

Return error in class deepSleep() when max sleeptime is exceeded #4936

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 26 commits into
base: master
Choose a base branch
from
Open
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ extern "C" void esp_yield();

void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
{
if (time_us > deepSleepMax()) // we need to prevent the esp8266 from not waking up from deepsleep
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hate to dogpile here, but if you do find out that deepSleepMax() doesn't really work and need to derate by 5% or whatever, please use that # to compare and not deepSleepMax() in this if condition. Otherwise someone will pass in, say, deepSleepMax() - 1 which won't work but which won't be caught by this check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it also be wise to increasingly loop the whole function until users's time_us is reached ?

{
time_us = deepSleepMax() - (deepSleepMax() / 20); // 5% correction because of inaccurate timekeeping by the esp8266
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println("Warning: max sleeptime exceeded; sleeptime has been adjusted to max possible sleeptime!");
#endif
}
system_deep_sleep_set_option(static_cast<int>(mode));
system_deep_sleep(time_us);
esp_yield();
Expand Down