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

Connection

Connect to the saved network, start the captive portal on demand, connect with new credentials and disconnect with the NetWizard API.

These methods start NetWizard and control the station (client) connection.

Methods

autoConnect()

void autoConnect(const char* ssid, const char* password);

Prop

Type

Loads the saved credentials and connects to the saved network. NetWizard starts the captive portal if either of the following is true:

  1. The device is not configured, that is, no credentials are saved.
  2. The device cannot connect to the saved network within the connect timeout, for example because the credentials are invalid or the network is out of range.

Whether autoConnect() returns before the portal closes depends on the strategy.

void setup() {
  // ...
  NW.autoConnect("NetWizard Demo", "");
  // ...
}

Call autoConnect() once in setup(), after configuring NetWizard and registering callbacks. The access point credentials are also used by startPortal().

loop()

void loop();

Runs NetWizard: processes DNS and, with the synchronous WebServer, HTTP requests; updates the connection status; advances the portal state; checks the portal timeout; and invokes the callbacks. Call it on every iteration of your sketch's loop().

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

connect()

bool connect();
bool connect(const char* ssid, const char* password);

Without arguments, connects to the saved network. Returns false if no credentials are saved, and true otherwise.

With ssid and password, overwrites the saved credentials, stores them persistently and connects to the new network. Returns true.

The return value indicates that a connection attempt was started, not that it succeeded. Monitor the result with onConnectionStatus() or getConnectionStatus().

NW.connect();                       // connect to the saved network
NW.connect("ssid", "password");     // save and connect to a new network

disconnect()

void disconnect();

Disconnects from the current WiFi network. The saved credentials are kept, so you can reconnect later with connect() or by restarting the device.

NW.disconnect();
  • Portal: start and stop the captive portal on demand.
  • Credentials: manage the saved credentials.

On this page