Wi-Fi

[中文]


What is the one-to-one bit rate for ESP32 in ESP-NOW mode?

Test result:

  • Test board: ESP32_Core_board_V2.

  • Wi-Fi mode: station.

  • Around 214 Kbps in opened environment.

  • Around 555 Kbps in shielding box.


Do ESP32 and ESP8266 support Chinese SSID for Wi-Fi?

Yes, but the CODEC format of router or smart phone should be the same.

For example, if both router and device use UTF-8 format, then the device can be successfully connected to the router with Chinese SSID.


How much time does an ESP32 scan take?

The total time for scanning depends on:

  • Active scan (by default) or passive scan.

  • The time spent on each channel is 120 ms for active scanning and 360 ms for passive scanning.

  • The country code and configured channel range from 1~13 channels (by default).

  • Fast scan (by default) or full-channel scan.

  • Station mode or Station-AP mode, and if any active connections are currently maintained.

By default, channels 1 to 11 use active scans, and channels 12 to 13 use passive scans.

  • In the absence of connection in Station mode, the total time for a full-channel scan is: 11*120 + 2*360 = 2040 ms.

  • With active connections in Station mode or Station-AP mode, the total time for a full-channel scan is: 11*120 + 2*360 + 13*30 = 2430 ms.


[Scan] Do Espressif’s products support boundary scans?

No, they don’t.


How can I optimize the second harmonic and other spurious signals created by my own products?

The second harmonic mainly comes from the radiation generated by the RF link and PA (power amplifier) power supply. The backplane (board size) and the product also make impact on the second harmonic. Therefore, it is recommended that you should:

  • Add a ground capacitor of approximately 2.4 pF to the RF matching circuit to reduce the spurious radiation coming from the RF link.

  • Add a series inductor to the PA power supply (Pins 3 and 4 of ESP32) to reduce the spurious radiation coming from it.


What is the definition for Wi-Fi channel? Can I select any channel of my choice?

A channel refers to a specific frequency channel within the allowable range of frequencies allocated for use by Wi-Fi systems. Different countries and regions use different channel numbers. Please refer to ESP8266 Wi-Fi Channel Selection Guidelines.


How can I suppress the harmonics of 80 MHz?

If the harmonics of 80 MHz (160 MHz, 240 MHz, 320 MHz, etc) exceed the allowable levels of spurious emissions, you can add a resistor of approximately 470 Ω to the data transmission circuit (TXD) to suppress those harmonics.


[LWIP] With ESP-IDF v4.1, how to configure ESP32’s IP address when it is in SoftAP mode?

Since ESP-IDF v4.1 and later versions do not have TCP/IP interfaces anymore, it is recommended to use the ESP-NETIF interface instead.

Code example:

{
    ...
    esp_netif_t *ap_netif = esp_netif_create_default_wifi_ap();
    char* ip= "192.168.5.241";
    char* gateway = "192.168.5.1";
    char* netmask = "255.255.255.0";
    esp_netif_ip_info_t info_t;
    memset(&info_t, 0, sizeof(esp_netif_ip_info_t));

    if (ap_netif)
    {
        ESP_ERROR_CHECK(esp_netif_dhcps_stop(ap_netif));
        info_t.ip.addr = esp_ip4addr_aton((const char *)ip);
        info_t.netmask.addr = esp_ip4addr_aton((const char *)netmask);
        info_t.gw.addr = esp_ip4addr_aton((const char *)gateway);
        esp_netif_set_ip_info(ap_netif, &info_t);
        ESP_ERROR_CHECK(esp_netif_dhcps_start(ap_netif));
    }
    ...
}

[LWIP] How to configure ESP32’s static IP when it is in Station mode?

Since ESP-IDF v4.2 and later versions do not have tcp/ip interfaces anymore, it is recommended to use the ESP-NETIF interface instead. The code example is as follows:

esp_netif_ip_info_t info_t = {0};
esp_netif_dns_info_t dns_info = {0};

// Initialize TCP/IP network interface (should be called only once in application)
ESP_ERROR_CHECK(esp_netif_init());
// Create default event loop that running in background
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
esp_netif_t *eth_netif = esp_netif_new(&cfg);
// Set default handlers to process TCP/IP stuffs
ESP_ERROR_CHECK(esp_eth_set_default_handlers(eth_netif));

