Giter Club home page Giter Club logo

Comments (3)

ivan140 avatar ivan140 commented on July 3, 2024

Hi,

Had the same issue with ESP 8266. My workaround was:

  • after receiving the reset command setting the text in the message to some other not resetting command: ' '
  • saving the fact, that you just resetet to EEPROM
  • adding some delay before calling the actual ESP.restart()
else if (m.text.indexOf("/reset") > -1) {
                m.text = "";
                if (!config.justResetet) {
                  bot.sendMessage(m, "reset");
                  config.justResetet = true;
                  EEPROM.put(0, config);
                  EEPROM.commit();
                  delay(3000);
                  ESP.restart();
                } else {
                  config.justResetet = false;
                  EEPROM.put(0, config);
                  EEPROM.commit();
                }
}

P.S.: it's maybe more of a feature(bug) of the ESP itself, rather than the CTBot library. There are some issues and comments about this function and how it works. If I'm not mistaken, it saves the complete state of variables and so on and repeats the whole iteration of the loop.

from ctbot.

shurillu avatar shurillu commented on July 3, 2024

Hello mad-b, hello ivan140,

the issue is relate to the method how Telegram knows if a message is corrected collected or not.
Everytime a getNewMessage() method is called, it send to the Telegram server the last received message, so the Telegram server knows that message is corrected received and send all the new messages.
Going back to your issue, this simple trick will resolve the problem: before calling the ESP.restart(), call the getNewMessage() method to confirm the reset message is arrived.
You don't need to handle the message (if any) fetched by the getNewMessage() because it will not be confirmed so after the reset, it will be fetched one more time.
Try this:

#include "CTBot.h"
CTBot myBot;
String ssid  = "mySSID"    ; // REPLACE mySSID WITH YOUR WIFI SSID
String pass  = "myPassword"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "myToken"   ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
void setup() {
	Serial.begin(115200);
	Serial.println("Starting TelegramBot...");
	myBot.wifiConnect(ssid, pass);
	myBot.setTelegramToken(token);
}
void loop() {
	TBMessage msg;
	if (myBot.getNewMessage(msg)) {
     if (msg.text.equalsIgnoreCase("restart")) {
        myBot.getNewMessage(msg); // confirm the restart message is received
        ESP.restart();
     } else 
	      myBot.sendMessage(msg.sender.id, msg.text);
	}	 
	delay(500);
}

from ctbot.

mad-b avatar mad-b commented on July 3, 2024

Thanks for the info, Stefano. I was suspecting it was something of the sort :)

from ctbot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.