Chapter 26: WiFi Protocol Fundamentals

Chapter Objectives

By the end of this chapter, you will be able to:

  • Understand the purpose and evolution of the IEEE 802.11 standards.
  • Recognize key WiFi terminology like SSID, BSSID, Channel, and Bandwidth.
  • Differentiate between the 2.4 GHz and 5 GHz frequency bands and their implications.
  • Understand the basic concepts of WiFi network topologies (Infrastructure BSS, IBSS).
  • Identify common WiFi security protocols (WEP, WPA, WPA2, WPA3).
  • Relate these fundamental concepts to the configuration options available in ESP-IDF.
  • Know which WiFi standards are supported by different ESP32 variants.

Introduction

Welcome to Volume 2, where we dive into the exciting world of connectivity, starting with the most ubiquitous wireless technology: WiFi. In previous chapters, we focused on the core ESP32 system, FreeRTOS, and essential peripherals. Now, we’ll explore how to connect your ESP32 device to the world.

Before we write code to connect to a network, it’s crucial to understand the underlying principles of WiFi. How do devices discover networks? How do they communicate without interfering with each other? How is communication secured? This chapter introduces the fundamental concepts and terminology of the IEEE 802.11 standards, the family of specifications that define WiFi. Understanding these basics will empower you to configure WiFi connections effectively, troubleshoot issues, and make informed decisions when designing your connected applications using ESP-IDF.

Theory

The IEEE 802.11 Standard Family

WiFi, technically known as Wireless Local Area Network (WLAN), is based on the IEEE 802.11 set of standards developed and maintained by the Institute of Electrical and Electronics Engineers (IEEE). These standards define how wireless communication occurs over the air, covering both the Physical Layer (PHY) and the Medium Access Control (MAC) layer.

Physical Layer (PHY):

  • Defines the physical characteristics of the wireless transmission – how data bits are converted into radio waves
  • Handles the electrical, mechanical, and procedural interfaces to the transmission medium
  • Encompasses modulation techniques (BPSK, QPSK, QAM), frequency bands (2.4 GHz, 5 GHz, 6 GHz), and data rates
  • Includes specifications for radio frequency (RF) power levels, receiver sensitivity, and antenna configurations
  • Manages error detection and correction at the bit level

Medium Access Control (MAC) Layer:

  • Defines how devices access the shared wireless medium (the airwaves) to avoid data collisions
  • Establishes protocols for device association/disassociation with networks
  • Handles basic data framing, addressing, and delivery acknowledgment
  • Manages authentication and encryption processes
  • Implements power-saving mechanisms and quality of service (QoS) features
  • Controls fragmentation and reassembly of data frames

Evolution of 802.11 Standards

Over the years, the 802.11 standard has evolved through various amendments, each bringing improvements like higher speeds, better reliability, or new features. Here are some key amendments relevant to ESP32 development:

  • 802.11b (1999): Operated in the 2.4 GHz band, offering speeds up to 11 Mbps. Largely legacy now but formed the basis for widespread WiFi adoption.
  • 802.11g (2003): Also in the 2.4 GHz band, but increased speeds up to 54 Mbps using OFDM modulation (Orthogonal Frequency-Division Multiplexing). Backwards compatible with 802.11b.
  • 802.11n (2009 – WiFi 4): Introduced significant speed improvements (up to 600 Mbps theoretically) by using MIMO (Multiple-Input Multiple-Output) antennas, channel bonding, and operating in both 2.4 GHz and 5 GHz bands.
  • 802.11ac (2013 – WiFi 5): Primarily focused on the 5 GHz band, offering wider channels, more MIMO streams, and higher speeds (gigabit range theoretically).
  • 802.11ax (2019 – WiFi 6 / WiFi 6E): Designed for high-density environments (like airports, stadiums). Improves efficiency, capacity, and performance using technologies like OFDMA (Orthogonal Frequency-Division Multiple Access) and operates in 2.4 GHz, 5 GHz, and potentially 6 GHz bands (WiFi 6E).
  • 802.11be (2024- WiFi 7): Aims for extremely high throughput, lower latency, and even better reliability, leveraging wider channels (320 MHz), more spatial streams, and advanced coordination techniques.

ESP32 variants support a subset of these standards, primarily 802.11b/g/n. Newer variants like ESP32-C6 also add support for 802.11ax (WiFi 6).

