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

Async Mode

Compile NetWizard against ESPAsyncWebServer so the captive portal runs on an asynchronous web server.

By default, NetWizard serves the captive portal with the core synchronous WebServer. In async mode, it uses ESPAsyncWebServer instead. Enable async mode only if your sketch uses ESPAsyncWebServer; the server you pass to the NetWizard constructor must then be an AsyncWebServer.

Dependencies

Async mode requires the following libraries in addition to those listed in Installation.

ESP32Async organization

Since v1.2.0, NetWizard depends on ESP32Async/ESPAsyncWebServer. The ESP32Async organization was formed by the core collaborators to maintain a single version of the library, and the improvements from the mathieucarbou fork have been merged into it. If you have the deprecated me-no-dev or mathieucarbou forks installed, remove them and install the ESP32Async libraries instead.

Enable async mode

Async mode is controlled by the NETWIZARD_USE_ASYNC_WEBSERVER macro. It defaults to 0; set it to 1.

  1. Open the Arduino libraries folder and go to NetWizard/src (NetWizard Pro: NetWizardPro/src).

  2. Open NetWizard.h (NetWizard Pro: NetWizardPro.h) and set the macro to 1:

    #define NETWIZARD_USE_ASYNC_WEBSERVER 1
  3. Save the file.

The change applies to every sketch that uses this copy of the library.

Usage

In async mode, include the TCP library for your platform and ESPAsyncWebServer.h, then pass an AsyncWebServer to NetWizard. NW.loop() is still required.

AsyncDemo.ino
#if defined(ESP32)
  #include <AsyncTCP.h>
#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350)
  #include <RPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include <NetWizard.h>  // NetWizard Pro: #include <NetWizardPro.h>

AsyncWebServer server(80);
NetWizard NW(&server);

void setup() {
  Serial.begin(115200);
  NW.autoConnect("NetWizard Demo", "");

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

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

Benefits

  • Requests are handled in the background: the asynchronous server processes HTTP requests outside your main loop instead of in NW.loop(). DNS processing, status updates and callbacks still run in NW.loop(), so keep calling it frequently.
  • Responsiveness: the device remains responsive to other tasks while requests are served.
  • Compatibility: many projects and libraries, such as ESP-DASH, are built on ESPAsyncWebServer. Async mode lets NetWizard share the same server instance.

On this page