DIYables ESP32 Web Server Query String Example
WebServerQueryStrings Example - Dynamic Multi-Page Server
Overview
This example demonstrates how to create a dynamic multi-page web server that uses URL query parameters to provide interactive content and control functionality with seamless page navigation.
Features
- Multi-page navigation with dynamic content based on URL parameters
- Temperature unit conversion (Celsius/Fahrenheit) via query parameters
- LED control with query string parameters
- Dynamic content generation based on user input
- Professional multi-page layout with consistent navigation
- URL parameter parsing and validation
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) |
Library Installation
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) and COM port.
- Open the Library Manager by clicking on the Library Manager icon on the left side of the Arduino IDE.
- Search for Web Server for ESP32 and locate the mWebSockets by DIYables.
- Click on the Install button to add the mWebSockets library.

Web Server Query Strings Example
- On Arduino IDE, Go to File Examples Web Server for ESP32 WebServerQueryStrings example to open the example code
Code Structure
- home.h: Home page HTML template
- temperature.h: Temperature monitoring page template
- led.h: LED control page template
- WebServerQueryStrings.ino: Main server logic
Circuit Connection
No external components required - this example uses the built-in LED on pin 13.
Query Parameter Features
Temperature Page Parameters
- unit=c or unit=celsius - Display temperature in Celsius
- unit=f or unit=fahrenheit - Display temperature in Fahrenheit
- No parameter - Defaults to Celsius
LED Control Parameters
- state=on - Turn LED on
- state=off - Turn LED off
Setup Instructions
1. Network Configuration
Edit the WiFi credentials directly in the WebServerQueryStrings.ino file:
2. Upload Code and Monitor Output
- Connect your ESP32 to your computer
- Select the correct board and port in Arduino IDE
- Upload the WebServerQueryStrings.ino sketch
- Open Serial Monitor (9600 baud)
- Wait for WiFi connection
- Note the IP address displayed
- If you do not see IP address in Serial monitor, press the reset button on the ESP32 board
Usage Examples
Open your web browser and enter the IP address displayed in the Serial Monitor to access the web server.

Test the Temperature Monitoring Function:
- Click on the "Temperature" menu.
- View the temperature display. Click each button to change the temperature unit

Test the LED Control Function:
- Click on the "LED Control" menu. You will see the web interface like the below:

- Toggle the LED ON and OFF using the provided buttons.
- Observe the built-in LED status on the ESP32 board update instantly.
Accessing Different Pages
Home Page
- URL: http://your-esp32-ip/
- Features: Welcome page with navigation menu
Temperature Page (Default - Celsius)
- URL: http://your-esp32-ip/temperature
- Display: Temperature in Celsius with unit selector
Temperature in Fahrenheit
- URL: http://your-esp32-ip/temperature?unit=f
- URL: http://your-esp32-ip/temperature?unit=fahrenheit
- Display: Temperature converted to Fahrenheit
LED Control
- Turn ON: http://your-esp32-ip/led?state=on
- Turn OFF: http://your-esp32-ip/led?state=off
Code Explanation
Query Parameter Processing
LED Control with Query Parameters
Parameter Validation
HTML Templates with Dynamic Content
Temperature Page Template
LED Control Template
Advanced Features
Route Configuration
Query Parameter Helper Functions
URL Building Helpers
Real Implementation Notes
Current Limitations
The actual implementation is simplified compared to a full-featured web server:
- Only supports single parameter extraction per handler
- Simple string-based temperature simulation (no unit conversion)
- Basic LED control with on/off states only
- Uses pin 9 instead of the standard pin 13
Troubleshooting
Common Issues
Parameters Not Working
- Check URL format: page?param=value
- Verify parameter names match exactly (case-sensitive)
- Current implementation uses state for LED, not action
LED Pin Issues
- This example uses pin 9, not pin 13
- Verify LED_PIN constant matches your hardware
Query Parameter Access
- Use QueryParams structure, not server.arg()
- Loop through params.params[i] to find specific parameters
Debug Output
Customization
Adding New Handler with Parameters
Template System Enhancement
The actual implementation uses simple placeholder replacement:
Next Steps
- Explore WebServerJson.ino for REST API development
- Try WebServerWithWebSocket.ino for real-time communication
- Implement form handling with POST parameters