From 76d17bd1982bbeb260cf2761e4236140752c90f1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 13 Nov 2019 09:25:09 +0100 Subject: [PATCH] Fix possible teleperiod misses --- tasmota/tasmota.h | 2 -- tasmota/tasmota.ino | 27 ++++++++++++++------------- tasmota/xdrv_29_deepsleep.ino | 5 +++++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 33bed67aa..607afefd1 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -116,8 +116,6 @@ const uint16_t SYSLOG_TIMER = 600; // Seconds to restore syslog_level const uint16_t SERIALLOG_TIMER = 600; // Seconds to disable SerialLog const uint8_t OTA_ATTEMPTS = 5; // Number of times to try fetching the new firmware -const uint16_t TELE_PERIOD_START = 10000; // Initial tele_period until wifi connected - const uint16_t INPUT_BUFFER_SIZE = 520; // Max number of characters in (serial and http) command buffer const uint16_t FLOATSZ = 16; // Max number of characters in float result from dtostrfd (max 32) const uint16_t CMDSZ = 24; // Max number of characters in command diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 0135f3dde..568fff407 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -113,7 +113,7 @@ float global_temperature = 9999; // Provide a global temperature to b float global_humidity = 0; // Provide a global humidity to be used by some sensors float global_pressure = 0; // Provide a global pressure to be used by some sensors char *ota_url; // OTA url string pointer -uint16_t tele_period = TELE_PERIOD_START; // Tele period timer +uint16_t tele_period = 9999; // Tele period timer uint16_t mqtt_cmnd_publish = 0; // ignore flag for publish command uint16_t blink_counter = 0; // Number of blink cycles uint16_t seriallog_timer = 0; // Timer to disable Seriallog @@ -846,26 +846,27 @@ void PerformEverySecond(void) ResetGlobalValues(); if (Settings.tele_period) { - if (tele_period >= TELE_PERIOD_START) { + if (tele_period >= 9999) { if (!global_state.wifi_down) { tele_period = 0; // Allow teleperiod once wifi is connected } - } - tele_period++; - if (tele_period == Settings.tele_period) { - tele_period = 0; + } else { + tele_period++; + if (tele_period >= Settings.tele_period) { + tele_period = 0; - MqttPublishTeleState(); + MqttPublishTeleState(); - mqtt_data[0] = '\0'; - if (MqttShowSensor()) { - MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN + mqtt_data[0] = '\0'; + if (MqttShowSensor()) { + MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN #if defined(USE_RULES) || defined(USE_SCRIPT) - RulesTeleperiod(); // Allow rule based HA messages + RulesTeleperiod(); // Allow rule based HA messages #endif // USE_RULES - } + } - XdrvCall(FUNC_AFTER_TELEPERIOD); + XdrvCall(FUNC_AFTER_TELEPERIOD); + } } } } diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index fc9f0dd0e..6afc247ff 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -169,6 +169,11 @@ void CmndDeepsleepTime(void) Settings.deepsleep = XdrvMailbox.payload; RtcSettings.nextwakeup = 0; deepsleep_flag = (0 == XdrvMailbox.payload) ? 0 : 4; + if (deepsleep_flag) { + if (!Settings.tele_period) { + Settings.tele_period = TELE_PERIOD; // Need teleperiod to go back to sleep + } + } } Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.deepsleep); }