esp_netif_dhcpc_stop(eth_netif);

info_t.ip.addr = ESP_IP4TOADDR(192,168,3,23);
info_t.gw.addr = ESP_IP4TOADDR(192,168,3,1);
info_t.netmask.addr = ESP_IP4TOADDR(255,255,255,0);
esp_netif_set_ip_info(eth_netif,&info_t);

dns_info.ip.u_addr.ip4.addr = ESP_IP4TOADDR(8,8,8,8);
esp_netif_set_dns_info(eth_netif,ESP_NETIF_DNS_MAIN,&dns_info);

[LWIP] How to configure the Option contents of DHCP Server in ESP-IDF?

Since ESP-IDF v4.1 and later versions do not have TCP/IP interfaces anymore, it is recommended to use the ESP-NETIF interface instead. You can also refer to this example when dealing with DHCP Client configuration. The code example is as follows:

// Set up the handle for softap netif
esp_netif_t *ap_netif = esp_netif_create_default_wifi_ap();

// ESP_NETIF_IP_ADDRESS_LEASE_TIME, DHCP Option 51, Set the lease time for distributed IP address
uint32_t dhcps_lease_time = 60; // The unit is min
ESP_ERROR_CHECK(esp_netif_dhcps_option(ap_netif,ESP_NETIF_OP_SET,ESP_NETIF_IP_ADDRESS_LEASE_TIME,&dhcps_lease_time,sizeof(dhcps_lease_time)));

// ESP_NETIF_DOMAIN_NAME_SERVER , DHCP Option 6, Set DNS SERVER
// Set the local domain DNS first
esp_netif_dns_info_t dns_info = {0};
dns_info.ip.u_addr.ip4.addr = ESP_IP4TOADDR(8,8,8,8);
ESP_ERROR_CHECK(esp_netif_set_dns_info(ap_netif,ESP_NETIF_DNS_MAIN,&dns_info));

uint8_t dns_offer = 1; // Pass 1 to make the modified DNS take effect, if it is 0, then it means the gw ip of softap is used as the DNS server (0 by default)
ESP_ERROR_CHECK(esp_netif_dhcps_option(ap_netif,ESP_NETIF_OP_SET,ESP_NETIF_DOMAIN_NAME_SERVER,&dns_offer,sizeof(dns_offer)));

// ESP_NETIF_ROUTER_SOLICITATION_ADDRESS, DHCP Option 3 Router, Pass 0 to make the DHCP Option 3(Router) un-shown (1 by default)
uint8_t router_enable = 0;
ESP_ERROR_CHECK(esp_netif_dhcps_option(ap_netif,ESP_NETIF_OP_SET,ESP_NETIF_ROUTER_SOLICITATION_ADDRESS,&router_enable, sizeof(router_enable)));

// ESP_NETIF_SUBNET_MASK, DHCP Option 1, Configure the subnet mask
// If it fails to configure the subnet mask via ESP_NETIF_SUBNET_MASK, please make modifications using esp_netif_set_ip_info

[Performance] How to test the bit rate of Wi-Fi modules?

Please use the codes in example example/wifi/iperf provided by ESP-IDF SDK.


[LWIP] What is the default IP address of ESP8266 SoftAP?

Why do I have problem connecting to router with IP 192.168.4.X in SoftAP + Station mode?

  • The default network segment used by ESP8266 SoftAP is 192.168.4.*, and its IP address is 192.168.4.1. When connecting ESP8266 to the router of 192.168.4.X, it cannot distinguish whether this address indicates its own SoftAP or the external router.


[Connect] How many devices is ESP8266 able to connect in SoftAP mode?

Up to eight devices in hardware level. However, to ensure module performance, it is recommended to connect four devices at most.


Do ESP8266/ESP32/ESP32-S2 support web/SoftAP provisioning?

Yes.


[Connect] How do ESP8266 and ESP32 hide SSID in SoftAP mode?

The variable ssid_hidden in wifi_ap_config_t structure can be configured to hide the SSID.


