Skip to content

Instantly share code, notes, and snippets.

@oldmud0
Last active June 19, 2024 17:13
Show Gist options
  • Save oldmud0/4946228fc2e279932d06b32e0e23968d to your computer and use it in GitHub Desktop.
Save oldmud0/4946228fc2e279932d06b32e0e23968d to your computer and use it in GitHub Desktop.

Revisions

  1. oldmud0 revised this gist Jun 19, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions wifi.cpp
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    constexpr auto WIFI_CHANNEL = 9; // Find a relatively quiet channel
    constexpr auto WIFI_DATA_RATE = WIFI_PHY_RATE_24M;

    void initFastWifi() {
    // Set up Wi-Fi with a faster data rate by disabling AMPDU
  2. oldmud0 created this gist Jun 19, 2024.
    23 changes: 23 additions & 0 deletions wifi.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@

    void initFastWifi() {
    // Set up Wi-Fi with a faster data rate by disabling AMPDU
    // and setting a very fast fixed rate.
    // https://www.esp32.com/viewtopic.php?t=9965
    // We also need delays to work around races between each step:
    // https://esp32.com/viewtopic.php?t=2512
    WiFi.disconnect();
    vTaskDelay(100 / portTICK_RATE_MS);
    WiFi.mode(WIFI_STA);
    vTaskDelay(100 / portTICK_RATE_MS);
    ESP_ERROR_CHECK(esp_wifi_stop());
    vTaskDelay(100 / portTICK_RATE_MS);
    ESP_ERROR_CHECK(esp_wifi_deinit());
    vTaskDelay(100 / portTICK_RATE_MS);
    wifi_init_config_t initConfig = WIFI_INIT_CONFIG_DEFAULT();
    initConfig.ampdu_tx_enable = false;
    ESP_ERROR_CHECK(esp_wifi_init(&initConfig));
    ESP_ERROR_CHECK(esp_wifi_start());
    ESP_ERROR_CHECK(esp_wifi_set_channel(WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE));
    ESP_ERROR_CHECK(esp_wifi_internal_set_fix_rate(WIFI_IF_STA, true, WIFI_DATA_RATE));
    ESP_ERROR_CHECK(esp_now_init());
    }