Callbacks
React to connection status changes, captive portal state changes and submitted configuration with NetWizard callbacks.
NetWizard notifies your sketch of changes through callbacks. Register them in setup() before calling autoConnect(). Each method stores one callback; registering another replaces the previous one.
onConnectionStatus and onPortalState are invoked from NW.loop() (also while autoConnect() is running) when the value differs from the last value reported.
Methods
onConnectionStatus()
void onConnectionStatus(std::function<void(NetWizardConnectionStatus)> callback);Called when the connection status changes. The new status is passed as a NetWizardConnectionStatus value.
void setup() {
// ...
NW.onConnectionStatus([](NetWizardConnectionStatus status) {
if (status == NetWizardConnectionStatus::CONNECTED) {
Serial.printf("Connected, IP: %s\n", NW.localIP().toString().c_str());
}
});
// ...
}onPortalState()
void onPortalState(std::function<void(NetWizardPortalState)> callback);Called when the captive portal state changes. The new state is passed as a NetWizardPortalState value. Use it to reflect the setup progress outside the portal, for example by turning an LED green when the configuration succeeds.
void setup() {
// ...
NW.onPortalState([](NetWizardPortalState state) {
if (state == NetWizardPortalState::SUCCESS) {
// indicate successful setup
}
});
// ...
}onConfig()
void onConfig(std::function<bool()> callback);Called when the user submits the configuration parameters in the portal, after the submitted values have been written to the NetWizardParameter objects. Return true to accept the submission or false to reject it. If no callback is registered, every submission is accepted.
void setup() {
// ...
NW.onConfig([&]() {
// read, validate and store the parameter values
return true;
});
// ...
}See Parameters for details.