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

Portal

Start and stop the NetWizard captive portal on demand and read its current state.

autoConnect() starts the captive portal automatically when it is needed. The methods on this page control the portal directly, for example to let the user reconfigure the device from a button press.

Methods

startPortal()

void startPortal();

Starts the captive portal on demand. The access point uses the SSID and password passed to autoConnect(), so call autoConnect() first.

If the device is connected to its saved network, it stays connected while the portal runs. Otherwise, the portal runs in access point mode only. startPortal() returns immediately regardless of the strategy; keep calling NW.loop().

The portal is subject to the portal timeout and stops when it expires.

NW.startPortal();

stopPortal()

void stopPortal();

Stops the captive portal if it is active: removes the portal routes, stops the DNS server and closes the access point. If credentials are saved, NetWizard then connects to the saved network; otherwise, it turns WiFi off.

NW.stopPortal();

getPortalState()

NetWizardPortalState getPortalState();

Returns the current portal state. See Portal states.

NetWizardPortalState state = NW.getPortalState();

Portal states

The portal tracks the progress of the setup flow so that the web interface stays in sync with the device, even after the device reconnects. NetWizardPortalState is a scoped enum:

ValueMeaning
NetWizardPortalState::IDLENo setup is in progress. This is also the state after the portal stops.
NetWizardPortalState::CONNECTING_WIFIThe user submitted credentials; NetWizard is starting the connection.
NetWizardPortalState::WAITING_FOR_CONNECTIONNetWizard is waiting for the device to connect to the submitted network, for up to 30 seconds.
NetWizardPortalState::SUCCESSThe device connected and the credentials were saved, or a submission containing only parameters was accepted.
NetWizardPortalState::FAILEDReserved. The current release does not enter this state.
NetWizardPortalState::TIMEOUTThe device did not connect to the submitted network within 30 seconds. The user can try again.

To react to state changes, register onPortalState().

On this page