2

I'm currently running my esp32 wroom as Access Point to stream UDP packets (~100 packets per second, 1Ko per packet) to different smartphones. At close range, I lost about 30% of the packets at steady rate. It not unusual to lose packets with UDP protocol however this issue happens only with some specific and quite recent smartphones. After some Wireshark investigations of the Wifi messages, I observe that this packet loss is happening only for smartphones using IEEE 802.11 Power Save mecanism. There are plenty of options regarding Power saving mode in ESP 32 configuration and I suspect that I may have misconfigured the ESP32.

Do you have an idea of what could cause the problem ?

Thanks

I'm sharing with you the ESP32 configuration:

#
# Wi-Fi
#

CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=16
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=64
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y
# CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER is not set
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=32
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP32_WIFI_TX_BA_WIN=32
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP32_WIFI_RX_BA_WIN=32
CONFIG_ESP32_WIFI_NVS_ENABLED=y
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
# CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE is not set
CONFIG_ESP32_WIFI_IRAM_OPT=y
CONFIG_ESP32_WIFI_RX_IRAM_OPT=y
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
# CONFIG_ESP_WIFI_SLP_IRAM_OPT is not set
# CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is not set
# end of Wi-Fi

see the Access point initialization code:

esp_err_t COM_wifi_access_point_start(void) 
    {    
    esp_err_t esp_err;
    
    do  {
        
        // Initialization of the physical WiFi port
        tcpip_adapter_init();

        // Shutdown of the DHCP server before reprogramming the IP address of the probe
        BREAK_ON_ERR( esp_err = tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP) );

        // Initialization of the structure containing the IP address of the probe
        tcpip_adapter_ip_info_t ip_info;
        IP4_ADDR(&ip_info.ip,EPF_IPV4_IP_ADDR_1,EPF_IPV4_IP_ADDR_2,EPF_IPV4_IP_ADDR_3,EPF_IPV4_IP_ADDR_4);
        IP4_ADDR(&ip_info.gw,EPF_IPV4_GW_ADDR_1,EPF_IPV4_GW_ADDR_2,EPF_IPV4_GW_ADDR_3,EPF_IPV4_GW_ADDR_4);
        IP4_ADDR(&ip_info.netmask,EPF_IPV4_NM_ADDR_1,EPF_IPV4_NM_ADDR_2,EPF_IPV4_NM_ADDR_3,EPF_IPV4_NM_ADDR_4);

        // The new IP address is applied
        BREAK_ON_ERR( esp_err = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &ip_info) );

        // Restarting the DHCP server
        BREAK_ON_ERR( esp_err = tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP) );

        // Connecting the IT WiFi handler
        BREAK_ON_ERR( esp_err = esp_event_loop_init(wifi_event_handler, NULL) );

        // Initialization of the WiFi driver to the default configuration
        wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
        BREAK_ON_ERR( esp_err = esp_wifi_init(&wifi_init_config) );

        // The driver is told to store all WiFi configuration in RAM
        // => We don't always write the configuration in flash each time
        BREAK_ON_ERR( esp_err = esp_wifi_set_storage(WIFI_STORAGE_RAM) );

        // Switching from the default connection mode to Access Point mode
        BREAK_ON_ERR( esp_err = esp_wifi_set_mode(WIFI_MODE_AP) );

        // The desired configuration is applied to the WiFi driver
        wifi_config_t ap_config =
            {
            .ap =
                {
                .ssid           = "",
                .channel        = EPF_WIFI_CHANNEL_NUMBER,
                .password       = EPF_WIFI_PASSWORD,
                .authmode       = WIFI_AUTH_WPA_WPA2_PSK,
                .ssid_hidden    = COM_WIFI_BROADCAST,                               // SSID in broadcast mode => Non-hidden network
                .max_connection = EPF_WIFI_NB_CONNECTION,                           // Only one connection allowed simultaneously
                .beacon_interval= COM_WIFI_BEACON_INT
                }
            };
        sprintf((char*)ap_config.ap.ssid, EPF_WIFI_SSID_TMPL, PAR_get_live_raw_fast(EPF_MAI_PROBE_SERIAL_NB) );
        
        BREAK_ON_ERR( esp_err = esp_wifi_set_config(WIFI_IF_AP, &ap_config) );

        // Starting WiFi
        // After calling this function, the access point is visible from remote WiFi devices
        BREAK_ON_ERR( esp_err = esp_wifi_start() );

        // Renaming the hostname
        BREAK_ON_ERR( esp_err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_AP, COM_LOCALHOSTNAME) );
        
        esp_err = ESP_OK;
        
        } while(0);

    return esp_err;
    }

1 Answers1

1

The ESP32-s WiFi power saving is enabled by default. You can disable it with a call to esp_wifi_set_ps(WIFI_PS_NONE); - see if it works for you. I've had to turn it off after I saw significant ICMP packet loss under load.

Tarmo
  • 3,728
  • 1
  • 8
  • 25
  • I tried using `esp_wifi_set_ps(WIFI_PS_NONE)` but it didn't seems to work. I'm still watching Power management request from the smartphone when I looked at the Wifi frame with Wireshark. – magic_streamer Sep 03 '21 at 15:25