ESP8266 Odd Router Interaction

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


I’m not completely sure but it sounds like the ESP does get an IP and the router just isn’t really “opening the path” to it until you hit Apply Settings I’ve seen a few ASUS routers act like this with small IoT devices

Maybe try a few things:

  • adding a short delay after WiFi connects before starting the server
  • avoiding long delays in loop() and using small delays + yield()
  • trying a static IP
  • checking once with a phone hotspot to see if the behavior changes

I might be wrong, but this feels more like a router-side issue than your code Hope it helps a bit

I do not have the hardware but check the following:

Function order can cause problems with some versions of the compiler.

You call handleRoot() and handleNotFound() before the compiler has seen them.
On ESP8266 Arduino this sometimes compiles, sometimes fails depending on board settings.

simply add forward declarations at the top or move the functions above setup().

A 500 ms delay makes the web server laggy. Sometimes browsers retry because the ESP8266 is too slow to answer.

I always add a WiFi reconnect.

if (WiFi.status() != WL_CONNECTED) {
WiFi.reconnect();
}

Hi taha_zarif90 and gilshultz

Thank you so much for your super-speedy suggestions. I have implemented most of them as they are really good practice to do. Thanks for the benefit of your experience.

Sadly, I still have a misbehaving ESP8266 :slightly_frowning_face:. Although, as you say this could be a server-side issue .... and then when the ping works and the web-server doesn't, I change my mind :thinking:

It happens with any ESP8266 I try so it doesn't seem to be a board issue either :face_with_raised_eyebrow:

I will continue to try some of your other ideas.

Thanks again.

Honestly I’m still not sure but the fact that every ESP8266 shows the same behavior really makes me think it’s something in the router rather than the boards The ping works but the web-server doesn’t” part is especially weird it feels like the router is treating ICMP and TCP differently or delaying something in its table

If you haven’t tried it yet testing the ESP on a different access point or a phone hotspot might give a really clear clue If it works normally there then the ASUS is almost certainly the culprit

I might be wrong, but this seems like one of those subtle router quirks

Hi taha_zarif90

Yes, it definitely seems that more testing is required. It is probably true that if it were something more systemic and not a quirk of my setup there would be far more users experiencing similar issues.

Thanks

Hi All

Just to update this thread, I have tried it with a WiFi hotspot on my phone and the behaviour in terms of associating with the WiFi and serving the web-page is much more in-keeping with my expectations. It all takes a matter of seconds, normally less than 20.

So it seems that it has something to do with the router.

Does anyone know what could be causing this on issue with an ASUS RT-BE58U router?

Thanks in advance

Maybe client Isolation is active in the wireless settings of the router

Thanks for the suggestion Rintin

I have had a look and have yet to find that option in my router.

But there is definitely something wrong with the router behaviour, all ESP8266's are powered off and it still reports them as connected (although the access time is not ticking up).

Hi All

Another update:

When I set the router's Authentication Method to "WPA/WPA2-Personal" things seemed to work much better, similar to the phone hot-spot (which was also using "WPA2-Personal". This did require the router to go through the "Apply Settings" process.

However, after several connections and disconnections to the network (initiated by me hitting the ESP8266 reset button), it is back to misbehaving again. Grrr

Apologies if this is a newbie question but does the ESP8266 with the ESP8266WiFi.h library only support "WPA/WPA2-Personal" ?

Thanks

Great the hotspot test basically proves the ESP8266 is fine.
On many ASUS routers the fix is usually in the Wi-Fi settings.
Try checking these:

1: turn off Airtime Fairness
2: turn off Target Wake Time (TWT)
3: set WPA to WPA2/WPA3 (not WPA3-only)
4: split 2.4GHz and 5GHz if “Smart Connect” is on

One of those usually fixes slow or inconsistent ESP8266 connections

That’s a good point if client isolation is enabled the ESP can connect but the web-server won’t be reachable
Worth checking for sure On some ASUS routers it’s hidden under “Wireless → Professional”

That’s pretty unusual if the router keeps showing devices that are actually powered off then its client table really isn’t updating properly
A reboot usually clears that but if it doesn’t it could be a firmware bug

If you haven’t yet try updating the router firmware or restarting it once
If the ESPs start behaving normally afterward then it confirms the router was the culprit

It’s not your code.
The ESP8266 simply doesn’t work well with routers using WPA3 or mixed WPA2/WPA3 modes.
It only reliably supports WPA2-Personal (AES).
If you set your router to WPA2-Personal / AES only, the connection problems after reset should disappear.

For more details, the official ESP8266 WiFi documentation explains the supported security modes:

Hi taha_zarif90

Thanks again for your great suggestions.

I have checked all the settings you suggested

1: turn off Airtime Fairness - Yep off
2: turn off Target Wake Time (TWT) - Yep off
3: set WPA to WPA2/WPA3 (not WPA3-only) - Set to "WPA/WPA2-Personal"
4: split 2.4GHz and 5GHz if “Smart Connect” is on - Yep only 2.4GHz, the 5GHz is a totally different SSID and not linked

Also "Set AP isolated" is off which is the closest I could find to "client isolation".

Sadly, none of this makes it behave as it should. :man_shrugging:

I can try a router reboot but I have been reading around about firmware bugs in Asus routers where the client table does not update properly. If only I'd known when I selected it.

Thank you for your thumbs-up for the code and also the link regarding security modes. All good information and really useful to know.

Thanks, and thanks again.

Given everything you already checked, it really does feel like the router is the weak link here. When an ESP8266 has the right security mode and a clean 2.4 GHz setup, it normally behaves the same way every time. The only thing that can still create this kind of inconsistent behavior is the router’s firmware not updating the client table correctly.

A reboot is definitely worth trying, but if the bug reports about your Asus model are accurate, a firmware update (or even rolling back to a stable version) might be the only real fix.

If you try a firmware change, I’d be curious to hear whether the ESP starts reconnecting more reliably afterward.

Hi taha_zarif90

I will investigate whether there is any stable firmware.

Router vs ESP8266; looks like the winner is the Mighty Flea !

Hi All

Sorry to open this old thread but I believe I have found a solution to this issue, despite having almost given up.

The following line in the ESP8266 setup code section fixes this connection/routing issue for me

WiFi.setPhyMode(WIFI_PHY_MODE_11G);

I don't know if this fixes it to only 11G or why that helps ,but I am just so pleased it does.

I hope this helps other uses

PS
Credit to lukehaas for suggestion this as a solution to a similar issue