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

Unstable sending of ESP32 messages #81

Closed usr222 closed 2 years ago

usr222 commented 2 years ago

I use the device on ESP32. I wrote a code in which, upon the occurrence of certain conditions, for example, the closure and opening of the sensor must be sent to telegrams. But I noticed that these messages are not always sent. More precisely, immediately after turning on the device for about 1 hour, everything works. Then some messages are not sent (or are they sent, but do not come?). For example, the sensor is closed - the message has gone and was received. After some time, the sensor was opened - the property came. Then, again, after some time, the sensor is closed - the message does not come. The sensor is open - the message received. And so it can happen with different events. There is no specific pattern. At the same time, the device itself works normally, without freezes, which is confirmed by duplicate messages in Serial Port. Replaced the AsyncTelegram2 library in the same code on UniversalTelegrambot - for 5 days everything has been working fine for 5 days. But since this synchronous library would like to use yours. What could be the problem?

cotestatnt commented 2 years ago

Hi @usr222 Could you share the part of code which is not working (or even better the complete sketch).

If you have omitted the instruction myBot.getNewMessage(msg), this could be the reason because the bot need to be synced with Telegram server even if you have to "send only" messages. Which version of library are you using?

usr222 commented 2 years ago

hi @cotestatnt The code is very big. Here is part of the code

switch (mode) {
    case tmOFF :
 if (!flag_msg_off) {
Serial.println("OPEN");
bot.sendMessage(CHAT_ID, "OPEN", "");
        flag_msg_off = 1;
}
break;
case tmON :
 if (!flag_msg_on) {
Serial.println("CLOSE");
bot.sendMessage(CHAT_ID, "CLOSE", "");
        flag_msg_on = 1;
}
break;
...

}

and yes i didn't use myBot.getNewMessage(msg). But I did not use a similar function with the UniversalTelegrambot library, but everything works there without it. I should just write at the beginning of the loop

TBMessage msg; bot.getNewMessage(msg);

?

cotestatnt commented 2 years ago

UniversalTelegramBot is another library and it works in a slighlty different mode off course. Probably what is done with AsyncTelegram2 when the method getNewMessage() get called is done in other way under the hood.

Yes, adding those 2 lines of code inside loop is enought and it should work without problems unitl you keep your ESP32 on and connected.

usr222 commented 2 years ago

Added. I'll watch for a few days and then report back.