Does the buffer parameter in esp_wifi_802.11_tx interface include FCS?

No, the FCS frame is generated automatically by hardware.


What is the supported Wi-Fi frequency band and power meter for ESP-WROOM-32D?

The Wi-Fi frequency band is 2412 ~ 2484 MHz, and the available channels and corresponding operating frequencies can be configured in software. There are default values in power meter, and it can also be configured by software. For detailed guidance, please refer to ESP32 Phy Init Bin Parameter Configuration Guide.


What is the maximum value of ESP32 Wi-Fi RF power?

The RF power of ESP32 is 20 dB, which is exactly the maximum value.


How does ESP32 adjust Wi-Fi TX power?

  • Configure Component config -> PHY -> Max Wi-Fi TX power(dBm) via menuconfig, and the max value is 20 dB.

  • Use API esp_err_t esp_wifi_set_max_tx_power(int8_t power);.


[Connect] How many devices is ESP32 able to connect in AP mode?

Up to 10 devices in AP mode. It is configured to support four devices by default.


[Connect] How do Wi-Fi modules rank signal strength levels based on RSSI values?

We do not have a rating for RSSI signal strength. You can take the calculation method from Android system for reference if you need a standard for classification.

@UnsupportedAppUsage
private static final int MIN_RSSI = -100;

/** Anything better than or equal to this will show the max bars. */
@UnsupportedAppUsage
private static final int MAX_RSSI = -55;

public static int calculateSignalLevel(int rssi, int numLevels) {
  if(rssi <= MIN_RSSI) {
    return 0;
  } else if (rssi >= MAX_RSSI) {
    return numLevels - 1;
  } else {
    float inputRange = (MAX_RSSI -MIN_RSSI);
    float outputRange = (numLevels - 1);
    return (int)((float)(rssi - MIN_RSSI) * outputRange / inputRange);
  }
}

[Connect] Why does ESP32 disconnect from STA when it is in Soft-AP mode?

  • By default, the ESP32 will disconnect from the connected STA if it doesn’t receive any data from this STA for continuous 5 minutes. This time can be modified via API esp_wifi_set_inactive_time.

  • Note: esp_wifi_set_inactive_time is a newly added API.

    • master commit: 63b566eb27da187c13f9b6ef707ab3315da24c9d

    • 4.2 commit: d0dae5426380f771b0e192d8ccb051ce5308485e

    • 4.1 commit: 445635fe45b7205497ad81289c5a808156a43539

    • 4.0 commit: Pending, the MR is not merged yet

    • 3.3 commit: 908938bc3cd917edec2ed37a709a153182d511da


[Connect] While ESP32 connecting Wi-Fi, how can I determine the reason of failure by error codes?

For ESP-IDF v4.0 and later versions, please refer to the following codes to get the reason:

if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
  wifi_event_sta_disconnected_t *sta_disconnect_evt = (wifi_event_sta_disconnected_t*)event_data;
  ESP_LOGI(TAG, "wifi disconnect reason:%d", sta_disconnect_evt->reason);
  esp_wifi_connect();
  xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
}

When the callback function received WIFI_EVENT_STA_DISCONNECTED event, you can get the reason through the reason variable from wifi_event_sta_disconnected_t.

  • WIFI_REASON_AUTH_EXPIRE: This code is returned during the auth phase when the STA sends an auth but do not received any auth reply from the AP within the specified time. The possibility of this code occurrence is low.

  • WIFI_REASON_AUTH_LEAVE: This code is sent by AP, normally because the AP is disconnected from the STA for some reason.

  • WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT or WIFI_REASON_HANDSHAKE_TIMEOUT: Wrong password.

    WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT is the standard generalized error code, while WIFI_REASON_HANDSHAKE_TIMEOUT is a customized error code. The main difference is: WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT occurs when the router tells the device the password is wrong; WIFI_REASON_HANDSHAKE_TIMEOUT occurs when the device itself performs a timeout mechanism without being informed about the wrong password by the router.

  • WIFI_REASON_CONNECTION_FAIL: This code is returned during the scan phase when the STA scanned a matched AP while the AP is in the blacklist. This is probably because that the AP has actively disconnected from the STA last time or something wrong happened when the STA connecting the AP.


