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

10. HTTP Server Experiment

HTTP Server Experiment


HTTP Server Experiment1. HTTP Overview2. Core Concepts2.1 HTTP Request-Response Model2.2 HTTP Methods2.3 HTTP Status Codes2.4 esp_http_client Event-Driven Model3. Project Architecture and Flow3.1 HTTP Server3.3 Server Routing Table4. Hardware Dependencies5. Source Code Analysis — HTTP Server5.1 Route Handlers5.2 start_http_server() — Start Server6. Operation Flow6.1 Build and Flash Flow6.2 Testing HTTP Server6.3 Normal Log — HTTP Server7. Common Problems


1. HTTP Overview

HTTP is the "passport" for IoT devices to integrate into the Web ecosystem—mastering HTTP communication allows ESP32 to access any API on the internet like a browser, and also turn itself into a Web server for direct device control via webpages from phones or computers. Whether doing remote sensor data reporting, weather fetching, OTA firmware upgrades, or building smart home web control panels, HTTP is the most versatile choice. This tutorial covers the server RESTful API routine, teaching core HTTP communication skills on ESP32.

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: client sends GET request, server returns status code + data.

FeatureHTTPBare TCP/UDP
Protocol layerApplication layer (based on TCP)Transport layer
Data formatStandard Headers + BodyCustom
Status code200/404/500 etc. standard semanticsNone
Cross-platform compatibilityBrowser/curl/HTTP libraries for all languagesNeed custom parsing
Applicable scenariosWeb API, file download, RESTfulCustom protocols, extreme performance scenarios

This project contains both HTTP client and server routines: the client gets webpage data via GET request; the server provides RESTful API on port 80.


2. Core Concepts

2.1 HTTP Request-Response Model

┌─── HTTP Client (ESP32) ────────────┐    ┌─── HTTP Server ───────────────────┐
│                                   │    │                                  │
│  GET /index.html HTTP/1.1         │───→│  Parse request → route to handler │
│  Host: example.com                │    │  ↓                                │
│                                   │    │  Execute handler logic            │
│                                   │    │  ↓                                │
│  HTTP/1.1 200 OK                 │←───│  Return status code + Headers + Body│
│  Content-Type: text/html          │    │                                  │
│  Content-Length: 125             │    │                                  │
│                                   │    │                                  │
│  <html>...</html>                │    │                                  │
└───────────────────────────────────┘    └──────────────────────────────────┘

2.2 HTTP Methods

MethodSemanticsRequest BodyTypical Use
GETGet resourceNoneQuery data, get webpage

2.3 HTTP Status Codes

Status CodeSemanticsDescription
200OKRequest successful
206Partial ContentRange request for partial content (OTA firmware download)
301Moved PermanentlyPermanent redirect
404Not FoundRequested resource does not exist
500Internal Server ErrorServer internal error

2.4 esp_http_client Event-Driven Model

ESP-IDF's HTTP client uses event callback mechanism. Key events:

EventTriggerCallback Parameters
HTTP_EVENT_ON_CONNECTEDTCP connection established—
HTTP_EVENT_ON_DATAResponse data chunk receiveddata + data_len
HTTP_EVENT_ON_FINISHRequest completed—
HTTP_EVENT_ERRORRequest error—

3. Project Architecture and Flow

3.1 HTTP Server

xxxxxxxxxx
app_main()
  └─ xTaskCreate(vHttpServerTask, stack=8KB, prio=5)
      └─ vHttpServerTask():
          ├─ wifi_init()                      ← WiFi connect + wait for IP
          ├─ start_http_server()
          │   ├─ httpd_start(port 80)         ← Start HTTP server
          │   ├─ Register GET  "/"       → root_handler
          │   └─ Register GET  "/get"    → get_handler
          └─ while(1) vTaskDelay(1000ms)      ← Keep running

3.3 Server Routing Table

Routing determines "access which path → execute which function → return what content":

  • GET / → call root_handler, return {"msg":"ESP32 HTTP Server is running!"}

  • GET /get → call get_handler, return {"status":"ok","msg":"hello from esp32 http server"}

Both have Content-Type application/json.


4. Hardware Dependencies

  • Hardware Connection: No external wiring, WiFi wireless communication

  • Client required components: esp_http_client, esp_wifi, esp_netif, esp_event, nvs_flash

  • Server required components: esp_http_server (instead of esp_http_client), others same as above


5. Source Code Analysis — HTTP Server

