← index #6036PR #16225
Related · high · value 4.895
QUERY · ISSUE

ESP32 WiFi AP Channel Width

openby gigawattsopened 2020-05-13updated 2024-05-27
port-esp32

It seems when creating a WiFi AP, it defaults to a 40 MHz channel bandwidth.

import network
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid="TEST")
ap.config(authmode=0, channel=2)

In the above example, when viewing the broadcasted SSID with an Android app such as "Wifi Analyzer", shows "CH 2+6" and "2447 - 2407 = 40 MHz".

Is there a setting that can be changed to set this to 20 MHz, so it only uses one channel?

CANDIDATE · PULL REQUEST

esp32: Fix AP mode channel configuration.

mergedby projectgusopened 2024-11-13updated 2024-11-28
port-esp32

Summary

  • Seems at some point (probably following an ESP-IDF update), the channel setting code added in #8991 stopped working for the AP interface. This is because esp_wifi_config() is called after esp_wifi_set_channel(), the old channel gets re-configured and the AP doesn't change channels as expected.
  • For AP mode, calling esp_wifi_config() seems to be all that's needed to get desired behaviour. The Wi-Fi stack configures 40MHz bandwidth and selects the secondary channel based on the available channels.
  • However, the esp_wifi_set_channel() call is required in the particular case of ESP-NOW being used on the STA interface without an active connection to an AP. Testing suggests this is the only way to configure a particular channel in that case (unlike if the STA is associated to an AP, which means ESP-NOW has to use the same channel as the AP).
  • Make some docs updates regarding Wi-Fi channels, in particular the role of channels in ESP-NOW (which is pretty restricted, I think this is something that has changed in later ESP-IDF versions).

Closes #16165.

Testing

  • Added a multi-test for explicitly configuring the ESP-NOW channel. This test passed on master, and still passes in this PR with the channel fix.
  • Added a wlan multi-test for simple STA and AP behaviour. This test fails for esp32 in master as the AP chooses the wrong channel, and passes in this branch. Also tested on esp8266 port and CYW43 (RPI_PICO_W). CYW43 does not currently pass, but I have some fixes to submit separately so that it passes.

Trade-offs and Alternatives

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied