From a02eb5c4ab11aba45ea054614f74ceaf9a856423 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Mon, 25 Feb 2019 07:38:43 +0300 Subject: [PATCH 1/3] Revert loopDelay dependency on wifi sleep mode --- code/espurna/system.ino | 15 +++------------ code/espurna/utils.ino | 6 +++--- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/code/espurna/system.ino b/code/espurna/system.ino index 33bbf267..0f14dc8c 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -10,9 +10,7 @@ Copyright (C) 2018 by Xose PĂ©rez // ----------------------------------------------------------------------------- -#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP unsigned long _loop_delay = 0; -#endif bool _system_send_heartbeat = false; unsigned char _heartbeat_mode = HEARTBEAT_MODE; @@ -75,11 +73,9 @@ bool systemGetHeartbeat() { return _system_send_heartbeat; } -#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP unsigned long systemLoopDelay() { return _loop_delay; } -#endif unsigned long systemLoadAverage() { return _load_average; @@ -160,10 +156,7 @@ void systemLoop() { // ------------------------------------------------------------------------- // Power saving delay // ------------------------------------------------------------------------- - - #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP - delay(_loop_delay); - #endif + if (_loop_delay) delay(_loop_delay); } @@ -202,10 +195,8 @@ void systemSetup() { _systemSetupSpecificHardware(); // Cache loop delay value to speed things (recommended max 250ms) - #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP - _loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str()); - _loop_delay = constrain(_loop_delay, 0, 300); - #endif + _loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str()); + _loop_delay = constrain(_loop_delay, 0, 300); // Register Loop espurnaRegisterLoop(systemLoop); diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 888f3963..b58f076f 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -469,9 +469,9 @@ void info() { #if ADC_MODE_VALUE == ADC_VCC DEBUG_MSG_P(PSTR("[MAIN] Power: %u mV\n"), ESP.getVcc()); #endif - #if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP + if (systemLoopDelay()) { DEBUG_MSG_P(PSTR("[MAIN] Power saving delay value: %lu ms\n"), systemLoopDelay()); - #endif + } // ------------------------------------------------------------------------- @@ -606,4 +606,4 @@ bool isNumber(const char * s) { } } return digit; -} \ No newline at end of file +} From 3c1cfbfdbee9365d6fef379477b52ece939af055 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Mon, 25 Feb 2019 08:04:59 +0300 Subject: [PATCH 2/3] Set wifi sleep mode from settings --- code/espurna/utils.ino | 14 ++++++++++++++ code/espurna/wifi.ino | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index b58f076f..df7c25c6 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -368,6 +368,15 @@ void infoMemory(const char * name, unsigned int total_memory, unsigned int free_ } +const char* _info_wifi_sleep_mode(WiFiSleepType_t type) { + switch (type) { + case WIFI_NONE_SLEEP: return "NONE"; + case WIFI_LIGHT_SLEEP: return "LIGHT"; + case WIFI_MODEM_SLEEP: return "MODEM"; + } +} + + void info() { DEBUG_MSG_P(PSTR("\n\n---8<-------\n\n")); @@ -473,6 +482,11 @@ void info() { DEBUG_MSG_P(PSTR("[MAIN] Power saving delay value: %lu ms\n"), systemLoopDelay()); } + const WiFiSleepType_t sleep_mode = WiFi.getSleepMode(); + if (sleep_mode != WIFI_NONE_SLEEP) { + DEBUG_MSG_P(PSTR("[MAIN] WiFi Sleep Mode: %s\n"), _info_wifi_sleep_mode(sleep_mode)); + } + // ------------------------------------------------------------------------- #if SYSTEM_CHECK_ENABLED diff --git a/code/espurna/wifi.ino b/code/espurna/wifi.ino index a5a0e8a7..3d06fe6c 100644 --- a/code/espurna/wifi.ino +++ b/code/espurna/wifi.ino @@ -75,6 +75,10 @@ void _wifiConfigure() { jw.enableScan(getSetting("wifiScan", WIFI_SCAN_NETWORKS).toInt() == 1); + unsigned char sleep_mode = getSetting("wifiSleep", WIFI_SLEEP_MODE).toInt(); + sleep_mode = constrain(sleep_mode, 0, 2); + + WiFi.setSleepMode(static_cast(sleep_mode)); } void _wifiScan(uint32_t client_id = 0) { @@ -603,8 +607,6 @@ void wifiRegister(wifi_callback_f callback) { void wifiSetup() { - WiFi.setSleepMode(WIFI_SLEEP_MODE); - _wifiInject(); _wifiConfigure(); From 5db1523e20e08b43069bcf9f489fbe18840a2658 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Mon, 25 Feb 2019 16:18:55 +0300 Subject: [PATCH 3/3] Fix warning --- code/espurna/utils.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index df7c25c6..09e09e1b 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -373,6 +373,7 @@ const char* _info_wifi_sleep_mode(WiFiSleepType_t type) { case WIFI_NONE_SLEEP: return "NONE"; case WIFI_LIGHT_SLEEP: return "LIGHT"; case WIFI_MODEM_SLEEP: return "MODEM"; + default: return "UNKNOWN"; } }