diff --git a/src/ConfigHTML.h b/src/ConfigHTML.h index cc0e238..8ce11ee 100644 --- a/src/ConfigHTML.h +++ b/src/ConfigHTML.h @@ -96,6 +96,16 @@ const char CONFIG_HTML[] PROGMEM = R"rawliteral( +
+
+ Keep WiFi radio awake +
Disables modem sleep. Improves RSSI and response time on weak signals, uses slightly more power.
+
+ +
@@ -126,9 +136,9 @@ const char CONFIG_HTML[] PROGMEM = R"rawliteral(

Spoolman

- Enable Spoolman + Enable Spoolman
@@ -151,9 +161,9 @@ const char CONFIG_HTML[] PROGMEM = R"rawliteral(

PrusaLink

Connect to a Prusa printer for automatic filament tracking. Get the API key from your printer's web interface.
- Enable PrusaLink + Enable PrusaLink
@@ -185,36 +195,36 @@ const char CONFIG_HTML[] PROGMEM = R"rawliteral(
Enable or disable optional hardware peripherals. Changes take effect after reboot.
- LCD Display + LCD Display
- Status LED + Status LED
- 3x4 Matrix Keypad + 3x4 Matrix Keypad
- TFT Display (240x240) + TFT Display (240x240)
- Bambu AMS Dashboard (TFT) + Bambu AMS Dashboard (TFT)
- NFC Reader - @@ -284,6 +294,7 @@ const char CONFIG_HTML[] PROGMEM = R"rawliteral( }); if (cfg.nfc_reader) document.getElementById('nfc_reader').value = cfg.nfc_reader; document.getElementById('bambu_dashboard').checked = !!cfg.bambu_dashboard; + document.getElementById('wifi_keep_awake').checked = !!cfg.wifi_keep_awake; maybeSetValue('moonraker_url', cfg.moonraker_url); // Password placeholders if (cfg.wifi_pass_set) document.getElementById('wifi_pass').placeholder = '(set) Leave blank to keep'; @@ -342,7 +353,8 @@ const char CONFIG_HTML[] PROGMEM = R"rawliteral( prusalink_on: document.getElementById('prusalink_on').checked ? 1 : 0, prusalink_url: document.getElementById('prusalink_url').value.trim(), prusalink_api_key: document.getElementById('prusalink_api_key').value, - bambu_dashboard: document.getElementById('bambu_dashboard').checked ? 1 : 0 + bambu_dashboard: document.getElementById('bambu_dashboard').checked ? 1 : 0, + wifi_keep_awake: document.getElementById('wifi_keep_awake').checked ? 1 : 0 }; fetch('/api/config', { diff --git a/src/ConfigurationManager.cpp b/src/ConfigurationManager.cpp index 0ddc943..efd5970 100644 --- a/src/ConfigurationManager.cpp +++ b/src/ConfigurationManager.cpp @@ -35,6 +35,7 @@ static const char* NVS_KEY_NFC_READER = "nfc_reader"; static const char* NVS_KEY_HOSTNAME = "hostname"; static const char* NVS_KEY_LOW_SPOOL = "low_spool_g"; static const char* NVS_KEY_BAMBU_DASH = "bambu_dash"; +static const char* NVS_KEY_WIFI_AWAKE = "wifi_awake"; // Sanitize hostname: enforce mDNS naming constraints (lowercase alphanum + hyphens, // no leading/trailing hyphens) and reject empty strings to avoid boot-time errors. @@ -253,6 +254,10 @@ bool ConfigurationManager::loadFromNVS() { _bambuDashboard = prefs.getBool(NVS_KEY_BAMBU_DASH, false); anyOverride = true; } + if (prefs.isKey(NVS_KEY_WIFI_AWAKE)) { + _wifiKeepAwake = prefs.getBool(NVS_KEY_WIFI_AWAKE, false); + anyOverride = true; + } prefs.end(); return anyOverride; @@ -359,6 +364,10 @@ bool ConfigurationManager::isBambuDashboardEnabled() const { return _bambuDashboard; } +bool ConfigurationManager::isWifiKeepAwakeEnabled() const { + return _wifiKeepAwake; +} + void ConfigurationManager::getCurrentConfig(ConfigUpdate& out) const { memset(&out, 0, sizeof(out)); strncpy(out.wifi_ssid, _ssid, sizeof(out.wifi_ssid) - 1); @@ -383,6 +392,7 @@ void ConfigurationManager::getCurrentConfig(ConfigUpdate& out) const { strncpy(out.hostname, _hostname, sizeof(out.hostname) - 1); out.low_spool_threshold_g = _lowSpoolThreshold; out.bambu_dashboard = _bambuDashboard ? 1 : 0; + out.wifi_keep_awake = _wifiKeepAwake ? 1 : 0; } #ifndef NATIVE_TEST @@ -427,6 +437,7 @@ bool ConfigurationManager::saveToNVS(const ConfigUpdate& update) { prefs.putString(NVS_KEY_HOSTNAME, sanitizedHostname); prefs.putUShort(NVS_KEY_LOW_SPOOL, update.low_spool_threshold_g); prefs.putBool(NVS_KEY_BAMBU_DASH, update.bambu_dashboard != 0); + prefs.putBool(NVS_KEY_WIFI_AWAKE, update.wifi_keep_awake != 0); // Invalidate Spoolman enrichment cache on config change to force re-fetch // (config change could invalidate cached spool lookups) diff --git a/src/ConfigurationManager.h b/src/ConfigurationManager.h index 9a43c16..641493b 100644 --- a/src/ConfigurationManager.h +++ b/src/ConfigurationManager.h @@ -40,6 +40,7 @@ struct ConfigUpdate { char hostname[33]; // max 32 chars + null uint16_t low_spool_threshold_g; // grams below which LED breathes (default 100) uint8_t bambu_dashboard; + uint8_t wifi_keep_awake; // disable WiFi modem sleep (better RSSI, more power) }; class ConfigurationManager { @@ -89,6 +90,10 @@ class ConfigurationManager { bool isBambuDashboardEnabled() const; + // When true, firmware calls WiFi.setSleep(false) after WiFi.begin so the + // radio stays fully powered. Trades idle current for better RSSI/latency. + bool isWifiKeepAwakeEnabled() const; + // Web config support void getCurrentConfig(ConfigUpdate& out) const; bool saveToNVS(const ConfigUpdate& update); @@ -139,6 +144,7 @@ class ConfigurationManager { char _tftDriver[8] = "st7789"; uint16_t _lowSpoolThreshold = 100; // grams bool _bambuDashboard = false; + bool _wifiKeepAwake = false; bool _initialized = false; }; diff --git a/src/WebServerManager.cpp b/src/WebServerManager.cpp index 026d3d8..4631a84 100644 --- a/src/WebServerManager.cpp +++ b/src/WebServerManager.cpp @@ -724,6 +724,7 @@ void WebServerManager::handleApiGetConfig() { doc["hostname"] = cfg.hostname; doc["low_spool_threshold_g"] = cfg.low_spool_threshold_g; doc["bambu_dashboard"] = cfg.bambu_dashboard; + doc["wifi_keep_awake"] = cfg.wifi_keep_awake; doc["tft_enabled"] = cfg.tft_enabled; doc["tft_driver"] = cfg.tft_driver; doc["ap_mode"] = _apMode; @@ -782,6 +783,7 @@ void WebServerManager::handleApiPostConfig() { sanitizeHostname(update.hostname, sizeof(update.hostname)); update.low_spool_threshold_g = doc["low_spool_threshold_g"] | (uint16_t)100; update.bambu_dashboard = doc["bambu_dashboard"] | 0; + update.wifi_keep_awake = doc["wifi_keep_awake"] | 0; if (update.wifi_ssid[0] == '\0') { sendError(400, "WiFi SSID is required"); diff --git a/src/main.cpp b/src/main.cpp index d08aba3..7755d5e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -104,6 +104,9 @@ void initWiFi() { WiFi.setHostname(config.getHostname()); WiFi.begin(config.getWiFiSSID(), config.getWiFiPassword()); + // Keep-awake disables WIFI_PS_MIN_MODEM (Arduino default). Users on weak + // networks report ~10 dB better RSSI with modem sleep off; costs idle current. + WiFi.setSleep(!config.isWifiKeepAwakeEnabled()); int attempts = 0; while (WiFi.status() != WL_CONNECTED && attempts < 30) {