Crate esp_wifi

Source
Expand description

This documentation is built for the ESP32-C3 . Please ensure you are reading the correct documentation for your target device.

§Usage

§Importing

Ensure that the right features are enabled for your chip. See Examples for more examples.

[dependencies.esp-wifi]
# A supported chip needs to be specified, as well as specific use-case features
features = ["esp32s3", "wifi", "esp-now"]

§Optimization Level

It is necessary to build with optimization level 2 or 3 since otherwise, it might not even be able to connect or advertise.

To make it work also for your debug builds add this to your Cargo.toml

[profile.dev.package.esp-wifi]
opt-level = 3

§Globally disable logging

esp-wifi contains a lot of trace-level logging statements. For maximum performance you might want to disable logging via a feature flag of the log crate. See documentation. You should set it to release_max_level_off.

§Xtensa considerations

Within this crate, CCOMPARE0 CPU timer is used for timing, ensure that in your application you are not using this CPU timer.

§Features flags

Note that not all features are available on every MCU. For example, ble (and thus, coex) is not available on ESP32-S2.

When using the dump_packets config you can use the extcap in extras/esp-wifishark to analyze the frames in Wireshark. For more information see extras/esp-wifishark/README.md

  • esp-alloc (enabled by default) — Use esp-alloc for dynamic allocations.

    If you opt-out you need to provide implementations for pub extern "C" fn esp_wifi_free_internal_heap() -> usize and pub extern "C" fn esp_wifi_allocate_from_internal_ram(size: usize) -> *mut u8

  • coex — Enable WiFi-BLE coexistence support

  • sys-logs — Logs the WiFi logs from the driver at log level info (needs a nightly-compiler)

  • defmt — Enable support for defmt

  • log — Enable support for the log crate

  • wifi — Enable WiFi support

  • esp-now — Enable esp-now support

  • sniffer — Enable sniffer mode support

  • ble — Enable BLE support

  • smoltcp — Provide implementations of smoltcp traits

  • utils — Provide utilities for smoltcp initialization. Adds smoltcp dependency

§Additional configuration

We’ve exposed some configuration options that don’t fit into cargo features. These can be set via environment variables, or via cargo’s [env] section inside .cargo/config.toml. Below is a table of tunable parameters for this crate:

NameDescriptionDefault value
ESP_WIFI_RX_QUEUE_SIZESize of the RX queue in frames5
ESP_WIFI_TX_QUEUE_SIZESize of the TX queue in frames3
ESP_WIFI_STATIC_RX_BUF_NUMWiFi static RX buffer number. See ESP-IDF Programming Guide10
ESP_WIFI_DYNAMIC_RX_BUF_NUMWiFi dynamic RX buffer number. See ESP-IDF Programming Guide32
ESP_WIFI_STATIC_TX_BUF_NUMWiFi static TX buffer number. See ESP-IDF Programming Guide0
ESP_WIFI_DYNAMIC_TX_BUF_NUMWiFi dynamic TX buffer number. See ESP-IDF Programming Guide32
ESP_WIFI_CSI_ENABLEWiFi channel state information enable flag. See ESP-IDF Programming Guidefalse
ESP_WIFI_AMPDU_RX_ENABLEWiFi AMPDU RX feature enable flag. See ESP-IDF Programming Guidetrue
ESP_WIFI_AMPDU_TX_ENABLEWiFi AMPDU TX feature enable flag. See ESP-IDF Programming Guidetrue
ESP_WIFI_AMSDU_TX_ENABLEWiFi AMSDU TX feature enable flag. See ESP-IDF Programming Guidefalse
ESP_WIFI_RX_BA_WINWiFi Block Ack RX window size. See ESP-IDF Programming Guide6
ESP_WIFI_MAX_BURST_SIZESee smoltcp’s documentation1
ESP_WIFI_COUNTRY_CODECountry code. See ESP-IDF Programming GuideCN
ESP_WIFI_COUNTRY_CODE_OPERATING_CLASSIf not 0: Operating Class table number. See ESP-IDF Programming Guide0
ESP_WIFI_MTUMTU, see smoltcp’s documentation1492
ESP_WIFI_TICK_RATE_HZTick rate of the internal task scheduler in hertz100
ESP_WIFI_LISTEN_INTERVALInterval for station to listen to beacon from AP. The unit of listen interval is one beacon interval. For example, if beacon interval is 100 ms and listen interval is 3, the interval for station to listen to beacon is 300 ms3
ESP_WIFI_BEACON_TIMEOUTFor Station, If the station does not receive a beacon frame from the connected SoftAP during the inactive time, disconnect from SoftAP. Default 6s. Range 6-306
ESP_WIFI_AP_BEACON_TIMEOUTFor SoftAP, If the SoftAP doesn’t receive any data from the connected STA during inactive time, the SoftAP will force deauth the STA. Default is 300s300
ESP_WIFI_FAILURE_RETRY_CNTNumber of connection retries station will do before moving to next AP. scan_method should be set as WIFI_ALL_CHANNEL_SCAN to use this config. Note: Enabling this may cause connection time to increase incase best AP doesn’t behave properly. Defaults to 11
ESP_WIFI_SCAN_METHOD0 = WIFI_FAST_SCAN, 1 = WIFI_ALL_CHANNEL_SCAN, defaults to 00
ESP_WIFI_DUMP_PACKETSDump packets via an info log statementfalse
ESP_WIFI_PHY_ENABLE_USBKeeps USB running when using WiFi. This allows debugging and log messages via USB Serial JTAG. Turn off for best WiFi performance.true

It’s important to note that due to a bug in cargo, any modifications to the environment, local or otherwise will only get picked up on a full clean build of the project.

Modules§

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

Structs§

Enums§

Traits§

Functions§

  • Deinitializes the entire radio stack
  • Initialize for using WiFi and or BLE.
  • Enable verbose logging within the WiFi driver Does nothing unless the sys-logs feature is enabled.