timeline
    title WiFi Standards Evolution
        802.11b (11 Mbps) : 1999 : 2.4 GHz : Initial widespread adoption
        802.11g (54 Mbps) : 2003 : 2.4 GHz : Higher speed (OFDM), backward compatible with 'b'
        802.11n/WiFi 4 (~600 Mbps) : 2009 : 2.4 GHz & 5 GHz : MIMO, Channel Bonding
        802.11ac/WiFi 5 (~1+ Gbps) : 2013 : 5 GHz : Wider channels, More MIMO
        802.11ax/WiFi 6/6E (Multi-Gbps) : 2019 : 2.4/5/6 GHz : Efficiency (OFDMA), Better in dense environments
        802.11be/WiFi 7 (High Multi-Gbps) : 2024 : 2.4/5/6 GHz : Extremely High Throughput, Lower Latency

Key WiFi Terminology

Understanding the following terms is essential when working with WiFi:

Access Point (AP):

A device (like your home router) that creates a wireless network and allows other devices (stations) to connect to it and potentially to a wired network (like the internet).

Station (STA):

Any device equipped with a WiFi interface that can connect to an AP (e.g., laptops, smartphones, ESP32 boards).

Service Set Identifier (SSID):

The human-readable name of a WiFi network (e.g., “MyHomeNetwork”, “CoffeeShopFreeWiFi”). When you scan for networks, you see a list of SSIDs. An AP broadcasts its SSID (unless hidden) so stations can find it.

Basic Service Set Identifier (BSSID):

The MAC address of the wireless interface of the Access Point. While multiple APs might share the same SSID (in larger networks), each AP has a unique BSSID. When a station connects to a specific AP, it’s associating with that AP’s BSSID.

Channel:

WiFi operates in specific frequency bands (2.4 GHz and 5 GHz). These bands are divided into smaller frequency ranges called channels. Devices communicating on the same network must use the same channel. Choosing the right channel is important to avoid interference from other networks or devices.

  • 2.4 GHz Band: Offers longer range but has fewer non-overlapping channels (typically only 1, 6, and 11 in North America) and is more susceptible to interference from microwaves, Bluetooth devices, etc.
  • 5 GHz Band: Offers shorter range but many more non-overlapping channels and generally less interference, leading to potentially higher speeds and stability. Not all ESP32 variants support 5 GHz.
Feature 2.4 GHz Band 5 GHz Band
Range Longer Shorter
Speed (Potential) Lower Higher
Interference Higher (Microwaves, Bluetooth, etc.) Lower
Non-Overlapping Channels Fewer (e.g., 3 in North America) Many More
Wall Penetration Better Worse
ESP32 Support Most variants ESP32-C61 Only

Bandwidth (Channel Width):

Refers to the width of the channel used for communication. Wider channels allow for higher data rates. Common widths are 20 MHz, 40 MHz (channel bonding in 802.11n/ax), 80 MHz, and 160 MHz (802.11ac/ax).

RSSI (Received Signal Strength Indicator):

A measurement (usually in negative dBm, e.g., -50 dBm) indicating the power level of the signal received by the station from the AP. A higher value (closer to 0) means a stronger signal. Values below -75 dBm typically indicate a weak connection, while below -85 dBm might be unusable.

[Insert diagram showing an Access Point (with SSID and BSSID labels) connected to the internet, and several Stations (laptop, phone, ESP32) connecting wirelessly to the AP.]

Network Topologies

  • Infrastructure Mode (Basic Service Set – BSS): The most common topology. One or more stations connect to a central Access Point, which typically bridges the wireless network to a wired network (like Ethernet). All communication between stations usually goes through the AP.
  • Extended Service Set (ESS): Multiple APs connected by a wired network (Distribution System), all sharing the same SSID. This allows devices to roam seamlessly between APs in a larger area (like an office building or university campus).
  • Independent Basic Service Set (IBSS) / Ad-Hoc Mode: Stations connect directly to each other without needing a central AP. This is less common for general internet access but can be useful for direct device-to-device communication. ESP-IDF primarily focuses on Infrastructure mode (both STA and AP roles) and ESP-NOW (a proprietary Espressif protocol) offers efficient ad-hoc-like communication.

WiFi Security

