Article updated version | time | Release Notes | Revised by |
---|---|---|---|
V0.1 | Posted on 2020-04-25 | initial version | libo |
V0.2 | Posted on 2020-04-27 | Add notes, add differences between different versions of Wi-Fi library | libo |
Article Directory
1. Wi-Fi performance
ESP32 Wi-Fi performance
project | parameter |
---|---|
Mode | Station, AP, Coexistence |
Protocol | IEEE-802.11B, IEEE-802.11G, IEEE802.11N, 802.11 LR (Espressif) support software switching |
Safety | WPA/WPA2/WPA2-Enterprise and WPS |
Keyfeature | AMPDU, HT40, QoS |
Distance | 1 km with Espressif-specific protocol |
Speed | 20 MBit/sec TCP throughput, 30 MBit/sec UDP |
ESP32-S2 Wi-Fi Throughput:https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/wifi.html#esp32-s2-wi-fi-throughput
Other parameters: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#esp32-wi-fi-feature-list
ESP32-S2 Wi-Fi performance (verification and supplement required)
project | parameter |
---|---|
Mode | Station, AP, Coexistence |
Protocol | IEEE-802.11B, IEEE-802.11G, IEEE802.11N support software switching |
Safety | WPA/WPA2/WPA2-Enterprise and WPS |
Keyfeature | AMPDU, HT40, QoS |
Distance | 1 km with Espressif-specific protocol |
Speed | 20 MBit/sec TCP throughput, 30 MBit/sec UDP |
Other parameters: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/wifi.html#esp32-s2-wi-fi-feature-list
2. Wi-Fi programming framework
- The application layer calls Wi-Fi driver APIs to initialize Wi-Fi.
- Wi-Fi can be seen as a black box that works independently. When an event occurs, it is released to the default event loop . Applications can write programs and register according to their needs .
event
handle
- The network interface component esp_netif provides a series of
handle
programs, which are associated with the WiFi driver byevent
default. For example, ESP32 is used as an AP. When a user accesses, esp_netif will automatically start the DHCP service.
Note: Before Wi-Fi initialization, you should use the
WIFI_INIT_CONFIG_DEFAULT
Get Initialization Configuration Structure to personalize the structure, and then perform the initialization work. Prevent problems caused by uninitialized structure members, especially when IDF updates add new structure members.
2.1 General use process
Sample Wi-Fi Event Scenarios in Station Mode
Sample Wi-Fi Event Scenarios in AP Mode
2.2 menuconfig configurable items
-
Modify Wi-Fi Buffer to save space After
Wi-Fi is initialized, a part of the memory space will be statically allocated. If the user is more sensitive to memory, you canStatic RX Buffer
save up to 6400 Bytes space by reducing it , and byStatic TX Buffer
modifying it toDynamic TX Buffer
save (16 * 1600-32) Bytes left and right space. For details, please refer to: Wi-Fi Buffer Configure -
Keep WiFi configuration information in NVS
By enabling Wi-Fi NVS Flash, the Wi-Fi driver will save the configuration information in NVS, and the WiFi configuration phase can be skipped next time you start it. Users can also turn off this option and save the configuration information by themselves. -
Enable AMPDU to improve network throughput
AMPDU is enabled by default. In the 802.11n standard, the A-MPDU aggregation frame format is adopted, that is, multiple MPDUs are aggregated into one A-MPDU, only one PHY header is retained, and the PHY headers of the remaining MPDUs are deleted, which reduces the additional information of the PHY header of each MPDU. It also reduces the number of ACK frames, thereby reducing the protocol load, and effectively improving network throughput.
The 802.11n protocol defines a new MAC feature A-MSDU. This feature enables multiple MSDUs to be combined into one MSDU for transmission. Similar to A-MPDU, through aggregation, A-MSDU reduces the transmission of the MAC header of each MSDU. Additional information improves the transmission efficiency of the MAC layer. 802.11n supports optimization at the physical layer and provides short interval functions. The original 11a/g GI duration is 800us, while the short interval Short GI duration is 400us. When Short GI is used, the rate can be increased by 10%.
ESP32-S2 supports receiving AMSDU but doesn’t support transmitting AMSDU. The transmitting AMSDU is not necessary since ESP32-S2 has transmitting AMPDU.
3. Wi-Fi debugging
3.1 Improve signal quality
- Modifying the default HT40 to a fixed HT20 can reduce external interference, but the theoretical transmission rate drops from 150Mbps to 72Mbps (raw PHY data rate).
3.2 Wireshark network analysis tool
Espressif Wireshark User Guide
3.3 Error code monitoring
Error codes are defined in the
esp_err.h
file
ESP-IDF provides a default error code monitoring macros ESP_ERROR_CHECK
can be used to monitor the location and the error message, but it is recommended to monitor user-defined macros to automate processing error messages.
Error type | Approach |
---|---|
ESP_OK | Next step |
4. Differences in Wi-Fi Library of Different Versions
4.1 Event naming is different
All event names have changed, mainly because the SYSTEM_EVENT_XXX_YYY
corresponding changes have been changed to WIFI_EVENT_XXX_YYY
orIP_EVENT_XXX_YYY
v3.3 | v4.0 + | Remarks |
---|---|---|
SYSTEM_EVENT_WIFI_READY | WIFI_EVENT_WIFI_READY | This event will not be triggered in v4.0 |
SYSTEM_EVENT_SCAN_DONE | WIFI_EVENT_SCAN_DONE | – |
SYSTEM_EVENT_XXX_YYY | WIFI_EVENT_XXX_YYY | – |
SYSTEM_EVENT_STA_GOT_IP | IP_EVENT_STA_GOT_IP | – |
SYSTEM_EVENT_AP_STA_GOT_IP6 | IP_EVENT_GOT_IP6 | |
SYSTEM_EVENT_STA_LOST_IP | IP_EVENT_STA_LOST_IP | Is the official document wrong? |
4.2 Different function interface definitions
v3.3 | v4.0 + | Remarks |
---|---|---|
tcpip_adapter_init() | esp_netif_init() | Create and initialize LwIP thread |
esp_event_loop_init() | esp_event_loop_init() | Create system event loop thread, register event callback function |
no | esp_netif_create_default_wifi_ap(), esp_netif_create_default_wifi_sta() | Create a default network interface and bind it to the TCP/IP protocol stack |
esp_wifi_init() | esp_wifi_init() | Create and initialize Wi-Fi driver thread |
Five, matters needing attention
- The initialization process is not fixed, but the General Scenario should be followed as much as possible .
- The WiFi configuration work should be completed before the WiFi connection as much as possible. If the WiFi is configured in the middle, it will trigger the WiFi reconnection.
- The process of obtaining IP in WiFi station mode will take some time. Please do not
IP_EVENT_STA_GOT_IP
start socket related work before triggering. - If the AP is closed or the RSSI is weak, it
WIFI_EVENT_STA_DISCONNECTED
will be triggered, then the LwIP thread will disconnect and clear the UDP/TCP connection, and then the socket related functions will return an error code. Pay attention to the error monitoring . - If the IP address changes,
IP_EVENT_STA_GOT_IP
will be triggered at the same timeip_change
it is true, if you receive such an event, you need to close all sockets have been created, re-created . - Long-distance mode requires both ends to support Espressif 802.11LR. Compared with 802.11 B, this mode has a 4 dB gain increase. In principle, the transmission distance is 2-2.5 times that of 802.11 B, but the throughput of this mode is very limited to 1/2 Mbits