← index #6036PR #11493
Related · high · value 0.819
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/network_wlan.c: Bugfix: WLAN.config(channel=x) triggers reset.

closedby glenn20opened 2023-05-14updated 2023-06-26
port-esp32

Implements a fix for Issue #11491: WLAN.config(channel=X) triggers device reset if interface is not active(). The bug was introduced in PR #8991.

Eg. this code will trigger a device reset:

import network
ap = network.WLAN(network.STA_AP)
ap.config(channel=6)

The underlying cause is a bug in esp_wifi_set_channel() which triggers the device reset if wifi has not been started.

This fix:

  • If wifi is not started, set the wifi channel in the interface configuration struct (cfg.{ap,sta}.channel) (as was the case pre #8991).
  • If wifi is started: set channel with esp_wifi_set_channel().
  • WLAN.config('channel') also returns channel from cfg.{ap,sta}.channel if wifi is not started (for consistency).

This maintains backward compatibility with micropython pre-v1.20.0.

An alternative fix is to insert the following guard statement:

                   if (!wifi_started) {
                       esp_exceptions(ESP_ERR_WIFI_NOT_STARTED);
                   }

which has reduced code overhead and behaves equivalently to the 'txpower', 'protocol' and 'pm' config options, but is not backward compatible with allowed usage pre #8991.

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