ESP32 WiFi AP Channel Width
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?
esp32/network_wlan.c: Bugfix: WLAN.config(channel=x) triggers reset.
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 fromcfg.{ap,sta}.channelif 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.