From 5916838386f1b5ab5b103f220308be4dc66123b5 Mon Sep 17 00:00:00 2001 From: Igor B <7295529@gmail.com> Date: Sun, 29 May 2022 13:50:30 +0300 Subject: [PATCH] Update UniversalTelegramBot.cpp split the buffer into chunks 512b for big buffers (example for framebuffer higher resolution photos (>320x240)) --- src/UniversalTelegramBot.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/UniversalTelegramBot.cpp b/src/UniversalTelegramBot.cpp index fbb1ac7..d491acd 100644 --- a/src/UniversalTelegramBot.cpp +++ b/src/UniversalTelegramBot.cpp @@ -256,11 +256,33 @@ String UniversalTelegramBot::sendMultipartFormDataToTelegram( if (getNextByteCallback == nullptr) { while (moreDataAvailableCallback()) { - client->write((const uint8_t *)getNextBufferCallback(), getNextBufferLenCallback()); - #ifdef TELEGRAM_DEBUG - Serial.println(F("Sending photo from buffer")); - #endif + //split the buffer into chunks 512b for big buffers (example for framebuffer higher resolution photos (>320x240)) + unsigned int fbSize = getNextBufferLenCallback() ; + uint8_t* fBuffer = getNextBufferCallback(); + + uint8_t buffer[512]; + unsigned int count = 0; + unsigned int i = 0; + while (i <= fbSize) { + buffer[count] = fBuffer[i]; + i++; + count++; + if (count == 512) { + #ifdef TELEGRAM_DEBUG + Serial.println(F("Sending photo from buffer - chunk")); + #endif + client->write((const uint8_t *)buffer, 512); + count = 0; + } + } + if (count > 0) { + #ifdef TELEGRAM_DEBUG + Serial.println(F("Sending photo from buffer - remaining chunk")); + Serial.println(count); + #endif + client->write((const uint8_t *)buffer, count); } + } } else { #ifdef TELEGRAM_DEBUG Serial.println(F("Sending photo by binary"));