From bcfc6fd2cdbb3a9f5cd1de26d25d4d04f321950e Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 27 Jan 2022 12:04:59 +0100 Subject: [PATCH 1/3] Move time calculation into local timezone Switch from UTC to local time to make better predictions on wakeuptime for long deepsleep cycles. #14483 --- tasmota/xdrv_29_deepsleep.ino | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index ac0478ee5..f93506410 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -95,7 +95,7 @@ void DeepSleepPrepare(void) if ((RtcSettings.nextwakeup == 0) || (RtcSettings.deepsleep_slip < 9000) || (RtcSettings.deepsleep_slip > 11000) || - (RtcSettings.nextwakeup > (UtcTime() + Settings->deepsleep))) { + (RtcSettings.nextwakeup > (LocalTime() + Settings->deepsleep))) { AddLog(LOG_LEVEL_ERROR, PSTR("DSL: Reset wrong settings wakeup: %ld, slip %ld"), RtcSettings.nextwakeup, RtcSettings.deepsleep_slip ); RtcSettings.nextwakeup = 0; RtcSettings.deepsleep_slip = 10000; @@ -103,13 +103,13 @@ void DeepSleepPrepare(void) // Timeslip in 0.1 seconds between the real wakeup and the calculated wakeup // Because deepsleep is in second and timeslip in 0.1 sec the compare always check if the slip is in the 10% range - int16_t timeslip = (int16_t)(RtcSettings.nextwakeup + millis() / 1000 - UtcTime()) * 10; + int16_t timeslip = (int16_t)(RtcSettings.nextwakeup + millis() / 1000 - LocalTime()) * 10; // Allow 10% of deepsleep error to count as valid deepsleep; expecting 3-4% // if more then 10% timeslip = 0 == non valid wakeup; maybe manual timeslip = (timeslip < -(int32_t)Settings->deepsleep) ? 0 : (timeslip > (int32_t)Settings->deepsleep) ? 0 : 1; if (timeslip) { - RtcSettings.deepsleep_slip = (Settings->deepsleep + RtcSettings.nextwakeup - UtcTime()) * RtcSettings.deepsleep_slip / tmax((Settings->deepsleep - (millis() / 1000)),5); + RtcSettings.deepsleep_slip = (Settings->deepsleep + RtcSettings.nextwakeup - LocalTime()) * RtcSettings.deepsleep_slip / tmax((Settings->deepsleep - (millis() / 1000)),5); // Avoid crazy numbers. Again maximum 10% deviation. RtcSettings.deepsleep_slip = tmin(tmax(RtcSettings.deepsleep_slip, 9000), 11000); RtcSettings.nextwakeup += Settings->deepsleep; @@ -117,15 +117,15 @@ void DeepSleepPrepare(void) // It may happen that wakeup in just <5 seconds in future // In this case also add deepsleep to nextwakeup - if (RtcSettings.nextwakeup <= (UtcTime() - DEEPSLEEP_MIN_TIME)) { + if (RtcSettings.nextwakeup <= (LocalTime() - DEEPSLEEP_MIN_TIME)) { // ensure nextwakeup is at least in the future - RtcSettings.nextwakeup += (((UtcTime() + DEEPSLEEP_MIN_TIME - RtcSettings.nextwakeup) / Settings->deepsleep) + 1) * Settings->deepsleep; + RtcSettings.nextwakeup += (((LocalTime() + DEEPSLEEP_MIN_TIME - RtcSettings.nextwakeup) / Settings->deepsleep) + 1) * Settings->deepsleep; } - String dt = GetDT(RtcSettings.nextwakeup + LocalTime() - UtcTime()); // 2017-03-07T11:08:02 + String dt = GetDT(RtcSettings.nextwakeup); // 2017-03-07T11:08:02 // Limit sleeptime to DEEPSLEEP_MAX_CYCLE - // uint32_t deepsleep_sleeptime = DEEPSLEEP_MAX_CYCLE < (RtcSettings.nextwakeup - UtcTime()) ? (uint32_t)DEEPSLEEP_MAX_CYCLE : RtcSettings.nextwakeup - UtcTime(); - deepsleep_sleeptime = tmin((uint32_t)DEEPSLEEP_MAX_CYCLE ,RtcSettings.nextwakeup - UtcTime()); + // uint32_t deepsleep_sleeptime = DEEPSLEEP_MAX_CYCLE < (RtcSettings.nextwakeup - LocalTime()) ? (uint32_t)DEEPSLEEP_MAX_CYCLE : RtcSettings.nextwakeup - LocalTime(); + deepsleep_sleeptime = tmin((uint32_t)DEEPSLEEP_MAX_CYCLE ,RtcSettings.nextwakeup - LocalTime()); // stat/tasmota/DEEPSLEEP = {"DeepSleep":{"Time":"2019-11-12T21:33:45","Epoch":1573590825}} Response_P(PSTR("{\"" D_PRFX_DEEPSLEEP "\":{\"" D_JSON_TIME "\":\"%s\",\"Epoch\":%d}}"), (char*)dt.c_str(), RtcSettings.nextwakeup); @@ -140,7 +140,7 @@ void DeepSleepStart(void) AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "Sleeping")); // Won't show in GUI WifiShutdown(); - RtcSettings.ultradeepsleep = RtcSettings.nextwakeup - UtcTime(); + RtcSettings.ultradeepsleep = RtcSettings.nextwakeup - LocalTime(); RtcSettingsSave(); RtcRebootReset(); #ifdef ESP8266 From 32ec553cc7844d374689aa00dc8ce57c0b24643e Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu, 27 Jan 2022 16:53:39 +0100 Subject: [PATCH 2/3] Tasmota core 2.0.2.x based on release IDF44 (#14611) * Tasmota core 2.0.2.x based on release IDF44 Co-authored-by: s-hadinger <49731213+s-hadinger@users.noreply.github.com> --- lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp | 3 ++- platformio_tasmota32.ini | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp b/lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp index f9072ff7d..fbead560a 100644 --- a/lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp +++ b/lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp @@ -113,7 +113,8 @@ bool analogAttach(uint32_t pin) { return false; } -void analogWrite(uint8_t pin, int val) +// void analogWrite(uint8_t pin, int val); +extern "C" void __wrap__Z11analogWritehi(uint8_t pin, int val) { uint32_t channel = _analog_pin2chan(pin); if ( val >> (_pwm_bit_num-1) ) ++val; diff --git a/platformio_tasmota32.ini b/platformio_tasmota32.ini index 84ef4a3c4..a27266b38 100644 --- a/platformio_tasmota32.ini +++ b/platformio_tasmota32.ini @@ -32,19 +32,20 @@ build_flags = ${esp_defaults.build_flags} -include "esp32x_fixes.h" ; wrappers for the crash-recorder -Wl,--wrap=panicHandler -Wl,--wrap=xt_unhandled_exception + -Wl,--wrap=_Z11analogWritehi ; `analogWrite(unsigned char, int)` use the Tasmota version of analogWrite for deeper integration and phase control extra_scripts = pre:pio-tools/add_c_flags.py post:pio-tools/post_esp32.py ${esp_defaults.extra_scripts} [core32] -platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.1/platform-tasmota-espressif32-2.0.2.1.zip +platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.2/platform-tasmota-espressif32-2.0.2.zip platform_packages = build_unflags = ${esp32_defaults.build_unflags} build_flags = ${esp32_defaults.build_flags} [core32solo1] -platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.1solo1/platform-tasmota-espressif32-2.0.2.1solo1.zip +platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.2solo1/platform-tasmota-espressif32-2.0.2solo1.zip platform_packages = build_unflags = ${esp32_defaults.build_unflags} build_flags = ${esp32_defaults.build_flags} From f4aaaa24626226903a6ef8a4daa08530409b4f26 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Thu, 27 Jan 2022 18:48:57 +0100 Subject: [PATCH 3/3] Berry add limit to tcp reads --- tasmota/xdrv_52_3_berry_webclient.ino | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tasmota/xdrv_52_3_berry_webclient.ino b/tasmota/xdrv_52_3_berry_webclient.ino index 625c54622..71b0aaab4 100644 --- a/tasmota/xdrv_52_3_berry_webclient.ino +++ b/tasmota/xdrv_52_3_berry_webclient.ino @@ -325,10 +325,17 @@ extern "C" { int32_t wc_tcp_read(struct bvm *vm); int32_t wc_tcp_read(struct bvm *vm) { WiFiClient * tcp = wc_getwificlient(vm); + int32_t max_read = -1; // by default read as much as we can + if (be_top(vm) >= 2 && be_isint(vm, 2)) { + max_read = be_toint(vm, 2); + } int32_t btr = tcp->available(); if (btr <= 0) { be_pushstring(vm, ""); } else { + if ((max_read >= 0) && (btr > max_read)) { + btr = max_read; + } char * buf = (char*) be_pushbuffer(vm, btr); int32_t btr2 = tcp->read((uint8_t*) buf, btr); be_pushnstring(vm, buf, btr2); @@ -340,10 +347,17 @@ extern "C" { int32_t wc_tcp_readbytes(struct bvm *vm); int32_t wc_tcp_readbytes(struct bvm *vm) { WiFiClient * tcp = wc_getwificlient(vm); + int32_t max_read = -1; // by default read as much as we can + if (be_top(vm) >= 2 && be_isint(vm, 2)) { + max_read = be_toint(vm, 2); + } int32_t btr = tcp->available(); if (btr <= 0) { be_pushbytes(vm, nullptr, 0); } else { + if ((max_read >= 0) && (btr > max_read)) { + btr = max_read; + } uint8_t * buf = (uint8_t*) be_pushbuffer(vm, btr); int32_t btr2 = tcp->read(buf, btr); be_pushbytes(vm, buf, btr2);