Anniversary Sale · up to 80% off all librariesEnds Nov 9Shop now
SOFTTDocs

Async Mode

Serve the ElegantOTA portal through ESPAsyncWebServer, with the dependencies and configuration required on each platform.

By default, ElegantOTA registers its routes on the synchronous web server of your platform's Arduino core (WebServer or ESP8266WebServer). In async mode, it uses ESPAsyncWebServer (AsyncWebServer) instead.

Enable async mode only if your project uses ESPAsyncWebServer. You cannot use the synchronous web server and ESPAsyncWebServer in the same firmware.

Dependencies

Install the following libraries for your platform:

In PlatformIO, the ElegantOTA library manifest declares esp32async/ESPAsyncWebServer@^3.12.0 as a dependency. Add the TCP library for your platform to lib_deps yourself, for example:

platformio.ini
lib_deps =
  ayushsharma82/ElegantOTA@^4.0.0
  esp32async/AsyncTCP@^3.5.0          ; ESP32
  ; esp32async/ESPAsyncTCP@^2.0.0     ; ESP8266
  ; ayushsharma82/RPAsyncTCP@^1.3.2   ; RP2040 / RP2350

Use a different fork of a dependency

If your project depends on a fork of ESPAsyncWebServer that is not listed above, prevent PlatformIO from installing the declared dependency. This configuration is not tested.

  1. Install ElegantOTA manually, as described in Installation.
  2. Open the library.json file in the ElegantOTA library folder and delete the dependencies entry.

Enable async mode

Async mode is controlled by the ELEGANTOTA_USE_ASYNC_WEBSERVER macro, which defaults to 0.

The Arduino IDE cannot set build flags, so you enable async mode in the library source:

  1. Open your Arduino libraries folder.

  2. Open the src folder of the ElegantOTA library.

  3. In ElegantOTA.h (ElegantOTA Pro: ElegantOTAPro.h), set the ELEGANTOTA_USE_ASYNC_WEBSERVER macro to 1:

    #define ELEGANTOTA_USE_ASYNC_WEBSERVER 1
  4. Save the file.

Repeat this change after you update the library, because an update replaces the file.

Usage

In async mode, pass a pointer to your AsyncWebServer to ElegantOTA.begin(). Keep calling ElegantOTA.loop() from loop(); it is still responsible for rebooting the device after a successful update and, in ElegantOTA Pro, for direct downloads and update channel checks.

main.cpp
#if defined(ESP8266)
  #include <ESP8266WiFi.h>
  #include <ESPAsyncTCP.h>
#elif defined(ESP32)
  #include <WiFi.h>
  #include <AsyncTCP.h>
#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350)
  #include <WiFi.h>
  #include <RPAsyncTCP.h>
#endif

#include <ESPAsyncWebServer.h>
#include <ElegantOTA.h>

AsyncWebServer server(80);

void setup() {
  // ... connect to Wi-Fi

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send(200, "text/plain", "Hi! This is ElegantOTA AsyncDemo.");
  });

  ElegantOTA.begin(&server);
  server.begin();
}

void loop() {
  ElegantOTA.loop();
}

Benefits

  • Non-blocking request handling: ESPAsyncWebServer handles HTTP requests outside your loop() function, so the main loop does not have to call a request handler to serve the portal.
  • Responsiveness: the device can continue other work while it serves the portal and receives an update.

On this page