DIYables ESP32 Web Apps Chat
Overview
The WebChat example demonstrates how to create an interactive chat interface between a web browser and Arduino. Designed for ESP32 educational platform with enhanced IoT capabilities and seamless integration with built-in sensors. The ESP32 can respond intelligently to messages and control hardware based on chat commands.

Features
- Real-time Chat: Instant messaging via WebSocket
- Intelligent Responses: ESP32 provides contextual replies
- LED Control: Control built-in LED via chat commands
- User Recognition: ESP32 remembers your name
- Message History: View conversation history
- Responsive Design: Works on desktop and mobile
Hardware Used In This Tutorial
Or you can buy the following kits:
1 | × | DIYables ESP32 Starter Kit (ESP32 included) | |
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Setup Instructions
Quick Instructions
Follow these instructions step by step:
- If this is your first time using the ESP32, refer to the tutorial on setting up the environment for ESP32 in the Arduino IDE.
- Connect the ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate ESP32 board (e.g. ESP32 Dev Module) 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.

- You will be asked for installing some other library dependencies
- Click Install All button to install all library dependencies.

- On Arduino IDE, Go to File Examples DIYables ESP32 WebApps WebChat example, or copy the above code and paste it to the editor of Arduino IDE
- Configure WiFi credentials in the code by updating these lines:
- Click Upload button on Arduino IDE to upload code to ESP32
- Open the Serial Monitor
- Check out the result on Serial Monitor. It looks like the below
- If you do not see anything, reboot ESP32 board.
- Take note of the IP address displayed, and enter this address into the address bar of a web browser on your smartphone or PC.
- Example: http://192.168.0.2
- You will see the home page like below image:

- Click to the Chat link, you will see the Web Chat app's UI like the below:

- Or you can also access the page directly by IP address followed by /chat. For example: http://192.168.0.2/chat
- Start chatting with your Arduino! Type your name when prompted and try commands like "led on", "hello", or "help" to interact with your Arduino.
How to Use
Starting a Conversation
- Open the chat interface in your browser
- Type your name when prompted
- Start chatting with your Arduino!
Chat Commands
The ESP32 recognizes these special commands:
LED Control
- "led on" or "turn on led" → Turns on built-in LED
- "led off" or "turn off led" → Turns off built-in LED
- "blink" or "blink led" → Makes LED blink
Information Commands
- "hello" or "hi" → Friendly greeting
- "help" → Shows available commands
- "time" → Shows ESP32 uptime
- "status" → Shows system status
Questions
- "how are you?" → ESP32 shares its status
- "what can you do?" → Lists capabilities
- "what is your name?" → ESP32 introduces itself
Example Conversation
Creative Customization - Build Your Interactive Assistant
Transform this basic chat example into something amazing! The modular design allows you to adapt and expand the functionality to create your own unique interactive ESP32 assistant.
Code Structure
Main Components
- WebApp Server: Manages HTTP and WebSocket connections
- Chat Page: Provides the web interface
- Message Handler: Processes incoming chat messages
- Response Generator: Creates intelligent replies
Key Functions
Adding Custom Commands
To add new chat commands, modify the handleChatMessage function:
Customization Options
Modify ESP32 Personality
Edit the response messages to change Arduino's personality:
Add Hardware Control
Extend LED control to other components:
Change Web Interface Theme
The chat interface can be customized by modifying CSS in the library files:
- Colors: Edit gradient backgrounds
- Fonts: Change font families
- Layout: Adjust spacing and sizing
Troubleshooting
Common Issues
1. ESP32 not responding to messages
- Check Serial Monitor for error messages
- Verify WebSocket connection status
- Refresh the browser page
2. WiFi connection failed
- Double-check SSID and password
- Ensure 2.4GHz network (not 5GHz)
- Check signal strength
3. Can't access chat page
- Verify IP address is correct
- Check if ESP32 is still connected to WiFi
- Try accessing home page first: http://[IP]/
4. LED not responding to commands
- Check wiring (built-in LED should work by default)
- Verify commands are spelled correctly
- Check Serial Monitor for debug messages
Debug Tips
Enable debug mode by adding this line in setup():
Monitor Serial output to see:
- Incoming messages
- Command parsing
- Response generation
- Hardware actions
Advanced Features
Multiple Client Support
The chat supports multiple users simultaneously:
- Each user has a unique session
- ESP32 remembers individual names
- Broadcast messages to all users
Message Persistence
Add message logging to EEPROM:
Integration with Sensors
Connect sensors and make them accessible via chat:
Next Steps
After mastering the Chat example, try:
- WebMonitor - For debugging and development
- DigitalPins - For controlling multiple outputs
- Joystick - For directional control
- MultipleWebApps - Combining all features
Support
For additional help:
- Check the API Reference documentation
- Visit DIYables tutorials: https://esp32io.com/tutorials/diyables-esp32-webapps
- ESP32 community forums