Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cotestatnt committed Nov 27, 2024
1 parent e22e94c commit 7ca298b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
37 changes: 11 additions & 26 deletions src/AsyncTelegram2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -278,8 +264,7 @@ MessageType AsyncTelegram2::getNewMessage(TBMessage &message)
updateDoc.shrinkToFit();

m_rxbuffer = "";
// if (!updateDoc.containsKey("result")) // Deprecated
if (!updateDoc["result"].is<const char*>())
if (!updateDoc["result"])
{
log_error("JSON data not expected");
serializeJsonPretty(updateDoc, Serial);
Expand Down
7 changes: 0 additions & 7 deletions src/AsyncTelegram2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ca298b

Please sign in to comment.