yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ESP32 Core Board📖
1. ESP32 Introduction
  • 1. ESP32S3 Overview
  • 2. Environment Setup Introduction
  • 3. Dev Board Introduction
2. ESP-IDF Development Tutorial
1. Before Development
  • 1. Environment Setup (Windows)
  • 2. Environment Setup (Linux)
  • 3. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. DMA
  • 8. ADC
  • 9. PWM Breathing LED
  • 10. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. PSRAM External Memory Experiment
  • 5. Flash Read and Write Experiment
  • 6. USB Emulated Mass Storage Experiment
4. FreeRTOS operating system
  • 1.FreeRTOS Core Concepts Theory
  • 2.Task Creation and Management
  • 3.Queue
  • 4.Binary Semaphore
  • 5.Mutex
  • 6.Event Groups
  • 7.Software Timer
  • 8.Task Scheduler
  • 9.Low Power Mode
  • 10.Deadlock
  • 11.Priority Inversion
5. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. Socket Programming Basics
  • 9. HTTP Client Experiment
  • 10. HTTP Server Experiment
  • 11. MQTT IoT Communication Protocol
  • 12. WIFI OTA Upgrade
  • 13. Bluetooth Fundamentals
  • 14. Bluetooth Slave Mode
  • 15. Bluetooth Master Mode
6. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
7. Xiaozhi AI Voice
  • 1. Burn Xiaozhi Firmware
  • 2. Network and Configuration
  • 3. AI Agent Settings
  • 4. Program Analysis
  • 5. Free Chat
3. Arduino Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. ADC
  • 8. PWM Breathing LED
  • 9. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication
  • 2. I2C OLED Display
  • 3. SPI Bus Communication
  • 4. Flash Read and Write
  • 5. USB Emulated Mass Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Server Experiment
  • 5. UDP Client Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT IoT Communication Protocol
  • 11. WIFI OTA Upgrade
  • 12. Bluetooth Fundamentals
  • 13. Bluetooth Slave Mode
  • 14. Bluetooth Master Mode
5. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
4. MicroPython Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
  • 3. Thonny IDE
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. TIMER_IT
  • 5. Watchdog Timer
  • 6. ADC
  • 7. PWM Breathing LED
  • 8. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. Flash Read and Write Experiment
  • 5. Print Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT
  • 11. Bluetooth Fundamentals
  • 12. Bluetooth Slave Mode
  • 13. Bluetooth Master Mode
5. Audio Applications
  • 1. I2S Audio Playback Experiment
  • 2. Repeater Experiment
Download
  • Code
  • Hardware_Info
  • 3D_Model_File
  • Software_Tools
  • VMware
  • VM_File
Download ZIP

Welcome to ESP32 Core Board repository

9. HTTP Server Experiment

HTTP Server


HTTP Server1. HTTP Server Overview2. Core Concepts2.1 WebServer Routing Model2.2 HTTP Response Construction3. Hardware Dependencies4. Project Architecture and Flow5. Source Code Analysis5.1 Home Page Route Handler5.2 GET API Route Handler5.3 setup() and loop()6. Operation Flow6.1 Build and Flash6.2 Operation Steps6.3 Serial Monitor Output6.4 Verification Methods7. Common Issues


1. HTTP Server Overview

HTTP (HyperText Transfer Protocol) is the most widely used application layer protocol on the Internet. It is based on TCP and uses a request-response model: the client sends a GET request, and the server returns a status code + data.

The HTTP server runs on the ESP32-S3 and provides web page browsing and API interfaces. This experiment uses the WebServer library for route registration: server.on(path, callback) maps URL paths to handler functions, and server.handleClient() processes the request queue in loop(). Access http://<ESP32_IP>/ in a browser to see the HTML page, and access /get?msg=hello to return an API string.

Typical Application Scenarios:

Application TypeExample
Device Management PanelWeb page to configure Wi-Fi, view sensor data
Simple APIMobile App controls GPIO via HTTP GET
File UploadPOST uploads configuration file to SPIFFS

2. Core Concepts

2.1 WebServer Routing Model

The complete processing chain of a single HTTP request inside ESP32:

Browser/Client                ESP32 WebServer               Callback Function
    │                            │                            │
    │── GET / HTTP/1.1 ─────────→│                            │
    │                            │ accept() → Parse Request    │
    │                            │ Match Route / → handleRoot()│
    │                            │                            │── Execute Callback
    │                            │                            │   Build HTML
    │                            │←── server.send(200, html) ─│
    │                            │  Construct HTTP Response   │
    │←── 200 OK + HTML ──────────│                            │
    │                            │ close() Release Connection │

server.handleClient() is called frequently in loop(), processing one queued request at a time (non-blocking).

