cotestatnt / AsyncTelegram2

Powerful, flexible and secure Arduino Telegram BOT library. Hardware independent, it can be used with any MCU capable of handling an SSL connection.
MIT License
83 stars 25 forks source link

getMaxAllocHeap in send message method causes issues #106

Closed MicDG closed 1 year ago

MicDG commented 1 year ago

Hello, as somebody else reported in issue #83 I encountered some problems when sending messages due to this lines in the sendMessage(...) method (I am using an ESP32):

#if defined(ESP8266)
            DynamicJsonDocument doc(ESP.getMaxFreeBlockSize() - BUFFER_MEDIUM);
#elif defined(ESP32)
            DynamicJsonDocument doc(ESP.getMaxAllocHeap);
#else
            DynamicJsonDocument doc(BUFFER_BIG);
#endif

The keyboard I am generating needs a DynamicJsonDocument with 768 bytes of capacity to deserialize it correctly (checked this with the ArduinoJson Assistant), but the deserialization fails with a NoMemory error even though getMaxAllocHeap() reports over 49 kB of allocatable heap. In fact the document isn't created at all (checked with doc.capacity() ). Changing the code as such fixes this:

#elif defined(ESP32)
            DynamicJsonDocument doc(BUFFER_BIG);

Maybe the code should be adjusted to use a buffer size chosen via defines?

cotestatnt commented 1 year ago

Hi @MicDG I've removed those lines along all the source files.

In order to set a custom json buffer size, you can use the metod setJsonBufferSize()

MicDG commented 1 year ago

Thank you very much for the quick fix!