Skip to content

Commit

Permalink
fixed bug that would cause sleep durations to sometimes being twice a…
Browse files Browse the repository at this point in the history
…s long as they should be
  • Loading branch information
lmarzen committed Oct 27, 2024
1 parent 97fe219 commit 3f24eef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void beginDeepSleep(unsigned long startTime, tm *timeInfo)

// align wake time to nearest multiple of SLEEP_DURATION
int sleepMinutes = SLEEP_DURATION - offsetMinutes;
if (offsetSeconds < 120
if (desiredSleepSeconds - offsetSeconds < 120
|| offsetSeconds / (float)desiredSleepSeconds > 0.95f)
{ // if we have a sleep time less than 2 minutes OR less 5% SLEEP_DURATION,
// skip to next alignment
Expand All @@ -101,7 +101,8 @@ void beginDeepSleep(unsigned long startTime, tm *timeInfo)
}

// add extra delay to compensate for esp32's with fast RTCs.
sleepDuration += 10ULL;
sleepDuration += 1ULL;
sleepDuration *= 1.0015f;

#if DEBUG_LEVEL >= 1
printHeapUsage();
Expand Down

0 comments on commit 3f24eef

Please sign in to comment.