Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incomplete message received #119

Open
sanderkob opened this issue Aug 14, 2023 · 1 comment
Open

incomplete message received #119

sanderkob opened this issue Aug 14, 2023 · 1 comment

Comments

@sanderkob
Copy link

sanderkob commented Aug 14, 2023

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

if (err)
{
log_error("deserializeJson() failed\n");
log_debug("%s", err.c_str());
log_error();
log_error(m_rxbuffer);
// Skip this message id due to the impossibility to parse correctly
m_lastUpdateId = m_rxbuffer.substring(m_rxbuffer.indexOf(F("\"update_id\":")) + strlen("\"update_id\":")).toInt() + 1;
// int64_t chat_id = m_rxbuffer.substring( m_rxbuffer.indexOf("{\"id\":") + strlen("{\"id\":")).toInt();
m_rxbuffer = "";
// Inform the user about parsing error (blocking)
sendTo(message.chatId, "[ERROR] - No memory: inrease buffer size with \"setJsonBufferSize(buf_size)\" method");
return MessageNoData;

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant