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