Securing wireless communication is critical. Over time, security protocols have evolved:

  • WEP (Wired Equivalent Privacy): The original security protocol. Deeply flawed and insecure. Should never be used. Included for historical context only.
  • WPA (Wi-Fi Protected Access): An interim improvement over WEP, using TKIP (Temporal Key Integrity Protocol). Also considered insecure now compared to WPA2/WPA3.
  • WPA2 (Wi-Fi Protected Access II): The long-standing standard, using AES (Advanced Encryption Standard) encryption, which is much stronger. Most common security protocol found today. Uses a Pre-Shared Key (PSK – the network password) for personal networks (WPA2-Personal) or more complex authentication via a RADIUS server for enterprise networks (WPA2-Enterprise).
  • WPA3 (Wi-Fi Protected Access III): The latest standard, offering significant security enhancements over WPA2. It mandates Protected Management Frames (PMF) for better protection against deauthentication attacks and introduces Simultaneous Authentication of Equals (SAE) to replace PSK, making it more resistant to offline dictionary attacks. WPA3 is becoming more common and is supported by newer ESP32 variants.
%%{ init: { 'theme': 'base', 'themeVariables': { 'fontFamily': '"Open Sans", sans-serif' } } }%%
graph LR;
    WEP["WEP (1997)<br>Status: Insecure<br>Encryption: RC4<br>Flawed"]:::check;
    WPA["WPA (2003)<br>Status: Insecure (Legacy)<br>Encryption: TKIP<br>Interim Fix"]:::decision;
    WPA2["WPA2 (2004)<br>Status: Secure (Standard)<br>Encryption: AES-CCMP<br>PSK/Enterprise"]:::process;
    WPA3["WPA3 (2018)<br>Status: Most Secure<br>Encryption: AES-CCMP/GCMP<br>SAE, PMF"]:::success;

    WEP --> WPA;
    WPA --> WPA2;
    WPA2 --> WPA3;

    %% Styling
    classDef primary fill:#EDE9FE,stroke:#5B21B6,stroke-width:2px,color:#5B21B6;
    classDef success fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#065F46;
    classDef decision fill:#FEF3C7,stroke:#D97706,stroke-width:1px,color:#92400E; 
    classDef process fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF; 
    classDef check fill:#FEE2E2,stroke:#DC2626,stroke-width:1px,color:#991B1B;

    class WEP check;
    class WPA decision;
    class WPA2 process;
    class WPA3 success;

Tip: Always use WPA2 or WPA3 security for your WiFi networks. ESP-IDF allows you to configure the security type when connecting your ESP32 as a station.

Protocol Security Level Encryption Key Features / Notes
WEP Insecure RC4 Original standard, deeply flawed. Avoid completely.
WPA Insecure (Legacy) TKIP (RC4 wrapper) Interim improvement over WEP, vulnerable. Avoid if possible.
WPA2 Secure (Standard) AES-CCMP Long-standing standard, strong encryption. Most common today (WPA2-Personal uses PSK).
WPA3 Most Secure AES-CCMP/GCMP Mandatory PMF, replaces PSK with SAE (more resistant to offline attacks). Recommended.

%%{ init: { 'theme': 'base', 'themeVariables': { 'fontFamily': '"Open Sans", sans-serif' } } }%%
graph TD
    Start(Start) ==> Scan["Scan for Available Networks<br>(List SSIDs, Channels, Security)"]:::primary;
    Scan --> Choose{"Choose Target Network (SSID)"}:::decision;
    Choose -- Network Found --> Authenticate["Authenticate<br>(Provide Credentials - e.g., PSK)"]:::process;
    Authenticate --> AuthCheck{Authentication OK?}:::check;
    AuthCheck -- Yes --> Associate["Associate with AP<br>(Link Layer Connection)"]:::process;
    Associate --> AssocCheck{Association OK?}:::check;
    AssocCheck -- Yes --> DHCP["Obtain IP Address<br>(DHCP Request/Offer)"]:::process;
    DHCP --> Connected(Connected!):::success;
    AuthCheck -- No --> FailAuth(Authentication Failed):::check;
    AssocCheck -- No --> FailAssoc(Association Failed):::check;
    Choose -- Network Not Found --> Scan;
    FailAuth --> End(End Process):::check;
    FailAssoc --> End;
    Connected --> End;


    %% Styling
    classDef primary fill:#EDE9FE,stroke:#5B21B6,stroke-width:2px,color:#5B21B6;
    classDef success fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#065F46;
    classDef decision fill:#FEF3C7,stroke:#D97706,stroke-width:1px,color:#92400E;
    classDef process fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#1E40AF;
    classDef check fill:#FEE2E2,stroke:#DC2626,stroke-width:1px,color:#991B1B;

    class Start primary;
    class Connected success;
    class FailAuth, FailAssoc;
    class End check;