xxxxxxxxxx
server.on(path, handler)    // Register route: map URL path to callback function
server.on("/", handleRoot)  // GET / → handleRoot()
server.on("/get", handleGet)// GET /get?msg=xxx → handleGet()
server.begin()              // socket() → bind(80) → listen()
server.handleClient()       // Process next request in queue (non-blocking)
MethodPurposeBlocking?
server.on(path, callback)Register route, call callback when path matches—
server.begin()Bind port 80 and start listeningNo
server.handleClient()Process next HTTP request in queueNo (one at a time)
server.send(code, type, body)Construct and send complete HTTP responseNo
server.arg("key")Read URL query parameter ?key=valueNo

2.2 HTTP Response Construction

server.send(code, mime, body) internally constructs a standard HTTP response message:

xxxxxxxxxx
HTTP/1.1 200 OK\r\n
Content-Type: text/html\r\n
Content-Length: 123\r\n
\r\n
<html><body>...</body></html>

Developers only need to care about three parameters:

ParameterMeaningExample
codeHTTP status code200, 404, 500
mimeContent type (MIME)"text/html", "text/plain", "application/json"
bodyResponse body stringHTML source, JSON string, plain text

3. Hardware Dependencies

Pure software experiment. Must first connect to router via WIFI-STA.


4. Project Architecture and Flow

​x
setup()
  ├─ connectWiFi()
  ├─ server.on("/", handleRoot)        // Register routes
  ├─ server.on("/get", handleGet)
  └─ server.begin()                    // Start listening

loop()
  └─ server.handleClient()             // Process request queue

5. Source Code Analysis

Complete source code: Source code → Arduino → 3.Network Communication → HTTP_Server → HTTP_Server.ino

5.1 Home Page Route Handler

xxxxxxxxxx
#include <WebServer.h>
WebServer server(80);    // Listen on port 80 (HTTP default port)

void handleRoot() {
  String html = "<html><body>";
  html += "<h1>ESP32-S3 HTTP Server</h1>";
  html += "<p>Hello from ESP32</p>";
  html += "</body></html>";
  server.send(200, "text/html", html);
}

5.2 GET API Route Handler

Extract the value of msg from URL query parameters and echo it back.

xxxxxxxxxx
void handleGet() {
  String msg = server.arg("msg");    // Get ?msg=xxx parameter
  server.send(200, "text/plain", "GET OK: " + msg);
}

/get?msg=hello → server.arg("msg") returns "hello". Returns empty string when parameter name does not exist.

5.3 setup() and loop()

xxxxxxxxxx
void setup() {
  Serial.begin(115200);
  connectWiFi();

  server.on("/", handleRoot);
  server.on("/get", handleGet);
  server.begin();

  Serial.printf("HTTP Server started | http://%s/\n", WiFi.localIP().toString().c_str());
}

void loop() {
  server.handleClient();   // Process one HTTP request (non-blocking)
  delay(1);
}

handleClient() processes one client per call (multiple clients queued). Must be called frequently in loop(), otherwise clients will experience "stuttering".


6. Operation Flow

6.1 Build and Flash

Arduino flash process: See Arduino → 1. Before Development → 2. Build and Flash.

  1. Build and flash

  2. Access the IP address printed on serial from PC or mobile browser

6.2 Operation Steps

Step 1: Flash program, record server IP

Build and flash to ESP32-S3 development board. Open serial monitor (baud rate 115200), wait for WiFi connection success, and note down the server address printed on serial:

x
==================================
 HTTP Server Startup successful!
 Access: http://192.168.11.229:80/
==================================

Step 2: Access home page with Postman

Log into Postman on PCServer工具Postman, create a new request, enter the local address http://192.168.11.229:80/

Postman New Request

Request result as shown

GET Request

 

ESP32-S3 HTTP Server Hello from ESP32

Step 3: Test API interface (with parameters)

Enter http://192.168.11.229/get?msg=hello in the browser address bar (replace IP with actual address), press Enter. Browser displays:

GET2

GET OK: hello

Change the parameter after msg= to any string (such as ?msg=world), and the page will display the corresponding value.

Step 4: Test API interface (without parameters)

Enter http://192.168.11.229/get (without parameters) in the browser address bar, press Enter. Browser displays:

GET3

GET OK:

The msg parameter is empty, indicating that server.arg("msg") returns an empty string when no parameter is passed.

6.3 Serial Monitor Output

Serial Output

6.4 Verification Methods

OperationExpected Result
Browser access home pageDisplay HTML page
API access with parametersCorrectly return parameter value
Open multiple browsers simultaneouslyQueued processing, responses one by one

7. Common Issues

SymptomCauseSolution
No response when accessing via browserhandleClient() not called frequently enoughRemove long delay() in loop()
server.arg("msg") returns emptyParameter name misspelled or not passed in URLCheck URL format ?msg=xxx
Chinese characters garbled on pageContent-Type charset not specifiedserver.send(200, "text/html; charset=utf-8", html)
HTTP Client Experiment
MQTT IoT Communication Protocol

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文