Migrating from v1 to v2
Update a NetWizard v1 sketch to v2, where parameters became typed settings fields.
NetWizard v2 brings a redesigned portal in 12 languages, and replaces NetWizardParameter with typed settings fields. Most sketches only need their parameter declarations and getValue() calls updated. Everything else, including the WiFi credentials saved on your devices, carries over.
What changed
| Area | v1 | v2 |
|---|---|---|
| Settings | NetWizardParameter with a type constant | One class per field: NetWizardInput, NetWizardHeader, ... |
| Values | Strings, converted with toInt() | Typed: getValue() returns String, int, float, double or bool |
| Invalid values | Saved as typed, or silently dropped | Rejected by the device, the portal shows an error |
| Settings-only save | Could change the WiFi connection | Never touches the saved WiFi credentials |
| Portal | Single layout, English | Redesigned, responsive, 12 languages |
| Static IP | - | setStaticIP(), NetWizard Pro |
Update the field declarations
Replace each NetWizardParameter with the class for its type. The type constants are gone, and so is the separate value type for numbers: the initial value sets it.
| v1 | v2 |
|---|---|
NetWizardParameter h(&NW, NW_HEADER, "MQTT"); | NetWizardHeader h(&NW, "MQTT"); |
NetWizardParameter d(&NW, NW_DIVIDER); | NetWizardDivider d(&NW); |
NetWizardParameter s(&NW, NW_SPACER); | NetWizardSpacer s(&NW); |
NetWizardParameter host(&NW, NW_INPUT, "Host", "", "mqtt.example.com"); | NetWizardInput host(&NW, "Host", "", "mqtt.example.com"); |
NetWizardParameter port(&NW, NW_INPUT, "Port", "1883"); | NetWizardInput port(&NW, "Port", 1883); |
NetWizardParameter key(&NW, NW_PASSWORD_INPUT, "API Key"); | NetWizardPassword key(&NW, "API Key"); |
NetWizardParameter ca(&NW, NW_TEXTAREA, "Root CA"); | NetWizardTextarea ca(&NW, "Root CA"); |
NetWizardParameter tls(&NW, NW_TOGGLE, "Use TLS", 1); | NetWizardToggle tls(&NW, "Use TLS", true); |
Password, textarea and toggle fields are available in NetWizard Pro. The placeholder and required arguments keep their positions and defaults, so a field that was optional in v1 is still optional when you pass false last.
If a v1 input held a number as text, such as a port, give it a numeric initial value in v2. The portal then shows the number keyboard, and the device rejects anything that isn't a number.
Update how you read values
getValue() now returns the field's own type, so the conversion calls go away:
| v1 | v2 |
|---|---|
host.getValue() or host.getValueStr() | host.getValue() |
port.getValue().toInt() | port.getValue() |
ratio.getValueFloat() | ratio.getValue() |
tls.getValueInt() == 1 | tls.getValue() |
host.getValue(str) | String str = host.getValue(); |
getValueStr(), getValueInt(), getValueFloat(), the getValue(T&) overloads, getType() and getPlaceholder() were removed. setValue(), setPlaceholder() and setRequired() work as before, with setValue() taking the field's type.
Before and after
NetWizardParameter nw_header(&NW, NW_HEADER, "MQTT");
NetWizardParameter nw_host(&NW, NW_INPUT, "Host", "", "mqtt.example.com");
NetWizardParameter nw_port(&NW, NW_INPUT, "Port", "1883");
NetWizardParameter nw_tls(&NW, NW_TOGGLE, "Use TLS", 1);
NW.onConfig([&]() {
String host = nw_host.getValueStr();
int port = nw_port.getValueStr().toInt();
bool tls = nw_tls.getValueInt() == 1;
return true;
});NetWizardHeader nw_header(&NW, "MQTT");
NetWizardInput nw_host(&NW, "Host", "", "mqtt.example.com");
NetWizardInput nw_port(&NW, "Port", 1883);
NetWizardToggle nw_tls(&NW, "Use TLS", true);
NW.onConfig([&]() {
String host = nw_host.getValue();
int port = nw_port.getValue();
bool tls = nw_tls.getValue();
return true;
});Other changes
- Registering fields by hand. Fields add themselves to
NetWizardwhen constructed. If your sketch calledaddParameter()/removeParameter()(Lite) oradd()/remove()with a parameter (Pro), drop those calls. - Header descriptions. A header's second argument is now a description shown under the title:
NetWizardHeader mqtt(&NW, "MQTT", "Where readings are sent");. - Portal language. The portal follows the visitor's browser language. Call
setLanguage()to choose the default yourself. - Saved credentials. Devices keep their saved WiFi network after the update. NetWizard Pro devices keep using DHCP until a static IP is set.
- Custom portals (NetWizard Pro). If you build your own portal from the Pro source, note that the settings schema now marks each input's value kind with
"k"("s","i"or"f"), toggles sendtrue/false, and numeric values are sent as JSON numbers. Start from the v2 portal source to pick these up.