Welcome to ESP32 Core Board repository
2. WIFI STA Mode
WIFI STA Mode Experiment
WIFI STA Mode Experiment1. WIFI STA Mode Overview2. Core Concepts2.1 How STA Mode Works2.2 Network Configuration Parameters2.3 Core API3. Hardware Dependencies3.1 ESP32-S3 WiFi Hardware Features4. Project Architecture and Flow5. Source Code Explained5.1 Configuration Parameters5.2 STA Connection (No Retry Limit, Loop Until Success)5.3 Printing Network Information5.4 Main Program Entry6. Operating Procedures6.1 Flashing and Running6.2 Expected Results6.3 Serial Output Example6.4 Verification Methods7. Common Problems
1. WIFI STA Mode Overview
STA (Station, client mode) is the most common way for the ESP32-S3 to go online — just like a phone connecting to WiFi, it actively connects to an existing wireless router or hotspot, obtains an IP address, and then can access the Internet or other devices on the LAN.
This experiment configures the ESP32-S3 in STA mode; after connecting to a specified WiFi network, it prints the network status information (IP, mask, gateway, DNS, signal strength).
Typical application scenarios:
| Application Type | Example |
|---|---|
| IoT devices | Smart home sensors report data to the cloud |
| Data acquisition | Temperature/humidity nodes send data to a server via WiFi |
| OTA upgrade | Download firmware updates from a server |
| Time synchronization | Connect to an NTP server to obtain network time |
In STA mode the ESP32-S3 is a "client" and needs an existing router/hotspot to access. If you need the ESP32-S3 to create its own hotspot, refer to the WIFI AP Mode experiment.
2. Core Concepts
2.1 How STA Mode Works
+---------+ +----------+| Router | <-- WiFi --> | ESP32-S3 ||(hotspot)| 2.4GHz | (STA) |+----+----+ +----------+||-- Internet|-- other devices on the LAN
In STA mode, the ESP32-S3 actively scans for and connects to a router; the router assigns the IP address, subnet mask, gateway, and DNS via DHCP.
2.2 Network Configuration Parameters
| Parameter | Description | Value Used in This Experiment |
|---|---|---|
| SSID | WiFi name | "Yahboom2" (modifiable in code) |
| Password | WiFi password | "yahboom890729" |
| Retry mechanism | No upper limit; wait 3s and reconnect on failure until success | while True loop |
| Retry interval | Wait after a failed connection | 3s |
2.3 Core API
ximport networkwlan = network.WLAN(network.STA_IF) # create STA interfacewlan.active(True) # activatewlan.connect("SSID", "password") # connect to APwlan.isconnected() # check if connectedip, mask, gw, dns = wlan.ifconfig() # get network configwlan.config('ssid') # read configwlan.status('rssi') # read RSSIwlan.disconnect() # disconnectwlan.active(False) # deactivate3. Hardware Dependencies
The ESP32-S3 has a built-in 2.4 GHz WiFi module, no external hardware needed. A 2.4 GHz WiFi hotspot (router or phone hotspot) must be available nearby.
3.1 ESP32-S3 WiFi Hardware Features
| Feature | Parameter |
|---|---|
| WiFi standard | IEEE 802.11 b/g/n |
| Operating band | 2.4 GHz |
| Max transmit power | +21 dBm (11b) |
| Max receive sensitivity | -97 dBm (11b) |
| Supported protocols | WPA/WPA2/WPA3 personal/enterprise |
| Antenna | On-board ceramic antenna / IPEX external antenna |
| Operating modes | STA / AP / STA+AP / Sniffer |
| Channel range | 1 ~ 14 |
4. Project Architecture and Flow
xxxxxxxxxxScript execution (single-file .py)||- wifi_connect(): connect in a loop with no retry limit; print IP after connecting|- wifi_info(): print IP/mask/gateway/DNS/signal strength||- main():|- connect to WiFi (while True until connected)|- print network info (IP/mask/gateway/DNS/RSSI)
5. Source Code Explained
Full source code: Source Code -> MicroPython -> 4.Network Protocols -> WiFi_STA -> WiFi_STA.py
5.1 Configuration Parameters
The SSID and password can be modified according to the actual environment; RETRY_WAIT controls the retry interval after a connection failure.
xxxxxxxxxxWIFI_SSID = "Your Wi-Fi SSID" # Wi-Fi SSIDWIFI_PASS = "Your Wi-Fi password" # Wi-Fi passwordRETRY_WAIT = 3 # retry interval (s)5.2 STA Connection (No Retry Limit, Loop Until Success)
The while True loop runs until connected; each round checks the connection for 15s, and on failure it waits RETRY_WAIT seconds before retrying, with no limit on the number of attempts.
xxxxxxxxxxdef wifi_connect(): """Connect WiFi, loop until connected""" wlan = network.WLAN(network.STA_IF) # create STA interface print(f"[STA] Connecting to '{WIFI_SSID}' ...") while True: try: wlan.active(False) time.sleep_ms(500) wlan.active(True) time.sleep_ms(200) if wlan.isconnected(): print(f"[STA] Already connected. IP: {wlan.ifconfig()[0]}") return wlan wlan.connect(WIFI_SSID, WIFI_PASS) for _ in range(15): # 15s timeout if wlan.isconnected(): print(f"[STA] Connected! IP: {wlan.ifconfig()[0]}") return wlan time.sleep(1) except OSError as e: print(f"[STA] OSError: {e}") print(f"[STA] Retrying in {RETRY_WAIT}s...") time.sleep(RETRY_WAIT)The retry count is no longer limited — the
while Trueloop runs until connected. Each round checks the connection status within 15s, and after failure it waits 3s and retries automatically.
5.3 Printing Network Information
ifconfig() returns (IP, subnet mask, gateway, DNS), and status('rssi') returns the signal strength in dBm.
xxxxxxxxxxdef wifi_info(wlan): cfg = wlan.ifconfig() print(f" IP : {cfg[0]}") print(f" Mask : {cfg[1]}") print(f" Gateway : {cfg[2]}") print(f" DNS : {cfg[3]}") print(f" RSSI : {wlan.status('rssi')} dBm")
ifconfig()returns a (IP, subnet mask, gateway, DNS) quadruple, andstatus('rssi')returns the signal strength; the closer to 0, the stronger the signal (e.g. -40 dBm is good, -80 dBm is weak).
5.4 Main Program Entry
Calls wifi_connect() which blocks until connected, then prints the IP/mask/gateway/DNS and signal strength.
xxxxxxxxxxdef main(): wlan = wifi_connect() # connect to WiFi wifi_info(wlan) # print network info6. Operating Procedures
6.1 Flashing and Running
Thonny IDE steps: See MicroPython -> 1. Before Development -> 3.Thonny IDE.
- Modify the
WIFI_SSIDandWIFI_PASSin the code to an actually available WiFi network - Open
WiFi_STA.pyin Thonny IDE and click Run
6.2 Expected Results
After a successful connection, the IP address and network parameters are printed; you can ping the IP to verify network reachability.
6.3 Serial Output Example
xxxxxxxxxx[STA] Already connected. IP: 192.168.11.229IP : 192.168.11.229Mask : 255.255.255.0Gateway : 192.168.11.1DNS : 192.168.11.1RSSI : -9 dBm

6.4 Verification Methods
| Operation | Expected Result |
|---|---|
| Enter correct SSID/password | Connection succeeds, IP is printed |
| Enter a wrong password | Retries every 3s until connected |
After successful connection, ping <IP> (on PC) | Can ping the ESP32-S3 |
7. Common Problems
| Symptom | Cause | Solution |
|---|---|---|
| Keeps printing retries | Wrong SSID/password or too weak signal | Confirm the WiFi is 2.4 GHz (the ESP32-S3 does not support 5 GHz), check the password |
| IP obtained as 0.0.0.0 | DHCP did not assign an IP | Check whether the router's DHCP service is working properly |