CTBot icon indicating copy to clipboard operation
CTBot copied to clipboard

No exit from function getNewMessage, testConnection if no internet or no correct work (glitch) telegram api

Open hamster66 opened this issue 5 years ago • 7 comments

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.

hamster66 avatar Jan 22 '20 12:01 hamster66

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

shurillu avatar Jan 23 '20 08:01 shurillu

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

hamster66 avatar Jan 23 '20 11:01 hamster66

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

shurillu avatar Jan 23 '20 12:01 shurillu

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.

hamster66 avatar Jan 23 '20 14:01 hamster66

Is there really no more ideas? :(

hamster66 avatar Jan 31 '20 07:01 hamster66

Hello, same problem any new solution ?

HyperConnect1 avatar Jun 19 '20 00:06 HyperConnect1

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

hamster66 avatar Jun 23 '20 08:06 hamster66