witnessmenow/Universal-Arduino-Telegram-Bot

Doesn't work with WiFiManager and alternatives

stsdc opened this issue · 1 comments

stsdc commented

So I have tried latest WiFiManager@2.0.15-rc1 and AutoConnect@1.4.2, but with the same result. There is a connection with internet, but the bot is unresponsive.

Please look into this scatch, I'm trying to reproduce echoBot example here:

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>

#include <ESP8266WebServer.h>
#include <WiFiManager.h>

#define BOT_TOKEN_LENGTH 47
char BOTtoken[BOT_TOKEN_LENGTH] =  "XXXXXXXXX:xxxxxxxxxxxxxxxxxxxxxxxxx";

X509List cert(TELEGRAM_CERTIFICATE_ROOT);

WiFiClientSecure client_secure;
UniversalTelegramBot *bot;

int  BOT_MTBS = 1000; // mean time between scan messages
long bot_lasttime;    // last time messages' scan has been done


void handleNewMessages(int numNewMessages) {
  for (int i = 0; i < numNewMessages; i++) {
    bot->sendMessage(bot->messages[i].chat_id, bot->messages[i].text, "");
  }
}

void setup() {
  Serial.begin(74880);
  WiFiManager wifiManager;

  client_secure.setTrustAnchors(&cert); 
  wifiManager.autoConnect("AP_door", "pwd");

  if (WiFi.status() == WL_CONNECTED) {
    bot = new UniversalTelegramBot(BOTtoken, client_secure);
  }
}

void loop() {
  if (millis() - bot_lasttime > BOT_MTBS) {
    int numNewMessages = bot->getUpdates(bot->last_message_received + 1);

    while (numNewMessages) {
      Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot->getUpdates(bot->last_message_received + 1);
    }

    bot_lasttime = millis();
  }
}

My platformio.ini:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = 74880
lib_ldf_mode = deep
build_type = debug
monitor_filters = esp8266_exception_decoder, colorize
build_flags = -std=c++1y
lib_deps = 
	adafruit/Adafruit GFX Library@^1.11.3
	https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
	bblanchon/ArduinoJson@6.19.4
	witnessmenow/UniversalTelegramBot@^1.3.0
	https://github.com/tzapu/WiFiManager
	arduino-libraries/NTPClient@^3.2.1
Dilbao commented

I think you are not connected right after wifiManager.autoConnect("AP_door", "pwd"); and if check failed.
Add a delay after that line, something like:

while (WiFi.status() != WL_CONNECTED) {
 delay(50);
}