Skip to content

feat(wifi): keep-awake toggle to disable modem sleep#163

Merged
sjordan0228 merged 2 commits into
devfrom
feature/wifi-keep-awake-toggle
Apr 18, 2026
Merged

feat(wifi): keep-awake toggle to disable modem sleep#163
sjordan0228 merged 2 commits into
devfrom
feature/wifi-keep-awake-toggle

Conversation

@sjordan0228
Copy link
Copy Markdown
Contributor

@sjordan0228 sjordan0228 commented Apr 18, 2026

Summary

  • New NVS-backed config toggle Keep WiFi radio awake (default off). When enabled, firmware calls WiFi.setSleep(false) after WiFi.begin() to disable WIFI_PS_MIN_MODEM.
  • Arduino-ESP32 defaults modem sleep on, which can make reported RSSI look ~10 dB worse than ESPHome on identical hardware. Discord report today: -84 dBm on our firmware vs much stronger signal with ESPHome on the same D1 mini / ESP32 DevKitC boards.
  • Trades a small amount of idle current for better RSSI and lower ping — appropriate for USB-powered scanners, opt-in so existing installs aren't surprised.

Changes

file change
ConfigurationManager.h/.cpp wifi_keep_awake struct field, NVS_KEY_WIFI_AWAKE = "wifi_awake", isWifiKeepAwakeEnabled() getter, load/save wiring
ConfigHTML.h toggle row in WiFi section with help text, load + submit JS
WebServerManager.cpp /api/config GET exposes it, POST parses it
main.cpp WiFi.setSleep(!config.isWifiKeepAwakeEnabled()) after WiFi.begin()

Plumbing mirrors the existing bambu_dashboard pattern.

Test plan

  • Builds clean on esp32dev, esp32s3devkitc, esp32s3zero (espressif32@6.10.0)
  • Flash to test board, confirm toggle persists across reboot
  • A/B RSSI with toggle off vs on against the same AP, same location
  • Ask Discord reporter to test and report delta

Summary by CodeRabbit

  • New Features
    • Added WiFi radio power management option in Network settings. Users can now toggle the "Keep WiFi radio awake" setting to control whether the WiFi radio enters sleep mode, helping optimize power consumption while maintaining connectivity preferences.

Arduino-ESP32 defaults WiFi to WIFI_PS_MIN_MODEM, which can drop reported
RSSI ~10 dB vs ESPHome on identical hardware. New NVS-backed config
toggle (wifi_keep_awake, default off) calls WiFi.setSleep(false) after
WiFi.begin so users on weak networks can opt into full-power operation.

Plumbing mirrors the bambu_dashboard pattern: ConfigUpdate struct field,
NVS key "wifi_awake", getter, /api/config GET/POST, web form toggle in
the WiFi section.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@sjordan0228 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 3 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 28 minutes and 3 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fb3e4eda-07d8-4012-9335-535558faa619

📥 Commits

Reviewing files that changed from the base of the PR and between cb06259 and 7ab5d8c.

📒 Files selected for processing (5)
  • src/ConfigHTML.h
  • src/ConfigurationManager.cpp
  • src/ConfigurationManager.h
  • src/WebServerManager.cpp
  • src/main.cpp
📝 Walkthrough

Walkthrough

A new WiFi modem sleep behavior configuration feature is added across the firmware stack. The feature includes a UI checkbox toggle, persistent NVS storage via the ConfigurationManager, REST API exposure, and runtime control via WiFi.setSleep() in the initialization sequence.

Changes

Cohort / File(s) Summary
Configuration Data Structures
src/ConfigurationManager.h
Added wifi_keep_awake field to ConfigUpdate struct and _wifiKeepAwake internal state member. Introduced public accessor method isWifiKeepAwakeEnabled().
Configuration Persistence
src/ConfigurationManager.cpp
Implemented NVS read/write logic for NVS_KEY_WIFI_AWAKE. loadFromNVS() reads the flag into _wifiKeepAwake; getCurrentConfig() populates the output config; saveToNVS() persists updates back to NVS.
Web Interface
src/ConfigHTML.h, src/WebServerManager.cpp
Added "Keep WiFi radio awake" checkbox toggle to the Network configuration UI section. Extended /api/config GET and POST endpoints to include wifi_keep_awake field in JSON payloads.
Runtime WiFi Control
src/main.cpp
Integrated WiFi.setSleep(!config.isWifiKeepAwakeEnabled()) call in initWiFi() to conditionally apply the modem sleep setting after connection initiation.