Practical Examples

While this chapter focuses on theory, let’s see where these concepts appear in practice within the ESP-IDF environment.

Example 1: Observing WiFi Concepts in menuconfig

  1. Open an ESP-IDF project in VS Code (e.g., the wifi/getting_started/station example).
  2. Run idf.py menuconfig (or use the VS Code extension’s menuconfig shortcut).
  3. Navigate to Component config —> Wi-Fi.
  4. Observe options like:
    • WiFi MAC Address: Related to the device’s unique identifier (like a BSSID when in AP mode).
    • WiFi Country Code: Affects which channels are legally permissible.
    • Channel: Allows setting a specific channel if operating in AP mode.
    • Bandwidth: Options like HT20 (20 MHz) or HT40 (40 MHz) relate to 802.11n channel width.
    • WiFi CSI: Channel State Information, an advanced PHY layer concept.
    • Enable WPA3-Personal: Directly relates to the WPA3 security standard.
    • WiFi Protocol: Options to enable/disable 802.11b, g, n support. Newer chips might show ax options here.

These settings directly map to the protocol fundamentals we discussed.

Example 2: Interpreting Scan Results (Conceptual)

When you later implement WiFi scanning (covered in Chapter 34), the results will typically provide information for each detected network, such as:

  • SSID: The network name (e.g., “MyHomeNetwork”).
  • BSSID: The AP’s MAC address (e.g., 1A:2B:3C:4D:5E:6F).
  • Channel: The channel the AP is operating on (e.g., 6).
  • RSSI: The signal strength (e.g., -65 dBm).
  • Auth Mode: The security type detected (e.g., WPA2_PSK, WPA3_SAE, OPEN).

Understanding the theory allows you to correctly interpret this scan data.

RSSI vs. Distance Simulation

Drag the blue square (STA) left and right to see how distance affects the Received Signal Strength Indicator (RSSI).

AP
STA
Signal Strength: -50 dBm (Strong)

Variant Notes

WiFi capabilities differ across the ESP32 family:

ESP32 Variant 802.11 b/g/n (2.4GHz) 802.11 ax (WiFi 6, 2.4GHz) 5 GHz Support WPA3 Support Bluetooth/BLE 802.15.4 (Thread/Zigbee)
ESP32 (Original) Varies*
ESP32-S2
ESP32-S3 ✔ (BLE 5.0)
ESP32-C3 ✔ (BLE 5.0)
ESP32-C6 ✔ (BLE 5.1)
ESP32-H2 ✘ (No WiFi) N/A ✔ (BLE 5.2)
ESP32-C5 ✔ (BLE 5.0)
ESP32-C61 ✔ (BLE 5.4)
*WPA3 support depends on ESP-IDF version and specific chip revision. Generally available on newer variants/SDKs.
  • ESP32 (Original): Supports 802.11b/g/n on the 2.4 GHz band. It has both WiFi and Bluetooth/BLE capabilities.
  • ESP32-S2: Supports 802.11b/g/n on the 2.4 GHz band. Does not have Bluetooth capabilities. Designed as a lower-cost WiFi-only alternative with enhanced security features and USB OTG.
  • ESP32-S3: Supports 802.11b/g/n on the 2.4 GHz band. Includes Bluetooth LE 5.0. Features AI acceleration capabilities and USB OTG. Similar WiFi capabilities to the original ESP32 but with a more powerful core and additional peripherals.
  • ESP32-C3: Supports 802.11b/g/n on the 2.4 GHz band. RISC-V core. Includes Bluetooth LE 5.0. Positioned as a low-cost, secure successor to the ESP8266/ESP32.
  • ESP32-C6: Supports 802.11ax (WiFi 6) on the 2.4 GHz band, offering improved efficiency, especially in dense environments. Also supports 802.11b/g/n. RISC-V core. Includes Bluetooth LE 5.1 and 802.15.4 (Thread/Zigbee) radio.
  • ESP32-H2: Does not support 802.11 WiFi. It is designed specifically for 802.15.4 (Thread/Zigbee) and Bluetooth LE 5.2 connectivity.

