Hi All
I really hope someone can help me. I have used the ESP8266 numerous times in projects but I am experiencing really odd behaviour when joining a network.
The project should be really simple, all I want to do is detect if the ESP8266 is alive and connected to the network after coming out of reset. I have a client side JavaScript that looks whether the ESP8266 IP address is serving out a simple web-page (implementing a true ping does not really seem possible in javascript from a client web-browser without a number of other pre-requisites). I enable CORS so there is no issue there.
I have a ASUS RT-BE58U router. When the ESP8266 comes out of reset the following seems to happen:
- The router immediately picks it up and assigns an IP address (within seconds as seen on the router interface)
- The ESP8266 does not seem to respond to pings until after quite some time (minutes)
- The ESP8266 does not seem to serve the simple web-page until after some time later (sometimes 10's of minutes).
- The ESP8266 web-server may subsequently fail ( be no longer reachable) but I can still ping the ESP8266.
- All the time the router sees the ESP8266 attached.
There are different variations on this, sometimes it can work OK-ish in that wait times of minutes are reduced to 10's of seconds, sometimes the web-page is never up, ping normally works reliably .... eventually.
One odd thing is, is that there is a button on the router web-interface that says "Apply Settings" and even if I don't change any settings, I can push it, the router says it is applying setting (with a percentage progress) and at around 50-70% hey-ho the ESP8266 connects and serves the web-page with no problem. This is the only consistent feature of my problem.
I know it is not a signal strength problem. It doesn't seem to be an over-complex web-page. I have PC's and phones on the network with no problem. I do not have Wifi7 enabled. Same issue even when I disable the firewall.
I realise this is a very specific problem but I have been going around in circles for days and days with no luck. Has anyone seen anything like this? Are there any tools that could help me debug this?
I really hope someone can point me the right direction.
Thanks in advance.
Here is my web-page code:
// Simple website to detect the ESP8266 is alive
#include <ESP8266WiFi.h>
//#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//#include <ESP8266mDNS.h>
ESP8266WebServer server(80);
void setup() {
//Serial.begin(115200);
WiFi.mode (WIFI_STA);
WiFi.begin("xxxxxxxx", "xxxxxxxxxx");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
//Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.onNotFound(handleNotFound);
server.enableCORS(true);
server.begin();
}
void loop() {
delay(500);
server.handleClient();
}
void handleRoot() {
server.send(200, "text/plain", "Detected!");
}
void handleNotFound(){
String message = "Error!";
server.send(404, "text/plain", message);
}