embedded_webui
Section titled “embedded_webui”Overview
Section titled “Overview”The embedded_webui module (embedded/) is the minimal built-in web page served directly from the ESP32 flash by the http_service. It provides a zero-install fallback interface — terminal console, file browser, and firmware/resources update — when the full ESP3D-WEBUI 3.0 package is not installed on the device.
It is a plain JavaScript/webpack project (no framework) deliberately kept tiny: the production build produces a single gzipped index.html that must stay under 15 KB, works fully offline, and loads no external assets. Current page version: 3.0.0.a6.
Parent module: Network_&_Web_Services — the page is served by the firmware HTTP server from
main/embedded/index.html.gzand consumes its REST/WebSocket endpoints.
Architecture Overview
Section titled “Architecture Overview”Source Layout
Section titled “Source Layout”| Path | Role |
|---|---|
embedded/src/index.html | HTML shell — panels, login modal, element IDs used by the JS |
embedded/src/index.js | All runtime behavior (987 lines, bundled by webpack) |
embedded/src/menu.js | Top-menu external links (firmware repo, WebUI repo, wiki) |
embedded/src/style.css | Styles, extracted and inlined at build time |
embedded/config/webpack.prod.js | Production build → single inlined HTML → dist/index.html.gz |
embedded/config/webpack.dev.js | Dev server config (npm run dev) |
embedded/config/server.js | Local dev backend (express + express-ws, mocks the firmware API) |
embedded/config/buildassets.js | Post-build: gzips favicon, copies index.html.gz into main/embedded/ |
embedded/tools/format_sources.py | Source formatting helper |
Boot Sequence ([ESP800] discovery)
Section titled “Boot Sequence ([ESP800] discovery)”window.onloadwires all event listeners, then callsgetFWData().getFWData()issuesGET /command?cmd=[ESP800]json=YES version=3.0.0.a6 time=<PC time>.processFWJson()validates the{status, cmd, data}envelope, then configures the UI fromjson.data:Authentication == "Enabled"→ show login linkFWVersion→ version label (click opens/config)FlashFileSystem/SDConnection→ show file panel (falls back to/sdfileswhen no flash FS)WebUpdate→ show firmware update panel;WebUpdateResources→ show the UI-resources target selectorHostPath,Hostname(→document.title),RadioMode(captive-portal detection → “limited environment” warning)
- WebSocket bootstrap (see below), then
SendFileCommand("list", "all")populates the file browser.
Feature Areas
Section titled “Feature Areas”Terminal console
Section titled “Terminal console”- Collapsible panel; input
GET /command?cmd=<text>; response rendered viaprocessCmdJson(JSON pretty-printed, raw text otherwise;ESP3D says: command forwardedis filtered out). - Ring buffer of the last 300 lines, optional auto-scroll.
File browser
Section titled “File browser”- Endpoint:
GET <fspath>?action=<list|delete|createdir|deletedir>&filename=...&path=...wherefspathis/files(flash) or/sdfiles(SD fallback). - Renders status bar (total/used/occupation meter), directories (size
-1) then files, sorted case-insensitively; navigation viacurrentPath, “Up..” entry, per-item delete with confirm. - Clicking a file opens it in a new tab. If
index.html(.gz)is detected atHostPath, the WebUI link is revealed (gateway to the full ESP3D-WEBUI). - Multi-file upload:
POST <fspath>withFormData— each file is preceded by a<path><name>Sfield carrying its size so the firmware can verify completeness; progress bar viaupload.progress.
Firmware & UI-resources update
Section titled “Firmware & UI-resources update”POST /updatefw(firmware OTA) orPOST /updatefw?partition=ui_resources(resources partition), with the same size-prefixFormDatacontract.- Firmware success → countdown (40 s) then page reload; resources success → “Please restart device”.
Authentication
Section titled “Authentication”- Modal login:
POST /loginwithUSER/PASSWORD/SUBMIT=yesform fields; HTTP 401 anywhere triggershandle401()(re-shows modal, hides all panels). See authentication.
WebSocket channel
Section titled “WebSocket channel”- Asynchronous mode (default):
ws(s)://<same host>/ws, sub-protocolwebui-v3— handled by websocket_server. - Synchronous (legacy) mode:
ws://<WebSocketIP>:<WebSocketPort>from the[ESP800]fields. - Binary frames are decoded to text and appended to the console; text control messages:
currentID(session id),activeID(kicks the page if another client took over),ERROR(aborts an ongoing upload). - Unclean close / error →
finalizeServerDisconnect()(hides UI, marks title “(disconnected)”); clean close → reconnect attempt after 3 s.
Captive-portal detection
Section titled “Captive-portal detection”isLimitedEnvironment() checks the page host against known connectivity-check domains (Android/Apple/Microsoft) when RadioMode == "AP" and warns the user to browse the board’s real IP instead.
Build Pipeline
Section titled “Build Pipeline”npm run build # = npm run pack && npm run convert-assetspack— webpack production: Babel (preset-env+ core-js), CSS extraction,HtmlWebpackPlugin+ inline script/css plugins → one HTML file, minified, thenCompressionPlugin→dist/index.html.gz.convert-assets—buildassets.jsgzips the favicon and copiesindex.html.gztomain/embedded/index.html.gz, where the firmware HTTP server picks it up.
Development: npm run dev runs webpack-dev-server plus the express mock backend (config/server.js).
Dependencies
Section titled “Dependencies”| Consumes | Provided by |
|---|---|
[ESP800] JSON capabilities, /command | esp3d_commands, gcode_host |
| HTTP server, static file serving | http_service |
/ws asynchronous WebSocket | websocket_server |
/login, 401 flow | authentication |
/files, /sdfiles actions | filesystem |
/updatefw OTA + resources partition | update_service |
Related Design Documents (repository)
Section titled “Related Design Documents (repository)”- Embedded WebUI — function inventory
- Embedded WebUI — build flow and JSON/API contract
- Embedded WebUI — rewrite risks and anti-patterns
- docs/embedded README