Skip to content

Commit

Permalink
Make startDeviceSleep() use calculated sleep time
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelstoer committed Nov 1, 2019
1 parent 4ee8a2a commit 2538cb4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions EspaperClient/EspaperClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ void formatFileSystem() {


void startDeviceSleep(uint32_t sleepSeconds, uint32_t sleepUntilEpoch) {
Serial.printf_P(PSTR("Free mem: %d\n"), ESP.getFreeHeap());
Serial.printf_P(PSTR("Free mem: %d.\n"), ESP.getFreeHeap());
epd.Sleep();
int currentMillis = millis();
time_t now = startTime + ((currentMillis - startMillis) / 1000);
Serial.printf_P(PSTR("Start millis: %d, start time: %d, current millis: %d -> now: %d\n"), startMillis, startTime, currentMillis, now);
uint64_t effectiveSleepSeconds;
if (sleepUntilEpoch == 0) {
// use the local client configuration if server sends "nothing" (0 -> undefined)
Serial.printf_P(PSTR("'sleepUntilEpoch' is 0. Using configured default update interval of %dmin.\n"), UPDATE_INTERVAL_MINS);
effectiveSleepSeconds = UPDATE_INTERVAL_MINS * 60;
} else {
effectiveSleepSeconds = sleepUntilEpoch - now;
Expand All @@ -162,7 +163,7 @@ void startDeviceSleep(uint32_t sleepSeconds, uint32_t sleepUntilEpoch) {
effectiveSleepSeconds = sleepSeconds;
}
}
Board.deepSleep(sleepSeconds);
Board.deepSleep(effectiveSleepSeconds);
}

EspaperParser::ResourceResponse fetchAndDrawScreen(EspaperParser *parser, DeviceData *deviceData) {
Expand Down

0 comments on commit 2538cb4

Please sign in to comment.