ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

Detect the begin and the end of page serving

Open ghost opened this issue 2 years ago • 0 comments

In my ESP32 Arduino application in my loop() I have a lot of fast routines (i.e. motors, LEDs, remote IR, etc...). I discovered that when all this stuff is running the page loading is VERY slow.

Commenting out those functions leads the loading to be fast as usual. Of course if the processor is busy for other tasks, the time needed to serve the page increases.

Now, no matter what are those functions, is there a way to detect when the ESPAsyncWebServer is serving a page? In this way I can decide in my main loop() to temporary disable the functions that are not mandatory.

Something like this:

AsyncWebServer server;

server.serveStatic("/", LittleFS, "/www")
      .setDefaultFile("index.html")
      .setTemplateProcessor(std::bind(&WebApp::processor, this, std::placeholders::_1));

then:

void loop()
{
    if (!server.isServing()) // <--- metacode
    {
        class1.loop();
        class2.loop();
        class3.loop();
    }
}

ghost avatar Nov 14 '23 11:11 ghost