witnessmenow / Universal-Arduino-Telegram-Bot

Use Telegram on your Arduino (ESP8266 or Wifi-101 boards)
MIT License
1.09k stars 302 forks source link

Client would not send message after connection was closed #229

Open saikek opened 3 years ago

saikek commented 3 years ago

Hello, I'm getting very strange behavior in my application, most likely due to dependencies.

1) I'm using ESP8266 & ESP32 board.

When I run U-A-T-B code in a separate sketch, everything works fine. When I'm running it integrated into my project - Notify from setup() works, but when one is triggered in loop - it does not work - exception is:

[BOT Client]Connecting to server
[BOT Client]Conection error

I'm using in-secure client configuration & fresh fingerprints & cers:

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

WiFiClientSecure secured_client;
X509List cert(TELEGRAM_CERTIFICATE_ROOT);
UniversalTelegramBot bot(TELEGRAM_BOT_TOKEN, secured_client);

void TelegramNotifier::Init()
{
    const uint8_t fingerprint[20] = { 0xF2, 0xAD, 0x29, 0x9C, 0x34, 0x48, 0xDD, 0x8D, 0xF4, 0xCF, 0x52, 0x32, 0xF6, 0x57, 0x33, 0x68, 0x2E, 0x81, 0xC1, 0x90} ;

    secured_client.setTrustAnchors(&cert);
    secured_client.setFingerprint(fingerprint);
    secured_client.setInsecure();

    configTime(0, 0, "pool.ntp.org");

    Serial.println(F("[Telegram]: Setup is complete"));

    Notify("Telegram is OK!");
}
void TelegramNotifier::Notify(String message)
{
    Serial.println("Sending notify message " + message);
    bot.sendMessage(BOT_CHAT_ID, message, "");
}

My platformio project have other dependencies:

lib_deps =
    ESP Async WebServer@1.2.3
    AsyncMqttClient@0.8.2
    arduino-libraries/NTPClient
    mobizt/ESP Mail Client@^1.0.13
    witnessmenow/UniversalTelegramBot@^1.3.0

Platform version:

PLATFORM: Espressif 8266 (2.6.3) > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:
 - framework-arduinoespressif8266 3.20704.0 (2.7.4)
 - tool-esptool 1.413.0 (4.13)
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - tool-mklittlefs 1.203.210203 (2.3)
 - tool-mkspiffs 1.200.0 (2.0)
 - toolchain-xtensa 2.40802.200502 (4.8.2)

Dependency graph:

Dependency Graph
|-- <ESP Async WebServer> 1.2.3
|   |-- <ESPAsyncTCP> 1.2.2
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|   |-- <ArduinoJson> 6.16.1
|-- <AsyncMqttClient> 0.8.2
|   |-- <ESPAsyncTCP> 1.2.2
|   |   |-- <ESP8266WiFi> 1.0
|-- <NTPClient> 3.1.0
|-- <ESP Mail Client> 1.0.13
|   |-- <ESP8266WiFi> 1.0
|   |-- <SD(esp8266)> 2.0.0
|   |   |-- <SDFS> 0.1.0
|   |   |   |-- <ESP8266SdFat> 1.1.0
|   |   |   |   |-- <SPI> 1.0
|   |   |   |-- <SPI> 1.0
|   |-- <LittleFS(esp8266)> 0.1.0
|   |-- <ESP8266HTTPClient> 1.2
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Ethernet(esp8266)> 1.0.4
|   |   |-- <SPI> 1.0
|-- <UniversalTelegramBot> 1.3.0
|   |-- <ArduinoJson> 6.16.1
|-- <ESP8266WiFi> 1.0
|-- <Ethernet(esp8266)> 1.0.4
|   |-- <SPI> 1.0
|-- <SD(esp8266)> 2.0.0
|   |-- <SDFS> 0.1.0
|   |   |-- <ESP8266SdFat> 1.1.0
|   |   |   |-- <SPI> 1.0
|   |   |-- <SPI> 1.0
|-- <ArduinoOTA> 1.0
|   |-- <ESP8266WiFi> 1.0
|   |-- <ESP8266mDNS> 1.2
|   |   |-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0

Is anyone aware about any incompatibilities with other libraries or can give any hint on how can I narrow down this problem ?