feat: night mode — extended sleep interval during 22:00-06:00 - #25
feat: night mode — extended sleep interval during 22:00-06:00#25stritti wants to merge 5 commits into
Conversation
Between NIGHT_START_HOUR (22) and NIGHT_END_HOUR (6) local time, the device wakes only every 4 hours instead of every 3 minutes. Reduces night-time wake-ups from ~160 to ~2, cutting daily power consumption from ~40 mAh to ~27 mAh. Night mode only activates after the first NTP sync (valid epoch time). Time is reconstructed from stored epoch + uptime, so it works across deep-sleep cycles without additional network requests.
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eeb8a6fb5e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… deep-sleep cycles Codex P1: When night mode selects a 4-hour sleep interval, the next boot must increment total_uptime by the actual duration (not just TIME_TO_SLEEP_SECONDS). Without this fix, the time reconstruction drifts by ~3h57m every night cycle, causing the device to stay in night mode well into the day. - prepareForSleep(): save 'last_sleep_sec' to NVS before deep sleep - setup(): read 'last_sleep_sec' when incrementing total_uptime, then remove it so normal cycles without the key default to TIME_TO_SLEEP_SECONDS
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a7d7dbf63f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
When the device enters night mode at an hour not aligned to the intended 22:00/02:00 cadence (e.g. 00:30 after a restart), the unconditional 4-hour sleep could carry it past 06:00 into morning. The fix calculates the remaining seconds until NIGHT_END_HOUR and clamps the sleep interval, so the device always wakes at or before 06:00 to resume normal operation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a4f196b33
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
During night mode (4h sleep), no_wifi_count was only incremented by 1, undercounting skipped wake cycles by a factor of ~80. This caused the post-night wake (06:00) to skip WiFi/MQTT/display because the counter hadn't reached the SKIP_WIFI_WAKE_CYCLES threshold. Now the increment is scaled by lastSleepDuration / TIME_TO_SLEEP_SECONDS, so a 4-hour night sleep correctly advances the counter by ~80 cycles. Addresses P2 feedback from Codex review on PR #25.
Antwort auf Codex ReviewsP1: Account for night sleep in persisted uptime ✅Bereits im Branch implementiert: P2: Clamp night sleeps to the 06:00 boundary ✅Bereits im Branch implementiert: P2: Keep network cadence during night sleeps 🔧 Gefixt in 0bdf956
Fix: Der Increment wird jetzt über |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0bdf95635c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| preferences_->putUInt("no_wifi_count", 0); | ||
| } else { | ||
| preferences_->putUInt("no_wifi_count", cyclesWithoutWiFi + 1); | ||
| preferences_->putUInt("no_wifi_count", cyclesWithoutWiFi + skipIncrement); |
There was a problem hiding this comment.
Apply elapsed skip count before deciding WiFi
When the previous sleep was a night interval and no_wifi_count was still below the threshold, doNetwork has already been computed before this scaled increment is written, so that wake still skips WiFi/MQTT even though 4 hours elapsed; for example, entering night right after a network cycle makes the 02:00 wake skip the retained MQTT sample and display update. Fresh evidence in this revision is that the scaled increment is only persisted here after the network decision was made, so the intended long-sleep catch-up applies one wake too late.
Useful? React with 👍 / 👎.
cppcheck's --unusedFunction cannot resolve calls across translation units for PlatformIO builds, producing false positives for every function called from PoolMonitorContext.cpp to DisplayManager, NetworkManager, and TimeClientHelper, plus the Arduino framework entry point PoolMonitorContext::setup(). Changes: - Added --inline-suppr to platformio.ini check_flags - Added // cppcheck-suppress unusedFunction with ; comment syntax to 11 cross-TU functions that are genuinely called from other .cpp files - Removed DisplayManager::getWidth() and getHeight() which were genuinely unused (callers use getDisplay().width()/.height() directly)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec569c062c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| unsigned long totalUptime = preferences_->getULong("total_uptime", 0); | ||
| unsigned long lastEpoch = preferences_->getULong("last_epoch", 0); | ||
|
|
||
| if (lastEpoch > 0) { |
There was a problem hiding this comment.
Reject bogus epochs before enabling night mode
When an NTP update fails after WiFi connects, getCurrentTime() returns "--:--" but setup still persists timeClient.getEpochTime(); on a fresh boot that can be a small nonzero uptime value. This new lastEpoch > 0 gate then treats the bogus 1970-era timestamp as valid local time (typically inside the 00:00-06:00 night window), so an NTP outage during the day can put the device into repeated 4-hour sleeps and delay MQTT/display/OTA work. Require a successful sync or reject implausible epochs before using last_epoch for night-mode scheduling.
Useful? React with 👍 / 👎.
| - currentMinute * 60 - currentSecond; | ||
| } | ||
|
|
||
| if (secondsUntilEnd > 60 && sleepSeconds > static_cast<uint32_t>(secondsUntilEnd)) { |
There was a problem hiding this comment.
Clamp the final minute before morning
When the device evaluates night mode in the last minute before NIGHT_END_HOUR—for example after a restart or network cycle at 05:59:30—secondsUntilEnd is <= 60, so this guard skips the clamp and leaves sleepSeconds at the 4-hour night interval, waking around 09:59 instead of just after 06:00. Fresh evidence beyond the earlier clamp discussion is the secondsUntilEnd > 60 condition, which still allows this boundary oversleep; fall back to the normal interval or clamp the remaining time here.
Useful? React with 👍 / 👎.
Zusammenfassung
Nacht-Modus für den Pool Monitor: Zwischen 22:00 und 06:00 Uhr verlängert sich das Wake-Intervall von 3 Minuten auf 4 Stunden.
Energiebilanz
Funktionsweise
Konfiguration (Config.hpp)
NIGHT_START_HOURNIGHT_END_HOURNIGHT_SLEEP_INTERVAL_SECONDSBuild & Check
pio run --environment LILYGO_T5_V231: ✅ SUCCESSpio check --environment LILYGO_T5_V231 --skip-packages: ✅ PASSED