Sequence Diagram

sequenceDiagram
    participant User as User/Browser
    participant UI as Web UI
    participant API as WebServerManager
    participant Config as ConfigurationManager
    participant NVS as NVS Storage
    participant WiFi as WiFi Driver
    
    rect rgba(100, 150, 255, 0.5)
    Note over User,WiFi: Configuration Update Flow
    User->>UI: Toggle "Keep WiFi awake"
    UI->>API: POST /api/config with wifi_keep_awake: 1
    API->>Config: parseUpdate() sets update.wifi_keep_awake
    Config->>Config: saveToNVS(update)
    Config->>NVS: Write NVS_KEY_WIFI_AWAKE = 1
    NVS-->>Config: Stored
    API-->>UI: Config updated
    UI-->>User: Confirm change
    end
    
    rect rgba(150, 200, 100, 0.5)
    Note over User,WiFi: Runtime Application Flow
    User->>WiFi: Device restarts/reinitializes
    WiFi->>Config: initWiFi() calls isWifiKeepAwakeEnabled()
    Config->>Config: Returns _wifiKeepAwake value
    Config-->>WiFi: Returns setting state
    WiFi->>WiFi: setSleep(!enabled) applies modem sleep policy
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a WiFi keep-awake toggle to disable modem sleep, which is the core feature across all modified files.
Description check ✅ Passed The description covers the required template sections: Summary explains the feature and motivation, Changes lists affected files, and a Test plan is provided. However, the Checklist section is missing the required validation items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/wifi-keep-awake-toggle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the size/S Small change (10-50 lines) label Apr 18, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/ConfigHTML.h`:
- Around line 99-108: The checkbox input with id "wifi_keep_awake" has no
accessible label; either move the visible text (the element with class
"toggle-label") inside the same <label> as the input or give that text an id
(e.g., add id "wifi_keep_awake_label" to the span with class "toggle-label") and
set aria-labelledby="wifi_keep_awake_label" on the input element; ensure the
input retains id "wifi_keep_awake" so references in JS remain valid and update
any related CSS/JS if you change element nesting.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b3a372c7-10be-412f-a889-acaf52395900

📥 Commits

Reviewing files that changed from the base of the PR and between cb06259 and b389ec1.

📒 Files selected for processing (5)
  • src/ConfigHTML.h
  • src/ConfigurationManager.cpp
  • src/ConfigurationManager.h
  • src/WebServerManager.cpp
  • src/main.cpp

Comment thread src/ConfigHTML.h
Addresses CodeRabbit finding on #163. Toggle rows rendered the visible
caption as a <span class="toggle-label"> sibling to the <input>, so
screen readers announced the checkbox with no accessible name. Adds an
id to each caption span and points the input/select at it via
aria-labelledby.

Covers the new wifi_keep_awake toggle plus the pre-existing
spoolman_on, prusalink_on, lcd_enabled, led_enabled, keypad_enabled,
tft_enabled, bambu_dashboard toggles and the tft_driver, nfc_reader
selects.

Fixes WCAG 1.3.1 (Info and Relationships) and 4.1.2 (Name, Role,
Value). No visual or behavioral change.
@github-actions github-actions Bot added size/M Medium change (50-200 lines) and removed size/S Small change (10-50 lines) labels Apr 18, 2026
@sjordan0228
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sjordan0228
Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

✅ Actions performed

Full review triggered.

@sjordan0228 sjordan0228 merged commit afcc285 into dev Apr 18, 2026
2 checks passed
@sjordan0228 sjordan0228 deleted the feature/wifi-keep-awake-toggle branch April 18, 2026 23:14
roomonthethird pushed a commit to roomonthethird/spoolsense_scanner that referenced this pull request Apr 22, 2026
Bumps FIRMWARE_VERSION from 1.7.2 → 1.7.3.

CHANGELOG.md:
- Adds [1.7.3] entry documenting SpoolSense#163 WiFi keep-awake, SpoolSense#165 case files,
  SpoolSense#164/SpoolSense#13 TigerTag partial writes, SpoolSense#159/SpoolSense#162 openprinttag rename.
- Backfills missing [1.7.2] entry (Bambu MIFARE Classic reading, SpoolSense#24).
- Backfills missing [1.7.1] entry (writer enrichment + bug fixes,
  SpoolSense#130/SpoolSense#101/SpoolSense#128/SpoolSense#151 and platform pin).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium change (50-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant