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

Configuration

Configure the NetWizard constructor, portal strategy, hostname, timeouts and compile-time options.

This page covers the NetWizard constructor and the settings that control how NetWizard connects and runs the captive portal. Call the setters in setup() before autoConnect().

Constructor

NetWizard(NETWIZARD_WEBSERVER* server);

Prop

Type

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

Methods

setStrategy()

void setStrategy(NetWizardStrategy strategy);

Sets the captive portal strategy, which determines whether autoConnect() waits for the portal to close.

StrategyBehavior
NetWizardStrategy::BLOCKING (default)If autoConnect() starts the portal, it does not return until the portal closes: the user exits the portal, the portal times out, or the portal is stopped by reset().
NetWizardStrategy::NON_BLOCKINGautoConnect() returns immediately after starting the portal. The portal runs in the background while NW.loop() is called.

Use NON_BLOCKING when your application must perform important tasks while the portal is active, and handle connection status changes at runtime with the callbacks. Otherwise, the blocking strategy is recommended.

void setup() {
  // ...
  NW.setStrategy(NetWizardStrategy::NON_BLOCKING);
  NW.autoConnect("NetWizard Demo", "");
  // ...
}

setHostname()

void setHostname(const char* hostname);
void setHostname(String& hostname);

Sets the hostname the device uses to identify itself on the network. The default is netwizard. NetWizard applies the hostname each time it connects to a network.

NW.setHostname("my-device");

setConnectTimeout()

void setConnectTimeout(unsigned long timeout);

Sets how long, in milliseconds, autoConnect() tries to connect to the saved network before it starts the captive portal. Within this period, NetWizard retries the connection every 10 seconds. The default is 30000 (30 seconds).

NW.setConnectTimeout(15000);

This timeout does not apply to credentials submitted in the portal; the portal waits a fixed 30 seconds for those connections.

setPortalTimeout()

void setPortalTimeout(unsigned long timeout);

Sets how long, in milliseconds, the captive portal stays active. The default is 300000 (5 minutes).

NW.setPortalTimeout(150000);

The timer restarts while at least one client is connected to the access point, and the portal does not time out while it is testing submitted credentials. When the portal times out, it stops and NetWizard connects to the saved network, if any.

Compile-time options

Define these macros before the library is compiled, for example with PlatformIO build_flags (-DNETWIZARD_DEBUG=1), or edit their defaults in the library header.

Prop

Type

On this page