QuickFix for Telegram (#12451)

This commit is contained in:
Theo Arends 2021-06-24 10:14:07 +02:00
parent 684852b81c
commit 8d2728b94a
1 changed files with 20 additions and 5 deletions

View File

@ -104,7 +104,7 @@ bool TelegramInit(void) {
} }
String TelegramConnectToTelegram(String command) { String TelegramConnectToTelegram(String command) {
// AddLog(LOG_LEVEL_DEBUG, PSTR("TGM: Cmnd %s"), command.c_str()); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: Cmnd %s"), command.c_str());
if (!TelegramInit()) { return ""; } if (!TelegramInit()) { return ""; }
@ -114,18 +114,33 @@ String TelegramConnectToTelegram(String command) {
// AddLog(LOG_LEVEL_DEBUG, PSTR("TGM: Connected in %d ms, max ThunkStack used %d"), millis() - tls_connect_time, telegramClient->getMaxThunkStackUse()); // AddLog(LOG_LEVEL_DEBUG, PSTR("TGM: Connected in %d ms, max ThunkStack used %d"), millis() - tls_connect_time, telegramClient->getMaxThunkStackUse());
telegramClient->println("GET /"+command); // telegramClient->println("GET /"+command);
String request = String("GET /") + command +
" HTTP/1.1\r\n" +
"Host: api.telegram.org" +
"\r\n" + "Connection: close\r\n\r\n";
telegramClient->print(request);
char c; char c;
int ch_count=0; int ch_count=0;
uint32_t now = millis(); uint32_t now = millis();
bool avail = false; bool avail = false;
bool start = false;
while (millis() -now < 1500) { while (millis() -now < 1500) {
while (telegramClient->available()) { while (telegramClient->available()) {
char c = telegramClient->read(); char c = telegramClient->read();
if (ch_count < 700) { // Allow up to two messages if (ch_count < 1000) { // Allow up to two messages
response = response + c;
ch_count++; if (c == '{') {
start = true;
}
if (start) {
response = response + c;
ch_count++;
}
} }
avail = true; avail = true;
} }