From 13280c985d0d580088b75a9a29551562e2805784 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 28 Jan 2022 08:39:41 +0100 Subject: [PATCH 1/6] Added WIFI check to avoid extensive battery usage The device is send to an additional deepsleep cycle if there could not establish a WIFI connection with IP in the first 15 seconds after startup. Normal connection time is 6-7 seconds. Address #14483 --- tasmota/xdrv_29_deepsleep.ino | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index f93506410..ac78357bd 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -154,9 +154,13 @@ void DeepSleepStart(void) } void DeepSleepEverySecond(void) -{ +{ + //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("Wifi Info: up %d, wifidown %d, wifistatus %d, flag %d"),TasmotaGlobal.uptime, TasmotaGlobal.global_state.wifi_down, Wifi.status , deepsleep_flag); + if (TasmotaGlobal.uptime > 15 && Wifi.status != WL_CONNECTED && !deepsleep_flag && DeepSleepEnabled()) { + AddLog(LOG_LEVEL_ERROR, PSTR("Error Wifi could not connect 15 seconds. Deepsleep") ); + deepsleep_flag = DEEPSLEEP_START_COUNTDOWN; // Start deepsleep in 4 seconds + } if (!deepsleep_flag) { return; } - if (DeepSleepEnabled()) { if (DEEPSLEEP_START_COUNTDOWN == deepsleep_flag) { // Allow 4 seconds to update web console before deepsleep SettingsSaveAll(); From 11284bbd4930b6f60dc850a6e8669d0ea64614d3 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 28 Jan 2022 12:06:59 +0100 Subject: [PATCH 2/6] Introduce DEEPSLEEP_NETWORK_TIMEOUT = 15 Network timeout can be configured in seconds or totally disabled by = 0 --- tasmota/xdrv_29_deepsleep.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index ac78357bd..17ef2d896 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -32,6 +32,7 @@ #define D_PRFX_DEEPSLEEP "DeepSleep" #define D_CMND_DEEPSLEEP_TIME "Time" +#define DEEPSLEEP_NETWORK_TIMEOUT 15 const uint32_t DEEPSLEEP_MAX = 10 * 366 * 24 * 60 * 60; // Allow max 10 years sleep const uint32_t DEEPSLEEP_MAX_CYCLE = 60 * 60; // Maximum time for a deepsleep as defined by chip hardware @@ -137,8 +138,6 @@ void DeepSleepPrepare(void) void DeepSleepStart(void) { - AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "Sleeping")); // Won't show in GUI - WifiShutdown(); RtcSettings.ultradeepsleep = RtcSettings.nextwakeup - LocalTime(); RtcSettingsSave(); @@ -154,13 +153,14 @@ void DeepSleepStart(void) } void DeepSleepEverySecond(void) -{ +{ //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("Wifi Info: up %d, wifidown %d, wifistatus %d, flag %d"),TasmotaGlobal.uptime, TasmotaGlobal.global_state.wifi_down, Wifi.status , deepsleep_flag); - if (TasmotaGlobal.uptime > 15 && Wifi.status != WL_CONNECTED && !deepsleep_flag && DeepSleepEnabled()) { + if (DEEPSLEEP_NETWORK_TIMEOUT && TasmotaGlobal.uptime > DEEPSLEEP_NETWORK_TIMEOUT && Wifi.status != WL_CONNECTED && !deepsleep_flag && DeepSleepEnabled()) { AddLog(LOG_LEVEL_ERROR, PSTR("Error Wifi could not connect 15 seconds. Deepsleep") ); deepsleep_flag = DEEPSLEEP_START_COUNTDOWN; // Start deepsleep in 4 seconds } if (!deepsleep_flag) { return; } + if (DeepSleepEnabled()) { if (DEEPSLEEP_START_COUNTDOWN == deepsleep_flag) { // Allow 4 seconds to update web console before deepsleep SettingsSaveAll(); From 6df1f0bb26c287b76f60d4decc4b8ca994caa8bc Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 28 Jan 2022 16:15:48 +0100 Subject: [PATCH 3/6] added compiler option: #ifdef DEEPSLEEP_NETWORK_TIMEOUT additional code optional compiled --- tasmota/xdrv_29_deepsleep.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index 17ef2d896..9db9c8ba6 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -1,7 +1,7 @@ /* xdrv_29_deepsleep.ino - DeepSleep support for Tasmota - Copyright (C) 2021 Stefan Bode + Copyright (C) 2022 Stefan Bode This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -154,11 +154,14 @@ void DeepSleepStart(void) void DeepSleepEverySecond(void) { +#ifdef DEEPSLEEP_NETWORK_TIMEOUT //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("Wifi Info: up %d, wifidown %d, wifistatus %d, flag %d"),TasmotaGlobal.uptime, TasmotaGlobal.global_state.wifi_down, Wifi.status , deepsleep_flag); if (DEEPSLEEP_NETWORK_TIMEOUT && TasmotaGlobal.uptime > DEEPSLEEP_NETWORK_TIMEOUT && Wifi.status != WL_CONNECTED && !deepsleep_flag && DeepSleepEnabled()) { AddLog(LOG_LEVEL_ERROR, PSTR("Error Wifi could not connect 15 seconds. Deepsleep") ); deepsleep_flag = DEEPSLEEP_START_COUNTDOWN; // Start deepsleep in 4 seconds } +#endif // DEEPSLEEP_NETWORK_TIMEOUT + if (!deepsleep_flag) { return; } if (DeepSleepEnabled()) { From 9388c706897383f214b1693756b6ac3763a75d19 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 28 Jan 2022 16:36:46 +0100 Subject: [PATCH 4/6] Update xdrv_29_deepsleep.ino --- tasmota/xdrv_29_deepsleep.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index 9db9c8ba6..ca19428b0 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -32,7 +32,9 @@ #define D_PRFX_DEEPSLEEP "DeepSleep" #define D_CMND_DEEPSLEEP_TIME "Time" -#define DEEPSLEEP_NETWORK_TIMEOUT 15 +#ifndef DEEPSLEEP_NETWORK_TIMEOUT + #define DEEPSLEEP_NETWORK_TIMEOUT 15 +#endif const uint32_t DEEPSLEEP_MAX = 10 * 366 * 24 * 60 * 60; // Allow max 10 years sleep const uint32_t DEEPSLEEP_MAX_CYCLE = 60 * 60; // Maximum time for a deepsleep as defined by chip hardware @@ -154,13 +156,11 @@ void DeepSleepStart(void) void DeepSleepEverySecond(void) { -#ifdef DEEPSLEEP_NETWORK_TIMEOUT //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("Wifi Info: up %d, wifidown %d, wifistatus %d, flag %d"),TasmotaGlobal.uptime, TasmotaGlobal.global_state.wifi_down, Wifi.status , deepsleep_flag); if (DEEPSLEEP_NETWORK_TIMEOUT && TasmotaGlobal.uptime > DEEPSLEEP_NETWORK_TIMEOUT && Wifi.status != WL_CONNECTED && !deepsleep_flag && DeepSleepEnabled()) { AddLog(LOG_LEVEL_ERROR, PSTR("Error Wifi could not connect 15 seconds. Deepsleep") ); deepsleep_flag = DEEPSLEEP_START_COUNTDOWN; // Start deepsleep in 4 seconds } -#endif // DEEPSLEEP_NETWORK_TIMEOUT if (!deepsleep_flag) { return; } From 3b8b473bd4b2d2df886cb508eb864702c871b84a Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 28 Jan 2022 16:50:11 +0100 Subject: [PATCH 5/6] fix logging --- tasmota/xdrv_29_deepsleep.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index ca19428b0..43ef64fc0 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -158,7 +158,7 @@ void DeepSleepEverySecond(void) { //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("Wifi Info: up %d, wifidown %d, wifistatus %d, flag %d"),TasmotaGlobal.uptime, TasmotaGlobal.global_state.wifi_down, Wifi.status , deepsleep_flag); if (DEEPSLEEP_NETWORK_TIMEOUT && TasmotaGlobal.uptime > DEEPSLEEP_NETWORK_TIMEOUT && Wifi.status != WL_CONNECTED && !deepsleep_flag && DeepSleepEnabled()) { - AddLog(LOG_LEVEL_ERROR, PSTR("Error Wifi could not connect 15 seconds. Deepsleep") ); + AddLog(LOG_LEVEL_ERROR, PSTR("Error Wifi could not connect %s seconds. Deepsleep"), DEEPSLEEP_NETWORK_TIMEOUT); deepsleep_flag = DEEPSLEEP_START_COUNTDOWN; // Start deepsleep in 4 seconds } From d49410c17e95854f398e488cf4528cd7d4d59b42 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 28 Jan 2022 16:52:00 +0100 Subject: [PATCH 6/6] Update xdrv_29_deepsleep.ino --- tasmota/xdrv_29_deepsleep.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index 43ef64fc0..0fec046cf 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -158,7 +158,7 @@ void DeepSleepEverySecond(void) { //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("Wifi Info: up %d, wifidown %d, wifistatus %d, flag %d"),TasmotaGlobal.uptime, TasmotaGlobal.global_state.wifi_down, Wifi.status , deepsleep_flag); if (DEEPSLEEP_NETWORK_TIMEOUT && TasmotaGlobal.uptime > DEEPSLEEP_NETWORK_TIMEOUT && Wifi.status != WL_CONNECTED && !deepsleep_flag && DeepSleepEnabled()) { - AddLog(LOG_LEVEL_ERROR, PSTR("Error Wifi could not connect %s seconds. Deepsleep"), DEEPSLEEP_NETWORK_TIMEOUT); + AddLog(LOG_LEVEL_ERROR, PSTR("Error Wifi could not connect %d seconds. Deepsleep"), DEEPSLEEP_NETWORK_TIMEOUT); deepsleep_flag = DEEPSLEEP_START_COUNTDOWN; // Start deepsleep in 4 seconds }