Documentation / Hardware

Joining a network

One widget that scans, asks for a password on the panel, and remembers it.

Getting an ESP32 onto WiFi is the same work every time: scan without freezing the screen, show what was found, take a password, say something useful when it fails, and keep the answer so the next boot is silent. WiFi Setup is that work as a single widget. Drop it on a screen and the generator writes the whole flow.

It is on the palette for the Espressif chips only - ESP32, S2, S3 and C3. On an STM32 or an RP2040 the tile is greyed with the reason, because the code behind it is the Arduino WiFi library.

The flow

Search, select, enter pass, verify. Four states, and the password is typed at exactly one of them - on the device, by the person holding it.

StateOn screenLeaves by
Search"Searching…", then the lista scan finishing, or Search again
SelectNetworks strongest first, with a lock where one is neededpicking one
Enter passA masked field and a keyboardthe keyboard's tick, or its cross
Verify"Joining…", then joined, or why notsuccess, or back to the list

An open network skips the middle step: there is nothing to type.

Settings

SettingDefaultWhat it does
TitleSelect networkThe heading above the list.
Go to when joined(none)The screen to move to once it is on the network. Only fires while this screen is the one on show, so a background reconnect does not pull somebody off whatever they were reading.
Go to on Back(none)Puts a Back button on the list. Worth setting: without it the only way off this screen is to join something, which strands anybody who opened it by accident.
Reconnect on bootonRejoins the stored network at startup without asking.
Join timeout20 sHow long to wait before giving up and saying so.
Show ForgetonA button that clears the stored network and starts a fresh scan.
Access pointOffOff, when it cannot join, or always on. See below.

Where the password goes

The widget writes two settings, and your design has to declare them: wifi.ssid and wifi.pass. The second must be marked secret, and the designer says so if it is not.

A secret is different from an ordinary setting in three ways, and all three exist to make one rule structural rather than a matter of care:

There is no field anywhere in the designer for typing a station password, and no reveal control on the device - LVGL normally shows each character for a second and a half as it is typed, and the generated lv_conf.h turns that off.

Access point mode

The board can be its own network, either as a fallback when it cannot join anything or all the time. Unlike a station password, the access point's is configured in the design - it has to be, because an access point publishes the password people need in order to reach it. There is no earlier moment at which somebody could have entered one.

SettingWhat it does
AP nameWhat the network is called.
AP passwordEmpty leaves it open. Otherwise eight characters minimum: softAP() given a shorter one returns success and brings the network up open without saying so, which is why the designer refuses that range rather than warning about it.
Do not broadcastThe network is there but does not appear in a scan. You join it by typing the name.

What a design can read

The network is a set of variable sources, so an IP address goes on a label through an ordinary binding.

ValueTypeNotes
IP addressTextEmpty until it has joined.
Network nameTextWhat it is joined to.
Signal strengthInteger, dBmAbout -50 is excellent, -85 barely usable. -100 means not joined.
Signal barsInteger0 to 4, for an indicator.
ConnectedBoolean
Last problemTextWhy the last attempt failed. Worth putting on screen.
Access point running / name / addressBoolean, Text, TextOffered only when the widget runs an access point.

The text ones need a Text variable.

Two things the hardware does

Scanning drops an existing connection. On the ESP32 the radio cannot do both, so the widget only ever scans from the picker, never behind a working link - and when you open the picker while already joined, it remembers what you were on and rejoins it if you leave without picking anything. Search again from a working link therefore costs you a few seconds offline, not the network. Forget is the one thing that clears that memory, which is what makes it different from Back.

ADC2 does not work while WiFi is on. On the classic ESP32 that is GPIO 0, 2, 4, 12-15 and 25-27. An analog input on one of those reads garbage once the radio comes up, so the designer refuses the combination and points you at ADC1 - GPIO 32 to 39.

When it fails

Three different things go wrong and each says so, because "failed" on its own sends people to reset a router when they mistyped a key:

In the preview

A browser cannot scan, so preview shows a plausible list and walks the real flow - pick, type, join, succeed, fail - with the same masking and the same failure text. It is the one part of the designer that is a simulation rather than the thing itself, and it is there so the layout and the failure screen get looked at before anything is flashed.