Wi-Fi components can be used to configure and monitor the Wi-Fi network connection of ESP32-C3. The following features are supported.
STA mode: aka station mode or Wi-Fi client mode. ESP32-C3 is connected to the AP in this mode.
AP mode: aka SoftAP mode or access point mode. The AP is connected to ESP32-C3 in this mode.
AP-STA coexistence mode: ESP32-C3 is connected to another AP as an AP.
Security standards for the modes above: WPA, WPA2, WPA3, WEP, etc.
Scanning for APs, including active and passive scanning.
Promiscuous mode for monitoring IEEE 802.11 Wi-Fi packets.
esp_wifi.h defines the APIs for Wi-Fi components, as shown in Table 7.3.
Table 7.3. APIs for Wi-Fi components
|Initialise resources for the Wi-Fi driver, such as Wi-Fi control structures and Wi-Fi tasks|
|Free resources allocated in |
|Set the WiFi operating mode for ESP32-C3|
|Get the WiFi operating mode of ESP32-C3|
|Start Wi-Fi according to current configuration|
|Stop Wi-Fi according to current configuration|
|Connect ESP32-C3 to the AP|
|Disconnect ESP32-C3 from the AP|
|Scan for all available APs|
|Stop the scan in progress|
|Get the number of APs found by ESP32-C3|
|Get the information about APs found by ESP32-C3|
|Set the configuration of the ESP32-C3 STA or AP|
|Get the configuration of the ESP32-C3 STA or AP|
The ESP32-C3 Wi-Fi programming model is depicted in Figure 7.31.
The Wi-Fi driver can be considered a black box that knows nothing about upper-layer code, such as TCP stacks, application tasks, and event tasks. The application task (code) generally calls Wi-Fi driver APIs to initialise Wi-Fi and handles Wi-Fi events when necessary. The Wi-Fi driver receives API calls, handles them, and posts events in the application.
Wi-Fi event handling is based on the
esp_event library. Events are
sent by the Wi-Fi driver to the default event loop. Applications may
handle these events in callbacks registered using
esp_event_handler_register(). Wi-Fi events are also handled by the
esp_netif component to provide a set of default behaviors. For
example, when a Wi-Fi station connects to an AP,
automatically start the Dynamic Host Configuration Protocol (DHCP)
client by default.