Crash using ESPAsyncWebServer.h and UniversalTelegramBot.h

Hello All,

Does someone has an idea why my ESP8266 crashes/resets when calling the server.
Program works fine upto the moment I call http://localLANIPfromESP/temp

With serial output :
22:07:03.784 -> Webrequest 1 for TEMP received. Temperature sent : 21.00
22:07:06.983 ->
22:07:06.983 -> Soft WDT reset
22:07:06.983 ->
22:07:06.983 -> >>>stack>>>
22:07:06.983 ->
22:07:06.983 -> ctx: sys
22:07:06.983 -> sp: 3fffea30 end: 3fffffb0 offset: 01b0
22:07:06.983 -> 3fffebe0: 00000000 00000000 3ffef868 4020d5c7
22:07:06.983 -> 3fffebf0: 00000000 00000000 00000000 646e6573
22:07:06.983 -> 3fffec00: 7373654d 00656761 000005dc 3fffeccc
and so on ...

Am I mixing some incompatible or double functions # include here ?

Thanks for all reply's

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include "ESPAsyncWebServer.h"
#include <UniversalTelegramBot.h>

//OLED pins ESP8266 (battery capacity board)
#define OLED_SDA 4
#define OLED_SCL 5 
#define OLED_RST 16
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

int timelastupdate, timesincelastupdate, requestcountertemperature=0, requestcounterON=0, requestcounterOFF=0;
int h, m, s;

// Set your access point network credentials
const char* ssid = "SSIDNETWORK";
const char* password = "12345";
String LastRequest="NONE";

// Initialize Telegram BOT
#define BOTtoken "----------:--------------------------------------"  // your Bot Token (Get from Botfather)

// Use @myidbot to find out the chat ID of an individual or a group
#define CHAT_ID "123456789"

X509List cert(TELEGRAM_CERTIFICATE_ROOT);
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

String readTemp() {
  timelastupdate = millis();
  LastRequest="TEMP";
  requestcountertemperature++;
  float temperatureC = 21;
  Serial.print("Webrequest "); Serial.print(requestcountertemperature); Serial.print(" for "); Serial.print(LastRequest); Serial.print(" received. Temperature sent : "); Serial.println(temperatureC);
  bot.sendMessage(CHAT_ID, "Temp request received", "");
  return String(temperatureC);
}

String AnswerON() {
  timelastupdate = millis();
  LastRequest="ON";
  requestcounterON++;
  Serial.print("Webrequest "); Serial.print(requestcounterON); Serial.print(" for "); Serial.print(LastRequest); Serial.print(" received.");
  return String("AAN ontvangen");
}

String AnswerOFF() {
  timelastupdate = millis();
  LastRequest="OFF";
  requestcounterOFF++;
  Serial.print("Webrequest "); Serial.print(requestcounterOFF); Serial.print(" for "); Serial.print(LastRequest); Serial.print(" received.");
  return String("UIT ontvangen");
}


void setup() {
  // Start the Serial Monitor
  Serial.begin(115200);

  // Add root certificate for api.telegram.org
  client.setTrustAnchors(&cert);
  
  //reset OLED display via software if LoRa module is used
  pinMode(OLED_RST, OUTPUT);
  digitalWrite(OLED_RST, LOW);
  delay(20);
  digitalWrite(OLED_RST, HIGH);

  //initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  
  // connect to WiFi
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) { 
    delay(500);
    Serial.print(".");
  }
  Serial.println(""); Serial.print("Connected to WiFi network with IP Address: "); Serial.println(WiFi.localIP());

      String botmessage = "ESP8266 started and WiFi connected.\n";
      botmessage += "SSID in use is " + String(ssid) + ".\n";
      botmessage += "Chat ID is " + String(CHAT_ID) + ".\n";
      bot.sendMessage(CHAT_ID, botmessage);

    server.on("/temp", HTTP_GET, [](AsyncWebServerRequest *request){
  request->send_P(200, "text/plain", readTemp().c_str());
  // LastRequest="TEMP";
  });

  server.on("/ON", HTTP_GET, [](AsyncWebServerRequest *request){
  request->send_P(200, "text/plain", AnswerON().c_str());
  // LastRequest="ON";
  });

  server.on("/OFF", HTTP_GET, [](AsyncWebServerRequest *request){
  request->send_P(200, "text/plain", AnswerOFF().c_str());
  // LastRequest="OFF";
  });

  // Start web server
  server.begin();
  
}

