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
85 stars 25 forks source link

incomplete message received #119

Open sanderkob opened 1 year ago

sanderkob commented 1 year ago

AsyncTelegram2 version 2.2.1 and 2.2.2 board ESP8266 No change to default format style, so it is HTML. Built with VisualStudioCode PlatformIO, default board params.

I occasionally get an incomplete error, generated in this code https://github.com/cotestatnt/AsyncTelegram2/blob/526027396a3ac208d36c54f8eea09c06a51a866d/src/AsyncTelegram2.cpp#L240-L253

The json buffer is large enough, I checked this by sending additional info to my chat (the code added to AsyncTelegram2.cpp is in https://gist.github.com/sanderkob/693cf1c7664d2048fde183263edff221 ) I try to solve this without serial logging. The output from the additional code is:

[ERROR] - No memory: inrease buffer size with "setJsonBufferSize(buf_size)" method
[ERROR] - deserializeJson() failed
IncompleteInput
[ERROR] - rxbuffer

{"ok":true,"result":[
[ERROR] - JsonBufferSize
4096
[ERROR] - rxbuffer len msg
23
[ERROR] - content len msg
23

It appears that the intended message to be received is {"ok": true,"result": []} (with 25 chars) and deserialization fails because the last two chars are actually missing. The content of m_rxbuffer as sent to my chat is {"ok": true,"result": [ with 21 chars However, m_rxbuffer len and content len are both 23 chars.

So, the primary question is: why is the message truncated (]} missing)? In addition, why are spaces missing in the message that shows the content of m_rxbuffer?

To further investigate, I looked at the code https://github.com/cotestatnt/AsyncTelegram2/blob/526027396a3ac208d36c54f8eea09c06a51a866d/src/AsyncTelegram2.cpp#L164C9-L173

If the intent is to timeout after one sec, I would expect the code to be for (uint32_t timeout = millis(); (millis() - timeout < 1000) && pos < len;) to ensure that the loop exits after 1000 milliseconds or when pos reaches len. However, I do not think this is relevant to the problem at hand.

sanderkob commented 1 year ago

Some additional information. I have two telegram bots on ESP8266 that use AsyncTelegram2; the error occurs in both. Occurrence is of the order of 1 in 10^5 (10 ppm), i.e. once in every 100.000 getUpdates.. The error is independent of : rx,tx buffersize - setBufferSizes() 512, 2048 json buffersize - setJsonBufferSize() 1024, 2048 TCP_MSS size - lwip version 2.0.3, low memory (default) TCP_MSS = 536, high bandwith TCP_MSS = 1460 CPU frequenty - 80, 160 MHz

Are there any other factors to check? Since the error is not detrimental to my applicatrion I could safely ignore it.