diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 9422ba1d..a09c5d88 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -9,6 +9,7 @@ #define ADMIN_PASS "fibonacci" // Default password (WEB, OTA, WIFI) #define DEVICE_NAME MANUFACTURER "_" DEVICE // Concatenate both to get a unique device name +#define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250] //------------------------------------------------------------------------------ // TELNET @@ -266,6 +267,7 @@ PROGMEM const char* const custom_reset_string[] = { #define WIFI_RECONNECT_INTERVAL 180000 // If could not connect to WIFI, retry after this time in ms #define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations #define WIFI_AP_MODE AP_MODE_ALONE +#define WIFI_SLEEP_ENABLED 1 // Enable WiFi light sleep // Optional hardcoded configuration (up to 2 different networks) //#define WIFI1_SSID "..." diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 1d55c611..98de32e7 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -241,6 +241,7 @@ void setup() { if (!systemCheck()) return; #endif + // Init webserver required before any module that uses API #if WEB_SUPPORT webSetup(); #endif @@ -256,7 +257,6 @@ void setup() { #ifdef ITEAD_SONOFF_RFBRIDGE rfbSetup(); #endif - #if POWER_PROVIDER != POWER_PROVIDER_NONE powerSetup(); #endif @@ -311,26 +311,23 @@ void loop() { wifiLoop(); otaLoop(); - // Do not run the next services if system is flagged stable #if SYSTEM_CHECK_ENABLED systemCheckLoop(); + // Do not run the next services if system is flagged stable if (!systemCheck()) return; #endif #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE lightLoop(); #endif - - - buttonLoop(); relayLoop(); + buttonLoop(); ledLoop(); mqttLoop(); #ifdef ITEAD_SONOFF_RFBRIDGE rfbLoop(); #endif - #if POWER_PROVIDER != POWER_PROVIDER_NONE powerLoop(); #endif @@ -362,4 +359,9 @@ void loop() { irLoop(); #endif + // Power saving delay + #if LOOP_DELAY_TIME + delay(LOOP_DELAY_TIME); + #endif + } diff --git a/code/espurna/wifi.ino b/code/espurna/wifi.ino index 370d0664..e9a38ed4 100644 --- a/code/espurna/wifi.ino +++ b/code/espurna/wifi.ino @@ -174,6 +174,10 @@ void wifiInject() { void wifiSetup() { + #if WIFI_SLEEP_ENABLED + wifi_set_sleep_type(LIGHT_SLEEP_T); + #endif + wifiInject(); wifiConfigure();