Arduino Nano ESP32 - Web Apps Custom WebApp
Overview
The CustomWebApp example in the DIYables ESP32 WebApps Library provides a starting template for building browser-based interfaces that integrate with the existing DIYables web apps ecosystem on the Arduino Nano ESP32. The template establishes two-way WebSocket communication between a browser and the board: the browser can send text commands to the board, and the board can push data back to the browser at any time.
The example consists of four files that must be kept together in the same sketch folder:
- CustomWebApp.ino — main sketch with application logic
- CustomWebApp.h — header defining the page class interface
- CustomWebApp.cpp — class implementation and WebSocket message routing
- custom_page_html.h — embedded HTML, CSS, and JavaScript for the browser page

What This Tutorial Covers
- Running the default custom app template on Arduino Nano ESP32
- Understanding the app identifier system that isolates messages between multiple apps
- Modifying the template to handle custom hardware commands
- Sending sensor data to the browser at runtime
- Customizing the HTML, CSS, and JavaScript of the embedded web page
- Managing multiple custom apps in one project without message conflicts
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Steps
Follow these instructions step by step:
- If this is your first time using the Arduino Nano ESP32, refer to the tutorial on setting up the Arduino Nano ESP32 development environment.
- Connect the Arduino Nano ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate board (e.g. Arduino Nano ESP32) and COM port.
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search "DIYables ESP32 WebApps", then find the DIYables ESP32 WebApps Library by DIYables
- Click Install button to install the library.
- Search for DIYables ESP32 WebApps created by DIYables and click the Install button.
- You will be asked for installing some other library dependencies
- Click Install All button to install all library dependencies.
- In the Arduino IDE, go to File Examples DIYables ESP32 WebApps CustomWebApp. The IDE opens four files: CustomWebApp.ino, CustomWebApp.h, CustomWebApp.cpp, and custom_page_html.h.
- Update the WiFi credentials in CustomWebApp.ino:
- Click Upload button on Arduino IDE to upload code to Arduino Nano ESP32
- Open the Serial Monitor
- The Serial Monitor output should resemble the following:
- If nothing appears, press the reset button on the board.
- Enter the IP address from the Serial Monitor into a browser on the same network.
- Example: http://192.168.0.2
- The home page shows a card for the custom application:

- Select the Custom WebApp card to open the page:

- The page is also directly accessible at http://192.168.0.2/custom.
Verifying the Default Template
The default template demonstrates basic two-way communication:
- Type any text into the input field on the page and click Send. The board receives the message and echoes it back. The web page displays: Echo: <your message>
- The board sends an uptime message to all connected browsers every 5 seconds: Arduino uptime: X seconds
- All received messages are printed in the Serial Monitor.
App Identifier System
The library allows multiple web apps to share one WebSocket server on port 81. Each app is isolated by a short prefix string called the app identifier. The identifier is prepended to every message in both directions.
Board side (CustomWebApp.h / CustomWebApp.cpp)
Browser side (custom_page_html.h)
The identifier value in the .cpp file and the .h file must match exactly. When creating additional custom apps, assign a distinct identifier to each one.
Reserved identifiers — the following are already used by built-in apps and must not be reused:
- App identifiers: CHAT:, MONITOR:, PLOTTER:, DIGITAL_PINS:, JOYSTICK:, SLIDER:, TABLE:, RTC:, ROTATOR:, GAUGE:
- Sub-protocol identifiers: TIME:, DATETIME:, JOYSTICK_CONFIG:, PLOTTER_DATA:, PLOTTER_CONFIG:, SLIDER_VALUES:, TABLE_CONFIG:, TABLE_DATA:, VALUE_UPDATE:, PIN_CONFIG:, PIN_STATES:, PIN_UPDATE:
Adapting the Template
Handling Hardware Commands
Extend the callback in CustomWebApp.ino to respond to specific commands:
Sending Sensor Data from the Loop
Customizing the Web Page (HTML)
Edit custom_page_html.h to add buttons and display elements:
Customizing Message Processing (JavaScript)
Update ws.onmessage in custom_page_html.h to parse specific fields:
Customizing the URL Path
Change the path where the page is served by modifying the constructor in CustomWebApp.cpp:
The path must start with / and must not duplicate paths used by built-in apps (/chat, /monitor, /plotter, /web-digital-pins, /web-joystick, /web-slider, /web-table, /web-rtc, /web-rotator, /web-gauge).
Managing Multiple Custom Apps
When adding more than one custom page, each must have a unique identifier, a unique path, and a unique class name.
File Structure
Registering Multiple Apps
Unique Identifiers per App
The matching JavaScript constants in each *_page_html.h file must use the same string values.