Does ESP32 perform domain name resolution each time it connects to the server?

The domain name is resolved via DNS within the stack, and the resolved data will be cached within the specified time. The cache time is based on the TTL data obtained from the DNS server, which is a parameter filled when configuring the domain name, usually 10 minutes.


[Connect] What does the number after the state machine switch in Wi-Fi log mean?

eg: run -> init (fc0), fc0 means the STA has received the deauth frame and reason is password error.

  • c0 indicates the received frame type (00 indicates a timeout)

  • f indicates reason

Frame type: [a0 disassoc], [b0 auth], [c0 deauth].


[Connect] What does bcn_timeout, ap_probe_send_start mean?

The STA does not receive the Beacon frame within the specified time (6 s by default for ESP32, equals to 60 Beacon Intervals).

  • The reason could be:

    • Insufficient memory. “ESP32_WIFI_MGMT_SBUF_NUM” is not enough (there will be errors like “esf_buf: t=8, l=beacon_len, …” in the log). You can check this by typing the heap size when received a Disconnect event.

    • The AP did not send a beacon. This can be checked by capturing beacons from AP.

    • Rssi too low. When the Rssi value is too low in complex environments, the STA may not receive the beacon. This can be checked by retrieving Rssi values via esp_wifi_sta_get_ap_info.

    • Hardware related issues. Bad package capturing performance.

When there is a bcn_timeout, the STA will try to send Probe Request for five times. If a Probe Response is received from the AP, the connection will be kept, otherwise, the STA will send a Disconnect event and the connection will fail.


[Connect] How to reconnect Wi-Fi after it disconnected?

Call esp_wifi_connect after received the WIFI_EVENT_STA_DISCONNECTED event.


[Connect] When does ESP32 disconnect from SoftAP in station mode?

By default, the ESP32 will disconnect from the AP if it does not receive any beacon for 6 s. This time can be modified via esp_wifi_set_inactive_time.


[Scan] Why does the STA cannot find any AP sometimes during the scanning?

Generally, it is because the AP is too far away from the STA. Sometimes this can also be caused by inappropriate configurations of the scanning parameters.


[Scan] What is the maximum number of APs that can be scanned?

There is no limit to the maximum number of APs that can be scanned. The number depends on how many APs are around and configurations of the scanning parameters, such as the time spent on each channel, the longer time spent on each channel the more likely it is to find all the APs.


[Scan] Can I choose to connect the best AP when there are multiple APs with identical ssid/password during the scan?

By default, the scan type is WIFI_FAST_SCAN, which makes the STA always connects the first AP during the scan. If you expect to connect the best AP, please set scan_method to WIFI_ALL_CHANNEL_SCAN and configure sort_method to determine whether to choose the AP with the strongest RSSI or connect to the most secure AP.


[Scan] How to configure scan_method in the wifi_sta_config_t structure? What is the difference between all_channel_scan and fast_scan?

all_channel_scan and fast_scan are used to find the appropriate AP before connecting. The scan_method is set to fast_scan by default, which is mainly used together with threshold to filter APs with weak signal or encryption.

  • When fast_scan is set, the STA will stop scanning once it finds the first matched AP and then connect to it, so as to save time for connection.

  • When all_channel_scan is set, the STA will scan all channels and store four APs with the best signal or the most secure encryption according to the sorting method configured in sort_method. After the scan is completed, the STA will connect one of the four APs with the best signal or the most secure encryption.


[LWIP] How to get error code of the socket?

  • For ESP-IDF v4.0 and later versions: use the value of errno directly to get the error code after the socket API returns failure.

  • For previous versions of ESP-IDF v4.0: call getsockopt(sockfd, SOL_SOCKET, SO_ERROR, …) to get the error code after the socket API returns failure, otherwise you may get wrong error code when multiple sockets operate simultaneously.


[LWIP] What is the default keep-alive time of TCP?

By default, a TCP keep-alive message will be sent every 75 seconds for 9 times if no TCP message is received for two consecutive hours. Then, if there is still no message received, the LWIP will disconnect from the TCP.