void loop() {
  display.clearDisplay(); display.setTextColor(WHITE); display.setTextSize(1);
  display.setCursor(0,0); display.print("Module ON ");
  display.setCursor(0,10); display.print("IP: "); display.print(WiFi.localIP());
  display.setCursor(0,20); display.print("Req. "); display.print(requestcountertemperature); display.print(" ago");
  timesincelastupdate = (millis() - timelastupdate)/1000;
  h=timesincelastupdate/3600; m=(timesincelastupdate-(h*3600))/60; s=(timesincelastupdate-(h*3600)-(m*60));
  display.print(h); display.print("h"); display.print(m); display.print("m"); display.print(s); display.print("s");
  display.setCursor(0,30); display.print("Last req was:  "); display.print(LastRequest);
  display.display();
}

You can try the ESP Exception Decoder to see whether the stack dump provides some useful clue to the problem:
https://arduino-esp8266.readthedocs.io/en/3.0.2/Troubleshooting/stack_dump.html

Thanks for the try but exception decoder couldn't decode anything.
Some one else a idea or hint to try ?
Really stuck here and would like to use Telegram bot and ESP8266 as server at the same time.

You must remove the timestamps from the stack dump. You can turn off the timestamps in the Arduino IDE Serial Monitor by unchecking the box next to "Show timestamp.

I did. Tried a second time and now it worked.
What should I look for or find ? ( sorry, no experience with the exception decoder)

