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

2. WIFI STA Mode

WIFI-STA Mode


WIFI-STA Mode1. WIFI-STA Mode Overview2. Core Concepts2.1 Wi-Fi Connection Process2.2 Connection Status Codes2.3 Reconnection Algorithm with Timeout3. Hardware Dependencies4. Project Architecture and Flow5. Source Code Details5.1 Configuration Section5.2 connectWiFi() — Connection Algorithm with Timeout5.3 setup() — Startup Entry Point6. Operation Flow6.1 Build and Flash6.2 Expected Behavior6.3 Verification Methods7. Common Issues


1. WIFI-STA Mode Overview

In STA (Station) mode, ESP32-S3 acts as a Wi-Fi client to connect to an existing router or hotspot. After obtaining an IP address, it can access the internet. This experiment demonstrates a Wi-Fi connection algorithm with timeout detection and automatic retry, which serves as the foundation for all subsequent network experiments (UDP/TCP/HTTP/MQTT).

Typical Application Scenarios:

Application TypeExample
IoT DevicesSmart outlets, sensor nodes connecting to the internet via router
Data ReportingTemperature and humidity sensors periodically pushing data to cloud platform
Remote ControlMobile app controlling ESP32 peripherals through cloud
OTA UpdatesDownloading new firmware from HTTP server

2. Core Concepts

2.1 Wi-Fi Connection Process

WiFi.begin(ssid, pass) initiates an 802.11 connection, with the underlying steps: scanning target AP → Authentication → Association → WPA2 four-way handshake to establish encrypted link → DHCP to obtain IP address.

2.2 Connection Status Codes

WiFi.status() return values:

Status CodeMeaning
WL_CONNECTED (3)Connected and IP obtained
WL_DISCONNECTED (6)Not associated with any AP
WL_CONNECTION_LOST (5)Link lost after association
WL_CONNECT_FAILED (4)Wrong password or authentication failed
WL_NO_SSID_AVAIL (1)Target SSID not found during scan

2.3 Reconnection Algorithm with Timeout

In environments with poor signal, WiFi.begin() may block for a long time. This experiment uses millis() to implement a 10-second timeout timer. After timeout, it waits 15 seconds before retrying to avoid overwhelming the router with frequent requests.


3. Hardware Dependencies

Pure software experiment. ESP32-S3 has a built-in 2.4GHz Wi-Fi transceiver, supporting 802.11 b/g/n (Wi-Fi 4).


4. Project Architecture and Flow

​x
setup()
  ├─ Serial.begin(115200)
  ├─ WiFi.mode(WIFI_STA)       // Set to pure STA mode
  └─ connectWiFi()             // Connect to router (with timeout retry)

connectWiFi() Algorithm:
  while(true):
    WiFi.disconnect(true)      // Disconnect and clear credentials stored in NVS
    WiFi.begin(SSID, PASS)     // Initiate 802.11 connection
    while(status != CONNECTED && not timeout):
      delay(500)
    If connected → Print IP → return
    If timeout → delay(15000) → retry

5. Source Code Details

Source code: Source code → Arduino → 3.Network Communication → WIFI_STA → WIFI_STA.ino

5.1 Configuration Section

xxxxxxxxxx
#include <WiFi.h>
const char* WIFI_SSID = "Yahboom2";
const char* WIFI_PASS = "yahboom890729";

5.2 connectWiFi() — Connection Algorithm with Timeout

xxxxxxxxxx
void connectWiFi() {
  const int TIMEOUT_MS = 10000;  // 10 second timeout

  int attempt = 0;
  while (true) {
    attempt++;
    Serial.printf("Connecting to WiFi: %s (Attempt %d)\n", WIFI_SSID, attempt);

    WiFi.disconnect(true);   // true = also clear WiFi credentials saved in NVS
    delay(500);
    WiFi.begin(WIFI_SSID, WIFI_PASS);

    unsigned long startTime = millis();
    while (WiFi.status() != WL_CONNECTED && (millis() - startTime) < TIMEOUT_MS) {
      delay(500);
      Serial.print(".");
    }

    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("\nWiFi Connection succeeded!");
      Serial.print("Device IP: ");
      Serial.println(WiFi.localIP());
      return;
    }

    Serial.println("\nWiFi Connection timed out! Retrying in 15s...");
    delay(15000);
  }
}

The true parameter in WiFi.disconnect(true) also erases credentials stored in NVS, ensuring each retry starts from a clean state. WiFi.localIP() returns the IPv4 address assigned by the DHCP server.

5.3 setup() — Startup Entry Point

xxxxxxxxxx
void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);    // Pure STA mode — does not create AP signal, saves power
  connectWiFi();
}

void loop() { delay(1000); }

WiFi.mode(WIFI_STA) sets pure client mode. The counterparts are WIFI_AP (access point) and WIFI_AP_STA (dual-mode coexistence). Pure STA saves power and does not generate interfering AP signals.


6. Operation Flow

6.1 Build and Flash

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

  1. Modify WIFI_SSID and WIFI_PASS to your router credentials

  2. Build and flash

6.2 Expected Behavior

Open the serial monitor (115200 bps). After successful connection, it prints:

xxxxxxxxxx
Connecting to WiFi: Yahboom2 (Attempt 1)
...
WiFi Connection succeeded!
Device IP: 192.168.11.229

Serial output, WiFi connection

6.3 Verification Methods

ActionExpected Result
Enter correct passwordPrints IP address, WiFi connection succeeds
Enter wrong passwordRetries every 15 seconds after timeout, status code 4 (WL_CONNECT_FAILED)
Change timeout to 5 secondsTriggers retry faster under weak signal

7. Common Issues

SymptomCauseSolution
Continuously prints ..... without stoppingWrong password or signal too weakCheck password, move closer to router
Compilation error: WiFi.h not foundESP32 board package not installedInstall ESP32 Arduino Core in IDE
WiFi.status() returns 1SSID name incorrect, cannot be found during scanCheck if SSID matches router broadcast name exactly
WIFI Network Basics
WIFI AP Mode

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