The keep-alive time can be configured via socket option.


[LWIP] What is the retransmission interval of TCP?

When ESP32 serves as the transmitter, the first retransmission interval is normally 2 ~ 3 s by default. Then, the next interval is determined by Jacoboson’s algorithm, which can be simply seen as a multiplication of 2.


[LWIP] What is the maximum number of sockets that can be created?

32 for most, and the default number is 10.


[Sleep] What kinds of sleeping mode does ESP32 have? What are the differences?

  • There are mainly three sleeping modes: Modem sleep, Light sleep and Deep sleep.

    • Modem sleep: the station WMM sleeping mode specified in the Wi-Fi protocol (the station sends NULL data frame to tell the AP to sleep or wake up). The Modem sleep mode is enabled automatically after the station connected to AP. After entering this mode, the RF block is disabled and the station stays connected with the AP. The Modem sleep mode will be disabled after the station disconnected from the AP. The ESP32 can also be configured to decrease the CPU’s clock frequency after entering Modem sleep mode to further reduce its current.

    • Light sleep: this is a station sleep mode based on Modem sleep mode. The difference between is that, besides for the RF block being disabled, the CPU will also be suspended in this mode. After exiting from Light sleep mode, the CPU continues to operate from where it stopped.

    • Deep sleep: a sleeping mode un-specified in the Wi-Fi protocol. During Deep sleep mode, all the blocks except for RTC is disabled, and the station cannot be connected to AP. After exiting from this mode, the whole system will restart to operate (similar to system restart).


[Sleep] Where to enable the speedstep function for ESP32 in modem sleep mode?

Go to menuconfig -> Component Config -> Power Management.


[Sleep] How low can the speedstep function go for ESP32 in modem sleep mode?

For now, the CPU clock can go down to as low as 40 MHz.


[Sleep] What affects the average current of ESP32 in modem sleep mode?

The main factors are: the core, the clock frequency and the percentage of idle time of the CPU, whether there is Wi-Fi data sent or received during the test, data sending or receiving frequency, the transmitting power of RF block, whether the time when the router sends beacon is accurate, whether there are peripheral modules working, and etc.


[Sleep] Why the average current measured in modem sleep mode is a bit high?

  • A lot of Wi-Fi data sent and received during the test. The more data there is, the less chance there will be for entering sleeping mode and the higher average current will be.

  • The time when the router sends out beacon is not accurate. The station needs to wake up and monitor the beacon regularly, thus it will wait longer if the beacon time is not accurate. In this way, the station has less time in sleeping mode and the average current will be high.

  • There are peripheral modules working during the test. Please close them before the test.

  • The station+SoftAP mode is enabled. During modem sleep state, the current will only be lower in station-only mode.


[Sleep] Why the average current measured in light sleep mode is a bit high?

Besides for the reasons listed in the last question, the possible reasons also could be:

  • The application layer code is running continuously, thus the CPU does not get chance to suspend.

  • The application layer has enabled ets timer or esp timer and the timeout interval is short, thus the CPU does not get chance to suspend.


Does ESP8266 support 802.11k/v/r protocol?

For now, the ESP8266 only supports 802.11k and 802.11v, please refer to example roaming.


[Connect] After the NONOS_SDK updated from version 2.1.0 to 2.2.2, why does the connecting time become longer?

Please update to version master, which has solved the incompatibility issue between the CCMP encryption and some APs.


How does ESP32 receive and transmit Wi-Fi 802.11 packets?

  • By using the following APIs:

esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
esp_wifi_set_promiscuous_rx_cb(wifi_sniffer_cb);
  • The abovementioned APIs are also used in the ESP-MDF project, please refer to mconfig_chain.


[Connect] The ESP32 and ESP8266 failed to connect to router, what could be the reasons?

  • Please check if the SSID or password is wrong.

  • There could be errors in different Chinese codes, so it is not recommended to use an SSID written in Chinese.

  • The settings of bssid_set. If the MAC address of the router does not need to be identified, the stationConf.bssid_set should be configured to 0.

  • It is recommended to define the wifi_config field in wifi_config_t using the static variable static.


