-
Notifications
You must be signed in to change notification settings - Fork 0
Home
For my IoT projects I needed a responsive telegram bot client, with response times lower than 1 second.
I typically use ESP8266 boards running at 160 MHz.
This TelegramBotClient was adequate but over the years I improved it.
Because of a bad internet connection (with many short losses of connection) I wanted to make the code more robust.
It frequently happened that because of the loss of connection the polling process got stuck.
Therefore I introduced two watchdogs:
- for the connection to the server, 35 seconds
- for the polling process, 300 seconds
To prevent loss of outgoing messages I made a FIFO buffer for 5 messages (which number can be easily increased). Incoming messages are kept on the server by default.
In the past the SSL connection could be used wither security
The WifiClientSecure library (BearSSL), in use since Arduino ESP8266 Core 2.5 needs a fingerprint for api.telegram.org
However, by settings client.setInsecure() it will work without the fingerprint. Security is of no concern in my applications.
Recently I found out that the default server buffers for recv and xmit are 16384 and 512, as set in WifiClientSecure.
Now, the api.telegram.org server supports the MFLN option (TLSv1.3) where MFLN stands for Maximum Fragment Length Negotiation.
Therefore a smaller recv buffer is sufficient.
I did not investigate the lower limit but now operate with client.setbuffersizes(4092,512).
This saves me 10kB of heap memory.
I recently upgraded the code to work with ArduinoJson version 6.
In the earlier version, my polling reponse times were typically below 700 ms with 160 MHz and lwIP v2 Higher Bandwidth.
But now, with ArduinoJson v6, my response times ar over 1000 ms. I cannot explain this.