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

8. HTTP Client Experiment

HTTP Client Experiment


HTTP Client Experiment1. HTTP Client Overview2. Core Concepts2.1 HTTP Request Format2.2 HTTP Response Format2.3 Configuration Parameters3. Hardware Dependencies4. Project Architecture and Flow5. Source Code Explained5.1 Main Program6. Operating Procedures6.1 Flashing and Running6.2 Serial Output Example6.3 Verification Methods7. Common Problems


1. HTTP Client 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. In this experiment the ESP32-S3 acts as an HTTP client, constructing and sending a GET request to the public server example.com using a pure socket, verifying network reachability.

Typical application scenarios:

Application TypeExample
API callsReport sensor data to a cloud platform REST API
Weather fetchingRequest a weather API to get real-time weather
OTA firmwareDownload firmware update files
WebhookTrigger IFTTT / DingTalk robot notifications

2. Core Concepts

2.1 HTTP Request Format

GET / HTTP/1.1\r\n
Host: example.com\r\n
Connection: close\r\n
\r\n

Request line + headers + blank line, three parts separated by \r\n.

2.2 HTTP Response Format

xxxxxxxxxx
HTTP/1.1 200 OK\r\n           <- status line
Content-Type: text/html\r\n      <- headers
\r\n
<html>...</html>                <- response body

2.3 Configuration Parameters

ParameterDescriptionValue Used in This Experiment
HOSTTarget serverexample.com
PORTHTTP port80

3. Hardware Dependencies

The ESP32-S3 has built-in WiFi and needs access to the public Internet (example.com).


4. Project Architecture and Flow

xxxxxxxxxx
Script execution (single-file .py)
  |
  |- wifi_connect(): connect to WiFi (STA mode)
  |
  |- GET / -> DNS resolution -> TCP connection -> send request -> receive response -> print -> end

5. Source Code Explained

Full source code: Source Code -> MicroPython -> 4.Network Protocols -> HTTP_Client -> HTTP_Client.py

5.1 Main Program

getaddrinfo resolves the domain -> connect establishes a TCP connection -> build the HTTP request headers -> sendall sends -> loop recv to receive the response until the connection closes. After one execution it exits.

​x
def main():
    wifi_connect(WIFI_SSID, WIFI_PASS)   # connect to WiFi
​
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # TCP socket
    sock.settimeout(10)                  # 10s timeout
​
    ip = socket.getaddrinfo(HOST, PORT)[0][4][0] # DNS resolve
    sock.connect((ip, PORT))             # connect
​
    req = f"GET / HTTP/1.1\r\nHost: {HOST}\r\nConnection: close\r\n\r\n"  # request line + headers
    sock.sendall(req.encode("utf-8"))    # send
​
    resp = b""
    while True:
        chunk = sock.recv(512)           # receive
        if not chunk:                    # closed
            break
        resp += chunk
    sock.close()                         # close
​
    text = resp.decode("utf-8")
    _, _, body_text = text.partition("\r\n\r\n")# split body
    status = int(text.split(" ")[1]) if " " in text else 0  # status code
​
    print(f"[HTTP] <<< {status}  {len(resp)}B")
    print(body_text[:800])              # first 800 chars

6. Operating Procedures

6.1 Flashing and Running

Thonny IDE steps: See MicroPython -> 1. Before Development -> 3.Thonny IDE.

  1. Modify WIFI_SSID / WIFI_PASS

    WiFi、端口设置

  2. Run HTTP_Client.py; it exits after performing one GET

6.2 Serial Output Example

xxxxxxxxxx
===== ESP32-S3 HTTP Client =====
[WiFi] Already connected. IP: 192.168.11.229
GET http://example.com/
​
[HTTP] >>> GET /
[HTTP] <<< 200  869B
22f
<!doctype html><html lang="en"><head><title>Example Domain</title><link rel="icon" href="data:,"><meta name="viewport" content="width=device-width, initial-scale=1"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}</style></head><body><div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.</p><p><a href="https://iana.org/domains/example">Learn more</a></p></div></body></html>

串口打印

The HTML content printed in the middle of the serial output is the HTML returned by http://example.com. You can visit this URL in a browser, right-click -> View Page Source (or Ctrl+U), and compare it with the serial output: if they match, the GET request succeeded.

网站网页

查看页面源代码

Client源代码页面

6.3 Verification Methods

OperationExpected Result
Run the scriptPrints one GET response with status code 200

7. Common Problems

SymptomCauseSolution
getaddrinfo failsDNS cannot resolveCheck whether the WiFi connection was successful
Status code is not 200Malformed requestCheck the HTTP header format (\r\n separated)
Response body truncatedrecv() loop exits earlyEnsure while True until chunk == b""
TCP Server Experiment
HTTP Server Experiment

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/中文