[Connect] What kind of networking methods does ESP8266 have?

  • SmartConfig mode: using SmartConfig. The device scans feature pack in sniffer mode.

  • SoftAP mode: the device enables SoftAP and sends SSID and password after the phone connects to SoftAP and set up a stable TCP/UDP connection.

  • WPS mode: an additional button should be added on the device; or using the phone to enable WPS after it connected to SoftAP.


[Connect] What are the specifications of Wi-Fi parameters when using SmartConfig?

According to wifi spec, the SSID should not exceed 32 bytes and its password should not exceed 64 bytes.


[Connect] Does ESP8266 Wi-Fi support WAP2 enterprise-level encryption?


[Connect] What are the low-power modes for ESP32 to maintain its connection to Wi-Fi?

  • In such scenarios, the chip switches between Active mode and Modem-sleep mode automatically, making the power consumption also varies in these two modes.

  • The ESP32 supports Wi-Fi keep-alive in Light-sleep mode, and the auto wakeup interval is determined by the DTIM parameter.

  • Please find examples in ESP-IDF - > examples - > wifi - > power_save.


Do Espressif’s chips support WPA3?

  • ESP32 series: WPA3 is supported from esp-idf release/v4.1 and enabled by default. Go to menuconfig > Component config > Wi-Fi for configuration.

  • ESP8266: WPA3 is supported from the master branch of ESP8266_RTOS_SDK and enabled by default. Go to menuconfig > Component config > Wi-Fi for configuration.


[Connect] How does the device choose AP when there are multiple identical SSIDs in the current environment?

  • The device connects to the first scanned AP.

  • If you expect to sort APs by signal quality and etc., use the scan function to filter manually.

  • If you expect to connect to a specified AP, add BSSID information in connection parameters.


[Connect] Does ESP8266 have repeater solutions?

  • We have not officially released such application solutions yet.

  • For relay related applications, please find on github. The relay rates should be set basing on real tests.


What is ESP-NOW? What are its advantages and application scenarios?

  • ESP-NOW is a kind of connectionless Wi-Fi communication protocol that is defined by Espressif.

  • In ESP-NOW, application data is encapsulated in action frames from different vendors and then transmitted from one Wi-Fi device to another without a connection.

  • ESP-NOW is ideal for smart lights, remote control devices, sensors and other applications.


What is the retransmission time for ESP32’s data frame and management frame?Can this be configured?

The retransmission time is 31 and it can not be configured.


How to customize the hostname for ESP32?

  • Taking ESP-IDF V4.2 as an example, you can go to menuconfig > Component Config > LWIP > Local netif hostname, and type in the customized hostname.

  • There may be a slight difference on naming in different versions.


How to obtain 802.11 Wi-Fi packets?

Please refer to Wireshark User Guide in ESP-IDF Programming Guide.


Does ESP32 Wi-Fi support PMF (Protected Management Frames) and PFS (Perfect Forward Secrecy)?

The PMF is supported both in WPA2 and WPA3, and PFS is supported in WPA3.


How to get the RSSI of the connected AP for ESP32 IDF v4.1 Wi-Fi?

  • It can be obtained via scanning, please refer to example scan.

  • If there are multiple identical SSIDs in the current environment, you can get the AP’s bssid first after it connects to an AP and specify the bssid via wifi_scan_config_t, then get the RSSI by calling esp_wifi_scan_start().

    Code:

    //Obtain bssid via WIFI_EVENT_STA_CONNECTED in the callback function event_handler()
    else if(event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) {
    
            wifi_event_sta_connected_t* sta_connected_event = (wifi_event_sta_connected_t*) event_data;
            ESP_LOGI(TAG, "AP MAC:"MACSTR"", MAC2STR(sta_connected_event->bssid));
            ...
            //specify a bssid to perform scanning
            wifi_scan_config_t wifi_scan_config = {
                .bssid = sta_connected_event->bssid,
            };
            ESP_ERROR_CHECK(esp_wifi_scan_start(&wifi_scan_config, true));
            ...
    }
    

Why does ESP8266 print out an AES PN error log when using esptouch v2?

This occurs when ESP8266 has received retransmitted packets from the router for multiple times. However, this will not affect your usage.