在安装过程中重新初始化对象,以便在使用UniversalTelegramBot时覆盖全局初始化



我正在努力实现UniversalTelegramBot(https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot)在所有的例子中,我可以看到机器人被声明为一个全局变量。这需要变量BOTtoken在引导序列的早期就可用,并且它在那里被定义为一个固定值。

我正在尝试将BOTtoken存储在EEPROM中,并希望在设置过程中定义机器人,同时保持其全局范围。

有可能吗?(如果你需要代码,请告诉我(

WiFiClientSecure client;
UniversalTelegramBot bot(SECRET_BOT_TOKEN, client); // here it is defined at the global level
void setup() {
Serial.begin(115200);
EEPROM.begin(EEPROM_SIZE);
ReadUsersFromEEPROM(); // then I read some users from the EEPROM, including the token
UniversalTelegramBot bot(bot_token, client); // here is where I would like the init of the BOT to be, so it use the bot_token I just read from EEPROM, but if I re-declare like this it does not overrride the global setup and if I remove the global declaration, this remains local.

}

好吧,我找到了答案。事实上,通用Telegram Bot代码的原始编码器在GitHub中回复了我。

我缺少的部分是将机器人定义为全局范围中的指针,并在设置中使用NEW标记。。。

bot=新的UniversalTelegramBot(bot_token,客户端(;

这里有一个例子:https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/UsingWiFiManager/UsingWiFiManager.ino

谢谢大家!!!

最新更新