From 3264acfffeb9a1bafa405ce8f491441e2c4cbcf6 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 11 Oct 2020 14:23:56 +0200 Subject: [PATCH] Fix Telegram message decoding error regression from v8.5.0.1 --- CHANGELOG.md | 1 + RELEASENOTES.md | 1 + tasmota/xdrv_40_telegram.ino | 29 ++++++++++++++++++++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4148608f8..75fd26a73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Convert AdcParam parameters from versions before v9.0.0.2 +- Telegram message decoding error regression from v8.5.0.1 ## [9.0.0.1] - 20201010 ### Added diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c95883bdb..5f0a86a04 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -86,6 +86,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota - Shutter timing problem due to buffer overflow in calibration matrix (#9458) - Light wakeup exception 0 (divide by zero) when ``WakeupDuration`` is not initialised (#9466) - Thermostat sensor status corruption regression from v8.5.0.1 (#9449) +- Telegram message decoding error regression from v8.5.0.1 ### Removed - Support for direct upgrade from Tasmota versions before v7.0 diff --git a/tasmota/xdrv_40_telegram.ino b/tasmota/xdrv_40_telegram.ino index 9834d3b30..ba7414d22 100644 --- a/tasmota/xdrv_40_telegram.ino +++ b/tasmota/xdrv_40_telegram.ino @@ -199,9 +199,24 @@ void TelegramGetUpdates(String offset) { } } if (1 == i) { - Telegram.message[i][0] = a.substring(0, ch_count); //Assign of parsed message into message matrix if only 1 message) + Telegram.message[i][0] = a.substring(0, ch_count -2); //Assign of parsed message into message matrix if only 1 message) } if (i > 1) { i = i -1; } +/* + String buf = response; // we need to keep a copy of the buffer + JsonParser parser((char*)buf.c_str()); + JsonParserObject root = parser.getRootObject(); + if (root) { + JsonParserArray arr = root["result"]; + if (arr) { + i++; + Telegram.message[i][0] = arr[0].getStr(); +// Telegram.message[0][0] = arr[0].getObject()["update_id"].getStr(); + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TGM: Msg %s"), Telegram.message[i][0].c_str()); + } + } +*/ } //check result of parsing process if (response == "") { @@ -229,18 +244,18 @@ void TelegramAnalizeMessage(void) { JsonParser parser((char*)buf.c_str()); JsonParserObject root = parser.getRootObject(); if (root) { + // {"update_id":14354450, + // "message":{"message_id":141, + // "from":{"id":139920293,"is_bot":false,"first_name":"Theo","last_name":"Arends","username":"tjatja","language_code":"nl"}, + // "chat":{"id":139920293,"first_name":"Theo","last_name":"Arends","username":"tjatja","type":"private"}, + // "date":1602346120, + // "text":"Status 1"}} Telegram.message[i][0] = root["update_id"].getStr(); Telegram.message[i][1] = root["message"].getObject()["from"].getObject()["id"].getStr(); Telegram.message[i][2] = root["message"].getObject()["from"].getObject()["first_name"].getStr(); Telegram.message[i][3] = root["message"].getObject()["from"].getObject()["last_name"].getStr(); Telegram.message[i][4] = root["message"].getObject()["chat"].getObject()["id"].getStr(); Telegram.message[i][5] = root["message"].getObject()["text"].getStr(); - // Telegram.message[i][0] = root["update_id"].as(); - // Telegram.message[i][1] = root["message"]["from"]["id"].as(); - // Telegram.message[i][2] = root["message"]["from"]["first_name"].as(); - // Telegram.message[i][3] = root["message"]["from"]["last_name"].as(); - // Telegram.message[i][4] = root["message"]["chat"]["id"].as(); - // Telegram.message[i][5] = root["message"]["text"].as(); } int id = Telegram.message[Telegram.message[0][0].toInt()][0].toInt() +1;