Full source: Source Code → ESP-IDF → 5.Network_Protocol → 6.HTTP → HTTP_Server

5.1 Route Handlers

The most core concept of HTTP server is routing—client (browser/Postman) accesses different paths, ESP32 returns different content. Each route is a function that writes response to req. httpd_resp_set_type() sets Content-Type (set "application/json" for returning JSON, "text/html" for webpages), httpd_resp_send() sends the content out.

xxxxxxxxxx
static esp_err_t root_handler(httpd_req_t *req)
{
    char resp[] = "{\"msg\":\"ESP32 HTTP Server is running!\"}";
    httpd_resp_set_type(req, "application/json");
    httpd_resp_send(req, resp, strlen(resp));
    ESP_LOGI(TAG, "Root / Request processed successfully");
    return ESP_OK;
}
static esp_err_t get_handler(httpd_req_t *req)
{
    char resp[] = "{\"status\":\"ok\", \"msg\":\"hello from esp32 http server\"}";
    httpd_resp_set_type(req, "application/json");
    httpd_resp_send(req, resp, strlen(resp));
    ESP_LOGI(TAG, "GET Request processed successfully");
    return ESP_OK;
}

5.2 start_http_server() — Start Server

start_http_server() starts an HTTP server, then hangs routes one by one using httpd_register_uri_handler(). Each httpd_uri_t specifies three things: path (.uri), HTTP method (.method), handler function (.handler). Client accessing http://ESP32_IP/ calls root_handler, accessing /get calls get_handler.

​x
static void start_http_server(void)
{
    httpd_config_t config = HTTPD_DEFAULT_CONFIG();
    httpd_handle_t server = NULL;

    if (httpd_start(&server, &config) != ESP_OK) {
        ESP_LOGE(TAG, "Failed to start HTTP server!");
        return;
    }
    ESP_LOGI(TAG, "HTTP server started, port: 80");

    httpd_uri_t root_uri = {
        .uri      = "/",
        .method   = HTTP_GET,
        .handler  = root_handler,
        .user_ctx = NULL,
    };
    httpd_register_uri_handler(server, &root_uri);

    httpd_uri_t get_uri = {
        .uri      = "/get",
        .method   = HTTP_GET,
        .handler  = get_handler,
        .user_ctx = NULL,
    };
    httpd_register_uri_handler(server, &get_uri);
}

6. Operation Flow

6.1 Build and Flash Flow

ESP-IDF Flash Flow: See ESP-IDF → 1. Before Development → 3. Build and Flash.

6.2 Testing HTTP Server

  1. Flash HTTP_Server to ESP32. Note the IP address printed on serial (e.g. 192.168.11.100).

  2. Open Postman, create GET request, URL input http://192.168.11.100/ → returns {"msg":"ESP32 HTTP Server is running!"}

  3. Same method, GET request http://192.168.11.100/get → returns {"status":"ok","msg":"hello from esp32 http server"}

6.3 Normal Log — HTTP Server

xxxxxxxxxx
I (3856) HTTP-SERVER: ========== HTTP SERVER ==========
I (3858) HTTP-SERVER: Waiting for WiFi connection...
I (3872) HTTP-SERVER: Got IP: 192.168.11.100
I (3874) HTTP-SERVER: WiFi connected successfully!
I (3876) HTTP-SERVER: HTTP server started, port: 80
I (5000) HTTP-SERVER: Root / Request processed successfully
I (6000) HTTP-SERVER: GET Request processed successfully

Server Serial Output

Use Postman to test, create GET request, URL fill ESP32's IP and port:

  • GET http://<ESP32_IP>/ → returns {"msg":"ESP32 HTTP Server is running!"}

  • GET http://<ESP32_IP>/get → returns {"status":"ok","msg":"hello from esp32 http server"}

Postman GET / Request

编写GET申请,写当前IP适配端口


7. Common Problems

SymptomCauseSolution
HTTP client HTTP request errorURL unreachable or DNS resolution failedEnsure ESP32 can access external network; or use IP address instead of domain name
esp_http_client_init() returns NULLURL format errorCheck HTTP_URL starts with http://
Postman/browser accessing ESP32 no responseNot on same LAN / firewall blockedEnsure PC and ESP32 are on same router
httpd_start() failedPort 80 in useUse port like 8080
Content-Type incorrect causing client parsing failurehttpd_resp_set_type() not calledMust set "application/json" when returning JSON
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/中文