Arduino Nano ESP32 - Web Apps Library Reference
Overview
This page documents the full API of the DIYables ESP32 WebApps Library as used on the Arduino Nano ESP32 board. The library follows a modular architecture â each web application is a self-contained class that you register with the server. Only include the page classes your project requires; unused classes do not consume flash or RAM.
The library handles WiFi connection, HTTP serving, and WebSocket communication. Your sketch interacts with it entirely through callbacks and send methods.
Library Capabilities
- Modular page system: Register only the apps you need; each is independent
- Memory controlled: Per-app inclusion means you control flash and RAM usage
- 11 built-in web applications: Ready to use without any web programming
- Extensible base class: Derive from DIYablesWebAppPageBase to build custom pages
- WebSocket-first design: All real-time data exchange uses WebSocket on port 81
- Responsive UI: All built-in pages work on desktop, tablet, and mobile
- Callback-based API: Simple function registration â no polling required
- Concurrent app support: Multiple pages can run simultaneously on one server
Core Classes
DIYablesWebAppServer
The central server class. It manages HTTP routing, WebSocket connections, and dispatches incoming messages to the correct registered page handler.
Constructor
Instantiates the server with the given port numbers.
- httpPort: Port for HTTP requests (default: 80)
- websocketPort: Port for WebSocket connections (default: 81)
Connection Methods
Starts the server assuming WiFi or Ethernet is already configured externally.
- Returns: true on success, false on failure
Connects to WiFi with the provided credentials, then starts the HTTP and WebSocket servers.
- ssid: Network name
- password: Network password
- Returns: true on success, false on failure
Processes pending HTTP requests and WebSocket events. Call this inside loop() on every iteration.
Returns true when the board has an active WiFi connection.
Returns the board's current IP address as a String.
Page Registration
Registers a page instance with the server. The page's URL path is defined in its constructor.
- app: Pointer to a page object
Unregisters the page at the given URL path.
- path: Path string (e.g., "/chat")
Returns a pointer to the registered page at the given path, or nullptr if not found.
Assigns a custom 404 page shown when no registered page matches a request.
Typed Page Accessors
Returns the registered digital pins page, or nullptr if not added.
Returns the registered slider page, or nullptr if not added.
Returns the registered joystick page, or nullptr if not added.
Base Class
DIYablesWebAppPageBase
All built-in and custom page classes extend this abstract base. It provides HTTP response utilities, WebSocket broadcasting, and page lifecycle hooks.
Constructor
Registers the page under the specified URL path.
- pagePath: URL route for this page (e.g., "/web-joystick")
Abstract Methods â Required in Custom Pages
Invoked when a browser requests this page over HTTP.
- client: Interface for writing the HTTP response
Invoked when a WebSocket message arrives and its prefix matches this page.
- ws: The WebSocket connection that sent the message
- message: Raw message content
- length: Byte length of the message
Returns a short label string shown in the Serial Monitor startup output (e.g., "đšī¸ Web Joystick: ").
Returns an HTML fragment for this page's card on the home page.
Optional Override Methods
Called when a new WebSocket client connects. Override to send initial state.
Called when a WebSocket client disconnects.
Utility Methods
Returns this page's registered URL path.
Returns true if this page is active and will respond to requests.
Activates or deactivates the page without removing it from the server.
Writes standard 200 OK HTTP headers to the client.
Sends a message to a single WebSocket connection.
Delivers a message to every currently connected WebSocket client.
Transmits large HTML payloads using chunked transfer encoding.
Custom Page Example
Built-in Page Classes
DIYablesHomePage
Navigation hub listing all registered applications.
Constructor
URL
- /
---
DIYablesWebChatPage
Two-way text messaging between browser and board.
Constructor
URL
- /webchat
Methods
Registers a handler invoked each time the browser sends a chat message.
Pushes a message from the board to the browser chat view.
---
DIYablesWebMonitorPage
Browser-accessible serial monitor for output logging and command input.
Constructor
URL
- /webmonitor
Methods
Registers a handler invoked when the browser sends a command.
Sends a log message from the board to the browser monitor.
---
DIYablesWebDigitalPinsPage
Web interface for reading and writing digital pins 0â13.
Constructor
URL
- /webdigitalpins
Methods
Makes the pin visible and controllable in the web interface.
- pin: Pin number (0â13)
- mode: WEB_PIN_OUTPUT or WEB_PIN_INPUT
Handler called when the browser toggles an output pin. Receives (pin, state).
Handler called when the browser requests an input pin state. Returns the current state.
Handler called when the browser changes a pin's direction.
Pushes an updated pin state to all connected browser clients.
---
DIYablesWebSliderPage
Dual 0â255 range sliders suitable for PWM and analog control.
Constructor
URL
- /webslider
Methods
Handler called when either slider moves. Receives (slider1, slider2) in the range 0â255.
Handler called when a newly connected browser requests the current slider positions.
Pushes slider values to the browser, updating the displayed positions.
---
DIYablesWebJoystickPage
2D virtual joystick returning X/Y coordinates for directional control.
Constructor
- autoReturn: When true, the joystick snaps back to center on release
- sensitivity: Minimum displacement percentage required before an update is sent
URL
- /webjoystick
Methods
Handler invoked on joystick movement. Receives (x, y) each in the range â100 to +100.
Handler called when a browser requests the current joystick position.
Sends the current joystick position to connected browsers.
Updates the auto-center-return behavior at runtime.
Updates the movement sensitivity threshold at runtime.
---
DIYablesWebPlotterPage
Streaming data plotter supporting up to 8 simultaneous data series.
Constructor
URL
- /webplotter
Methods
Sets the chart title displayed above the plot.
Sets the X-axis and Y-axis labels.
When true, the Y-axis range adjusts automatically to incoming data.
Caps the number of data points retained per series before older points are discarded.
Appends a single (x, y) point to the named series.
Removes all data from all series.
---
DIYablesNotFoundPage
Optional 404 response page shown for unregistered routes.
Constructor
Basic Usage
The following sketch demonstrates adding a chat and monitor page to an Arduino Nano ESP32 project:
Web Application URL Reference
| Application | Default URL | |
|---|---|---|
| Home Page | http | //[board-ip]/ |
| Chat | http | //[board-ip]/webchat |
| Web Monitor | http | //[board-ip]/webmonitor |
| Digital Pins | http | //[board-ip]/webdigitalpins |
| Slider | http | //[board-ip]/webslider |
| Joystick | http | //[board-ip]/webjoystick |
| Plotter | http | //[board-ip]/webplotter |
WebSocket Protocol
All real-time communication goes through a single WebSocket server on port 81.
- WebSocket endpoint: ws://[board-ip]:81
- Reconnection: Browsers reconnect automatically on disconnect
- Message format: Text-based; each built-in app uses a unique prefix to identify its messages
Per-App Message Patterns
Chat â plain text in both directions
Monitor â plain text in both directions
Digital Pins
- Browser â Board: {"pin": 13, "state": 1}
- Board â Browser: {"pin": 13, "state": 1}
Slider
- Browser â Board: {"slider1": 128, "slider2": 255}
- Board â Browser: {"slider1": 128, "slider2": 255}
Joystick
- Browser â Board: {"x": 50, "y": -25}
- Board â Browser: {"x": 50, "y": -25}
Plotter
- Browser â Board: not applicable (display only)
- Board â Browser: {"series": "temp", "x": 10.5, "y": 23.4}
Memory Reference
Include only the pages your project uses. Approximate footprint per component:
| Component | Flash | RAM |
|---|---|---|
| DIYablesWebAppServer | ~8 KB | ~2 KB |
| DIYablesHomePage | ~3 KB | ~1 KB |
| DIYablesWebChatPage | ~6 KB | ~1.5 KB |
| DIYablesWebMonitorPage | ~5 KB | ~1.5 KB |
| DIYablesWebDigitalPinsPage | ~8 KB | ~2 KB |
| DIYablesWebSliderPage | ~6 KB | ~1.5 KB |
| DIYablesWebJoystickPage | ~7 KB | ~1.5 KB |
| DIYablesWebPlotterPage | ~10 KB | ~2 KB |
| WebSocket buffer (per client) | â | ~1 KB |
Minimum project (server + home + one app): ~17 KB Flash, ~4.5 KB RAM
All apps enabled: ~53 KB Flash, ~12 KB RAM