|
NetBurner 3.5.8
PDF Version |
Example Path: examples/Wifi/ESP32/WifiWebUI
Most ESP32-C5 examples send the user to the library's built-in provisioning page at /wifi. This example shows how to build your OWN application web interface for WiFi setup instead, driven entirely by the public ESP32C5 API (g_wifi).
The application serves its own page (html/index.html) and registers its own AJAX endpoints under the /api/app/ prefix (src/webui.cpp): scan for networks, set the station (STA) credentials, push them to the radio, and report live connection status.
The library's /wifi page and its /api/wifi/ JSON handlers are auto-registered inside g_wifi.Init() and remain fully available. This example does not (and cannot, without forking the library) remove them – it demonstrates an app-owned UI living alongside them. The app page links to the built-in page from its "Built-in Provisioning" card.
Served by webui.cpp, under /api/app/ so they never collide with the library's /api/wifi/ handlers:
| Method | URL | Purpose |
|---|---|---|
| GET | /api/app/status | JSON: hardware + STA + AP state (polled live) |
| POST | /api/app/scan | Start a scan; replies {"ok":true} |
| GET | /api/app/scan | JSON: {"scanning":bool,"count":N,"networks":[...]} |
| POST | /api/app/connect | Form vars ssid + pass: store, push to the ESP32, reply {"ok":true} |
These use NetBurner's standard web-handler classes: CallBackFunctionPageHandler for the GET/POST JSON endpoints, and HtmlPostVariableListCallback for the connect form. SSIDs read off the air are JSON-escaped before being echoed back to the page.
Reach the device over wired Ethernet, or over the provisioning AP (default SSID NetBurnerC5Wifi, 5 GHz). On SOMRT1061, holding the IRQ button (pin 30 low) at boot forces the AP on, so the UI is always reachable even with bad stored credentials.
The application prints a menu on the serial debug port (115200 baud):
| Key | Function |
|---|---|
| N | Start a WiFi scan |
| R | Show last scan results |
| I | Show interface info (STA/AP state, IPs) |
| A | Turn AP mode on |
| a | Turn AP mode off |
Press any other key to reprint the menu.
The example serves its UI from html/index.html, styled with the shared NetBurner SDK example look – a self-contained stylesheet, no framework or CDN. The page polls /api/app/status, drives a scan, and submits credentials, all via fetch().
Adding a new host platform is a small port – see platform/esp32_c5_wifi_mod/Porting_To_New_Platforms.md.