khoih-prog / ESPAsync_WiFiManager

This is an ESP32 (including ESP32-S2 and ESP32-C3) / ESP8266 WiFi Connection Manager, using ESPAsyncWebServer, with fallback web configuration portal. Use this library for configuring ESP32, ESP8266 modules' WiFi, etc. Credentials at runtime. You can also specify static DNS servers, personalized HostName, fixed or random AP WiFi channel. With examples supporting ArduinoJson 6.0.0+ as well as 5.13.5- . Using AsyncDNSServer instead of DNSServer now.
MIT License
291 stars 73 forks source link

Extremely long response time / connection timeouts #17

Closed tpalaz closed 3 years ago

tpalaz commented 3 years ago

Hello! I would like to share a problem which I have been experiencing now for roughly a week. On my ESP8266, the AsyncWebServer is often responding at a rate which is extremely slow (25s - up to 3 minutes). The sketch being used is a modified example (specifically, the DRD-Esp8266 Webserver). Here is the relevant code for webserver setup:

    webServer.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
       request->send(200, "text/plain", "hello there!");
    });

    webServer.on("/all", [](AsyncWebServerRequest * request)
    {
      String json('{');
      json += "\"heap\":" + String(ESP.getFreeHeap());
      json += ", \"analog\":" + String(analogRead(A0));
      json += ", \"gpio\":" + String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16)));
      json += "}";
      request->send(200, "text/json", json);
      json.clear();
    });
    webServer.begin();

When connecting to either "/" or "/all", sometimes the response is extremely quick (3ms) or incredibly slow / times out. Here are the request headers (they are the same for both pages, and do not change if the response is slow/fast)

GET / HTTP/1.1
Host: 192.168.1.69
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9

Similarily, here is the respone:

HTTP/1.1 200 OK
Content-Length: 12
Content-Type: text/plain
Connection: close
Accept-Ranges: none

The timing console shows that the initial connection hangs (anywhere from instant to 10+ seconds), and then the Waiting(TTFB) hangs for a long time too (10ms --- 5+ minutes).

This happens randomly, and there is no indication that it is caused by memory. The heap available when making requests is consistently at ~32872, and at lowest drops to about 2.9.

If the request does not got through, this is the error: (failed)net::ERR_CONNECTION_TIMED_OUT

There are no files being served, nothing. Interestingly, the captive portal almost always works and is always pretty quick to respond. I'm really confused what could be causing this. Iv'e tested on 2 seperate ESP8266 and both share similar results. As always, I am loving the library.

khoih-prog commented 3 years ago

Again thanks for your nice words about the library.

I've just retested the Async_ESP_FSWebServer_DRD and didn't find out any issue as mentioned. Even the files are loaded from SPIFFS/LittleFS, the response time is very quick.

Selection_585

I suggest you start from scratch, move ahead methodologically until starting experiencing problem, then find out why.

  1. Start from the original Async_ESP_FSWebServer_DRD
  2. Add/replace your code step-by-step and test every time OK until moving ahead

I'm afraid without the same code and settings environment (networks, hardware, routers, etc. ), no one can duplicate the issue and help you.

Remember to use the IP address instead of the mDNS name to avoid unreliability of the mDNS.

For example: using 192.168.2.186/edit instead of http://async-esp8266fs.local/edit