From a1fc5d48909aa7f1799c3348fec647609c6ace09 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 22 Jul 2020 09:34:35 +0200 Subject: [PATCH] Fix telegram restart loop Fix telegram restart loop (#8619) --- tasmota/xdrv_40_telegram.ino | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tasmota/xdrv_40_telegram.ino b/tasmota/xdrv_40_telegram.ino index a7beb5005..f99a121b7 100644 --- a/tasmota/xdrv_40_telegram.ino +++ b/tasmota/xdrv_40_telegram.ino @@ -57,7 +57,7 @@ BearSSL::WiFiClientSecure_light *telegramClient = nullptr; static const uint8_t Telegram_Fingerprint[] PROGMEM = USE_TELEGRAM_FINGERPRINT; struct { - String message[3][6]; // amount of messages read per time (update_id, name_id, name, lastname, chat_id, text) + String message[3][6]; // Amount of messages read per time (update_id, name_id, name, lastname, chat_id, text) uint8_t state = 0; uint8_t index = 0; uint8_t retry = 0; @@ -67,6 +67,7 @@ struct { bool recv_enable = false; bool echo_enable = false; bool recv_busy = false; + bool skip = true; // Skip first telegram if restarted } Telegram; bool TelegramInit(void) { @@ -172,7 +173,7 @@ void TelegramGetUpdates(String offset) { // } // ]} -// AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: Response %s"), response.c_str()); + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: Response %s"), response.c_str()); // parsing of reply from Telegram into separate received messages int i = 0; //messages received counter @@ -349,10 +350,14 @@ void TelegramLoop(void) { Telegram.state++; } } else { - if (Telegram.message[0][0].toInt() && (Telegram.message[Telegram.index][5].length() > 0)) { - String logging = TelegramExecuteCommand(Telegram.message[Telegram.index][5].c_str()); - if (logging.length() > 0) { - TelegramSendMessage(Telegram.message[Telegram.index][4], logging); + if (Telegram.skip) { // Skip first update as it may be a restart (again) + Telegram.skip = false; + } else { + if (Telegram.message[0][0].toInt() && (Telegram.message[Telegram.index][5].length() > 0)) { + String logging = TelegramExecuteCommand(Telegram.message[Telegram.index][5].c_str()); + if (logging.length() > 0) { + TelegramSendMessage(Telegram.message[Telegram.index][4], logging); + } } } Telegram.message[0][0] = ""; // All messages have been replied - reset new messages