Key Takeaways:

  • All WiFi-enabled ESP32 variants support 802.11b/g/n on 2.4 GHz.
  • None of the currently listed variants natively support the 5 GHz band.
  • ESP32-C6 is the first to introduce 802.11ax (WiFi 6) support (on 2.4 GHz).
  • ESP32-H2 lacks WiFi support entirely.
  • Support for newer security standards like WPA3 depends on the specific ESP-IDF version and the chip variant (generally available on S2, S3, C3, C6).

Common Mistakes & Troubleshooting Tips

  1. Confusing SSID and BSSID:
    • Mistake: Using the network name (SSID) when a function or configuration requires the AP's MAC address (BSSID), or vice-versa.
    • Symptom: Connection failures, inability to target a specific AP in dense environments with multiple APs sharing the same SSID.
    • Fix: Understand the difference: SSID is the name, BSSID is the specific AP's MAC address. Use the correct identifier as required by the ESP-IDF API function.
  2. Ignoring Channel Interference (2.4 GHz):
    • Mistake: Assuming poor performance is solely due to signal strength (RSSI) without considering channel congestion, especially in the crowded 2.4 GHz band.
    • Symptom: Slow speeds, connection drops, high latency despite seemingly adequate RSSI.
    • Fix: Use a WiFi analyzer tool (on a phone or laptop) to check channel usage in the area. If possible, configure the AP to use a less crowded, non-overlapping channel (1, 6, or 11). Understand that ESP32 performance can be impacted by severe interference.
  3. Selecting Incompatible Security Settings:
    • Mistake: Configuring the ESP32 station to use a security protocol (e.g., WPA3) that the target Access Point does not support, or vice-versa. Or providing an incorrect password (PSK).
    • Symptom: The ESP32 fails to associate or authenticate with the AP, often indicated by specific reason codes in WiFi events (covered later).
    • Fix: Ensure the security settings (WEP, WPA, WPA2-PSK, WPA3-SAE, etc.) configured in the ESP-IDF application exactly match the settings on the target Access Point. Double-check the Pre-Shared Key (password).
  4. Assuming 5 GHz Support:
    • Mistake: Designing an application assuming the ESP32 can connect to 5 GHz networks when the specific variant does not support it.
    • Symptom: Inability to see or connect to 5 GHz-only SSIDs.
    • Fix: Remember that current mainstream ESP32 variants (including C6) only operate on the 2.4 GHz band. Design accordingly or choose alternative hardware if 5 GHz is a strict requirement.

Exercises

  1. Network Parameter Identification: Use a smartphone or laptop WiFi scanning tool. Identify the following for your home network or a nearby network:
    • SSID
    • BSSID (MAC Address of the AP)
    • Channel
    • Security Type (e.g., WPA2, WPA3)
    • Approximate RSSI
    • Supported 802.11 standards (if the tool shows them, e.g., b/g/n/ax)
    • Relate these findings back to the terms discussed in this chapter.
  2. ESP-IDF Configuration Exploration:
    • Navigate to the wifi/getting_started/station example in your ESP-IDF installation.
    • Run idf.py menuconfig.
    • Go to Component Config -> Wi-Fi.
    • Examine the available options for WiFi Protocol (e.g., 802.11b, 802.11b/g, 802.11b/g/n). How might changing these affect compatibility or performance?
    • Locate the Enable WPA3-Personal support (SAE) option. What security implications does enabling or disabling this have?

Summary

  • WiFi is based on the IEEE 802.11 family of standards (b/g/n/ac/ax/be), defining PHY and MAC layer operations.
  • Key terms include SSID (network name), BSSID (AP MAC address), AP (Access Point), STA (Station), Channel (frequency subdivision), Bandwidth (channel width), and RSSI (signal strength).
  • WiFi typically operates in the 2.4 GHz (longer range, more interference) or 5 GHz (shorter range, less interference) bands. Most ESP32 variants only support 2.4 GHz.
  • The most common network mode is Infrastructure (BSS), where stations connect to an AP.
  • Security protocols have evolved: WEP (Insecure) -> WPA (Insecure) -> WPA2 (Common Standard) -> WPA3 (Modern Standard). Always use WPA2 or WPA3.
  • ESP32 variants support different standards: ESP32/S2/S3/C3 support 802.11b/g/n; ESP32-C6 adds 802.11ax (WiFi 6) support (all on 2.4 GHz). ESP32-H2 does not support WiFi.
  • Understanding these fundamentals is crucial for configuring connections and troubleshooting issues in ESP-IDF.

Further Reading

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top