From 3c1cfbfdbee9365d6fef379477b52ece939af055 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Mon, 25 Feb 2019 08:04:59 +0300 Subject: [PATCH] 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();