Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with WiFiManager and alternatives #325

Open
stsdc opened this issue Apr 11, 2023 · 1 comment
Open

Doesn't work with WiFiManager and alternatives #325

stsdc opened this issue Apr 11, 2023 · 1 comment

Comments

@stsdc
Copy link

stsdc commented Apr 11, 2023

So I have tried latest [email protected] and [email protected], 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/[email protected]
	witnessmenow/UniversalTelegramBot@^1.3.0
	https://github.com/tzapu/WiFiManager
	arduino-libraries/NTPClient@^3.2.1
@Dilbao
Copy link

Dilbao commented Jul 25, 2023

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants