Broadcast frame data rates (esp_wifi_config_80211_tx_rate question)

Strider
Posts: 1
Joined: Wed Jul 06, 2022 7:08 pm

Broadcast frame data rates (esp_wifi_config_80211_tx_rate question)

Postby Strider » Mon Jul 11, 2022 7:17 pm

Hello all,

I'm evaluating the ESP32 for a project, so I am new to the device (and Espressif). I've run the iperf test and things look fine for UDP unicast frames (40Mb/s+). When I send broadcast UDP frame (192.168.1.255) from the ESP32, the performance drops to less than 1Mb/s (no surprise). What I'd like to do is raise the minimum output data rate on the broadcast frames. I tried using:

esp_wifi_config_80211_tx_rate(WIFI_IF_AP, WIFI_PHY_RATE_54M));

but nothing seemed to change (and I'm not even sure it would do something for a frame not send with esp_wifi_80211_tx which seems to have a maximum length assigned to it).

So, is there a way to raise the base transmission rate for broadcast frame (total frame length 1514 bytes) from the ESP32? Or is esp_wifi_config_80211_tx_rate it and I'm missing something important?

Thanks!

My initialization code:

Code: Select all

void wifi_init_softap(void)
{
 
    // Initialize the IP stack 
    ESP_ERROR_CHECK(esp_netif_init());

    // Creates a "loop handler" that basically is used to register routines that 
    // respond to events from the WIFI module. Note that it is possible to create
    // other loop handlers for different components. 
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    // Creates default WIFI AP. Also returns a pointer the esp-netif instance of 
    // type esp_netif that we don't need here. 
    esp_netif_create_default_wifi_ap();

    // The macro WIFI_INIT_CONFIG_DEFAULT is a set of default configuration values. 
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();

    // Initialize WiFi Allocate resource for WiFi driver, such as WiFi control structure, 
    // RX/TX buffer, WiFi NVS structure etc. This WiFi also starts WiFi task.
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));

    // Register "wifi_event_handler" to handle any event that comes from the WiFi.
    ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
                                                        ESP_EVENT_ANY_ID,
                                                        &wifi_event_handler,
                                                        NULL,
                                                        NULL));

    // Data structure to handle Wifi identity setup
    wifi_config_t wifi_config = {
        .ap = {
            .ssid = TEST_ESP_WIFI_SSID,
            .ssid_len = strlen(TEST_ESP_WIFI_SSID),
            .channel = TEST_ESP_WIFI_CHANNEL,
            .password = TEST_ESP_WIFI_PASS,
            .max_connection = TEST_MAX_STA_CONN,
            .authmode = WIFI_AUTH_WPA_WPA2_PSK
        },
    };
    // If no password is set, force the authenication to OPEN. 
    if (strlen(TEST_ESP_WIFI_PASS) == 0) {
        wifi_config.ap.authmode = WIFI_AUTH_OPEN;
    }

    // Set sleep mode to none...
    esp_wifi_set_ps(WIFI_PS_NONE);

    // Use SRAM for packet storage
    ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM) );

    // Set the Wifi mode to AP
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));

    esp_wifi_config_80211_tx_rate(WIFI_IF_AP, WIFI_PHY_RATE_54M);

    // Configure the WiFi.
    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));


    // And start 'er up
    ESP_ERROR_CHECK(esp_wifi_start());

    // And log a status message
    ESP_LOGI(TAG, "wifi_init_softap finished. SSID:%s password:%s channel:%d",
             TEST_ESP_WIFI_SSID, TEST_ESP_WIFI_PASS, TEST_ESP_WIFI_CHANNEL);
}

Adrian
Posts: 6
Joined: Wed Mar 20, 2019 8:57 am

Re: Broadcast frame data rates (esp_wifi_config_80211_tx_rate question)

Postby Adrian » Wed Jul 20, 2022 12:05 pm

Hello,

I'm pretty sure that esp_wifi_config_80211_tx_rate only changes the TX rate of the function esp_wifi_80211_tx which you can use to send raw 802.11 frames.

Did you know that there is a esp_wifi_internal_set_fix_rate function? Its header is defined in components/esp_wifi/include/esp_private/wifi.h. You can use it the following way to enforce a fixed transmission rate:

Code: Select all

#include "esp_private/wifi.h"

void my_function() {
	// to enable fixed rate setting it to 802.11n, modulation coding scheme 3 you can use:
	esp_wifi_internal_set_fix_rate(ESP_IF_WIFI_STA, true, WIFI_PHY_RATE_MCS3_SGI);
	// to disable fixed rate:
	esp_wifi_internal_set_fix_rate(ESP_IF_WIFI_STA, false, 0);
}

And I recommend that you always check the returned error code of esp_wifi_internal_set_fix_rate.

Hope that helps.

Who is online

Users browsing this forum: Bing [Bot], MicroController and 148 guests