Closed gravedigger21 closed 2 years ago
This is the same as https://github.com/cotestatnt/AsyncTelegram2/issues/62
You have to wait that message is fully handled before restart ESP. Check this example
if (msgText.equals("/rst")) {
bot.sendMessage(msg, "reset");
Serial.println("reset"); Serial.println();
// Wait until bot synced with telegram to prevent cyclic reboot
while (!myBot.noNewMessage()) {
Serial.print(".");
delay(50);
}
ESP.reset();
}
Yes, it works. But now I would like to understand why this happens. Why doesn't regular delay() before ESP.reset() help? When is a received command considered processed? Does the module send some kind of confirmation to the bot?
When you send a request of update to Telegram server, it will reply with a list of last unreaded messages with specific message ID.
In order to get last message marked as readed, the next update request have to request for the last message ID + 1
otherwise Telegram server will reply again with last one unreaded.
This is the reason why you need to wait for noNewMessage()
in you sketch.
Who can explain why after executing ESP.reset () there is a loop on the execution of the last command? I use this code:
The module receives a command, executes it, reboots and ... again receives the same command. And so it goes on indefinitely. Only uploading the same code with the commented-out ESP.reset() line helps. Here is what I get in Serial
The last received message after a reboot is again perceived as a new one? What is it connected with?