From 7ca298ba56432adcbf338e07095a76efd4e6ee15 Mon Sep 17 00:00:00 2001 From: Tolentino Cotesta Date: Wed, 27 Nov 2024 15:14:42 +0100 Subject: [PATCH] small fix --- src/AsyncTelegram2.cpp | 37 +++++++++++-------------------------- src/AsyncTelegram2.h | 7 ------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/AsyncTelegram2.cpp b/src/AsyncTelegram2.cpp index 047562c..7e285f6 100644 --- a/src/AsyncTelegram2.cpp +++ b/src/AsyncTelegram2.cpp @@ -102,32 +102,18 @@ bool AsyncTelegram2::sendCommand(const char *command, const char *payload, bool // Blocking mode if (blocking) { - bool close_connection = false; - uint16_t len = 0, pos = 0; - // Skip headers - while (telegramClient->connected()) + if (!telegramClient->find((char *)HEADERS_END)) { - String line = telegramClient->readStringUntil('\n'); - if (line == "\r") - break; - if (line.indexOf("close") > -1) - { - close_connection = true; - } - if (line.indexOf("Content-Length:") > -1) - { - len = line.substring(strlen("Content-Length: ")).toInt(); - } + log_error("Invalid HTTP response"); + telegramClient->stop(); + return false; } - m_rxbuffer.clear(); - // If there are incoming bytes available from the server, read them and store: - for (uint32_t timeout = millis(); (millis() - timeout > 1000) || pos < len;) + // If there are incoming bytes available from the server, read them and print them: + m_rxbuffer = ""; + while (telegramClient->available()) { - if (telegramClient->available()) - { - m_rxbuffer += (char)telegramClient->read(); - pos++; - } + yield(); + m_rxbuffer += (char)telegramClient->read(); } m_waitingReply = false; if (m_rxbuffer.indexOf("\"ok\":true") > -1) @@ -156,7 +142,7 @@ bool AsyncTelegram2::getUpdates() if (m_waitingReply == false) { char payload[BUFFER_SMALL]; - snprintf(payload, BUFFER_SMALL, "{\"limit\":1,\"timeout\":0,\"offset\":%" INT32 "}", (int)m_lastUpdateId); + snprintf(payload, BUFFER_SMALL, "{\"limit\":1,\"timeout\":0,\"offset\":%"PRIu32"}", m_lastUpdateId); sendCommand("getUpdates", payload); } } @@ -278,8 +264,7 @@ MessageType AsyncTelegram2::getNewMessage(TBMessage &message) updateDoc.shrinkToFit(); m_rxbuffer = ""; - // if (!updateDoc.containsKey("result")) // Deprecated - if (!updateDoc["result"].is()) + if (!updateDoc["result"]) { log_error("JSON data not expected"); serializeJsonPretty(updateDoc, Serial); diff --git a/src/AsyncTelegram2.h b/src/AsyncTelegram2.h index 2022dad..5ecb8d7 100644 --- a/src/AsyncTelegram2.h +++ b/src/AsyncTelegram2.h @@ -40,13 +40,6 @@ #endif -// int 32 bit long, (eg. ESP32 platform) -#if INT_MAX == 2147483647 - #define INT32 "d" -#else - #define INT32 "ld" -#endif - /* This affect only inline keyboard with at least one callback function defined. If you need more than MAX_INLINEKYB_CB distinct keybords with