Decoding stack results
0x4021a8b2: operator new(unsigned int) at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/new_op.cc line 52
0x4021134c: malloc(size_t) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 1677
0x4021a8b2: operator new(unsigned int) at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/new_op.cc line 52
0x40204b85: WiFiClient::connect(IPAddress, unsigned short) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi\src/include/ClientContext.h line 41
0x402060c3: BearSSL::WiFiClientSecure::connect(char const*, unsigned short) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp line 226
0x4020d49e: UniversalTelegramBot::sendPostToTelegram(String const&, ArduinoJson6180_D1::ObjectRef) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp line 156
0x4020e774: String::concat(String const&) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 319
0x4020d5e4: UniversalTelegramBot::sendPostMessage(ArduinoJson6180_D1::ObjectRef, bool) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp line 644
0x4020e9a9: String::equals(char const*) const at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 502
0x4020d6f1: UniversalTelegramBot::sendMessage(String const&, String const&, String const&, int) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp line 575
0x4020e32a: String::reserve(unsigned int) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 148
0x4020e388: String::copy(char const*, unsigned int) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 211
0x4020e3c8: String::String(char const*) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 36
0x4020119a: readTemp() at C:\Users\Bart De Pauw\Documents\Arduino\ESP8266-OLED-P02-Server01/ESP8266-OLED-P02-Server01.ino line 62
0x4020e3c8: String::String(char const*) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 36
0x402011ec: std::_Function_handler ::_M_invoke(const std::_Any_data &, AsyncWebServerRequest *) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266/WString.h line 272
0x4020e32a: String::reserve(unsigned int) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 148
0x4020ea1e: String::equalsIgnoreCase(String const&) const at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 529
0x4020a4fc: AsyncCallbackWebHandler::handleRequest(AsyncWebServerRequest*) at c:\users\bart de pauw\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-3-20ed2b9\xtensa-lx106-elf\include\c++\4.8.2/functional line 2464
0x40208918: AsyncWebServerRequest::_removeNotInterestingHeaders() at C:\Users\Bart De Pauw\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\WebRequest.cpp line 182
0x4020aa5d: AsyncWebServer::_attachHandler(AsyncWebServerRequest*) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\WebServer.cpp line 116
0x40208a40: AsyncWebServerRequest::_parseLine() at C:\Users\Bart De Pauw\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\WebRequest.cpp line 581
0x4021a8b2: operator new(unsigned int) at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/new_op.cc line 52
0x4020f08e: String::trim() at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\WString.cpp line 812
0x40208c9c: AsyncWebServerRequest::_onData(void*, unsigned int) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\WebRequest.cpp line 124
0x40100bb0: millis() at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_wiring.cpp line 186
0x40223ea4: mem_free at core/mem.c line 237
0x40206c8c: std::_Function_base::_Base_manager ::_M_manager(std::_Any_data &, const std::_Any_data &, std::_Manager_operation) at c:\users\bart de pauw\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-3-20ed2b9\xtensa-lx106-elf\include\c++\4.8.2/functional line 1931
0x40208cf5: std::_Function_handler ::_M_invoke(const std::_Any_data &, void *, AsyncClient *, void *, unsigned int) at c:\users\bart de pauw\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-3-20ed2b9\xtensa-lx106-elf\include\c++\4.8.2/functional line 2073
0x4020b15e: AsyncClient::_recv(std::shared_ptr &, tcp_pcb*, pbuf*, long) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\ESPAsyncTCP-master\src\ESPAsyncTCP.cpp line 649
0x4020a311: std::_Function_handler ::_M_invoke(const std::_Any_data &, void *, AsyncClient *) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\WebServer.cpp line 46
0x4020b30e: AsyncClient::_s_recv(void*, tcp_pcb*, pbuf*, long) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\ESPAsyncTCP-master\src\ESPAsyncTCP.cpp line 738
0x4021e4b8: tcp_input at core/tcp_in.c line 501
0x4021134c: malloc(size_t) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 1677
0x4022319d: ip4_input at core/ipv4/ip4.c line 710
0x40211108: _umm_free(void*) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 1304
0x4021afc5: ethernet_input_LWIP2 at netif/ethernet.c line 188
0x4021adfb: esp2glue_ethernet_input at glue-lwip/lwip-git.c line 441
0x4024eca2: ethernet_input at glue-esp/lwip-esp.c line 363
0x4024ecb3: ethernet_input at glue-esp/lwip-esp.c line 371
0x40234ac9: br_aes_ct_ortho at src/symcipher/aes_ct.c line 223
0x4021a9d9: glue2esp_linkoutput at glue-esp/lwip-esp.c line 299
0x4021ac5b: new_linkoutput at glue-lwip/lwip-git.c line 235
0x402233b8: ip4_output_if_opt_src at core/ipv4/ip4.c line 1007
0x40211b57: Adafruit_SSD1306::drawPixel(short, short, unsigned short) at C:\Users\Bart De Pauw\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp line 609
0x401001e2: twi_delay(unsigned char) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_si2c.cpp line 186
0x4020faa4: twi_write_bit(bool) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_si2c.cpp line 219
0x40203000: TwoWire::write(unsigned char) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\Wire\Wire.cpp line 163
0x402029a8: Adafruit_SSD1306::display() at C:\Users\Bart De Pauw\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp line 959
0x40203000: TwoWire::write(unsigned char) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\Wire\Wire.cpp line 163
0x4020fb99: twi_write_byte(unsigned char) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_si2c.cpp line 243
0x4020fb99: twi_write_byte(unsigned char) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_si2c.cpp line 243
0x4020fd85: twi_writeTo(unsigned char, unsigned char*, unsigned int, unsigned char) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_si2c.cpp line 273
0x40203158: TwoWire::endTransmission(unsigned char) at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\Wire\Wire.cpp line 153
0x4020f248: esp_yield() at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_main.cpp line 91
0x4021a8b2: operator new(unsigned int) at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/new_op.cc line 52
0x4020f32a: __yield() at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_main.cpp line 100
0x40202a47: Adafruit_SSD1306::display() at C:\Users\Bart De Pauw\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp line 971
0x402017a0: loop() at C:\Users\Bart De Pauw\Documents\Arduino\ESP8266-OLED-P02-Server01/ESP8266-OLED-P02-Server01.ino line 149
0x4020f2f8: loop_wrapper() at C:\Users\Bart De Pauw\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\cores\esp8266\core_esp8266_main.cpp line 125

What can I do to restrict the problem ?