CTBot
CTBot copied to clipboard
No exit from function getNewMessage, testConnection if no internet or no correct work (glitch) telegram api
Hello. I’m doing a small project on ESP8266 using your library. Faced with the suspension of cycle loop() on functions getNewMessage, testConnection in the event of the sudden disappearance of the Internet or glitches on the Telegram api server. Is it possible to add a timeout to the library to perform these functions? Is there any other solution that can prevent freezing on these functions? Thanks in advance for your reply.
Hello hamster66, the problem you faced is dued to the WiFiClientSecure class. With a very quick googling you can found this and this. So a solution to your problem could be adding something like that in the ctbot.cpp:
String CTBot::sendCommand(String command, String parameters)
{
#if CTBOT_USE_FINGERPRINT == 0
WiFiClientSecure telegramServer;
#else
BearSSL::WiFiClientSecure telegramServer;
telegramServer.setFingerprint(m_fingerprint);
#endif
// ----------> ADD THE FOLLOWING LINE (timeout in milliseconds).
telegramServer.setTimeout(1000);
// check for using symbolic URLs
if (m_useDNS) {
// try to connect with URL
if (!telegramServer.connect(TELEGRAM_URL, TELEGRAM_PORT)) {
Let me know if it work. Cheers,
Stefano
Hi Stefano. I'm sorry, but apparently this solution does not work. It is possible that hangs when disconnecting / connecting the Internet became a little less, but they are definitely present. Most likely there is still a place where the function may hang
Mmmm I see. Have you tired to check the connection BEFORE calling the getNewMessage() method? Something like this:
if (WiFi.status() != WL_CONNECTED) {
// not connected, do connection stuff or wait the connection is up
}
// call getNewMessage() method
Stefano
The problem is not in wifi. My situation is when there is a normal wifi connection but the link to the Telegram server suddenly disappears or the Telegram server temporarily does not work correctly (failure). I already make a separate ping of api.telegram.org using my own resources and if it does not pass I do not call the functions of your library. This greatly improved the situation, but if the Internet disappears during the call getNewMessage or testConnection, there is a high probability of freezing in these functions.
Is there really no more ideas? :(
Hello, same problem any new solution ?
I had to radically change the algorithm of work. Now I am using reboot on WDT in case of freezing when calling these routines. This is definitely a crutch, but it works well :) We are waiting for a more elegant solution from Stefano