How to change ESP32 Wifi bandwidth code, with CORRECTED code example.

in #esp323 years ago (edited)

When you are use esp32 as webserver via arduino IDE, it's default wifi bandwidth is set to 40Mhz
This will be undesirable for use cases inside packed building or crowded area because of frequency shortage.
I've been researched for this and found the information on the internet has some defects. (each different)

So I tried some hack, and finally find out how.

If you want to change esp32's wifi bandwidth 20Mhz, you should put this in you code.

  1. Include header
    #include <esp_wifi.h>

  2. Put this code somewhere below "WiFi.begin(ssid, password);" or "WiFi.softAP(ssid, password);" on your code (put after your wifi begin)

ESP_ERROR_CHECK_WITHOUT_ABORT(esp_wifi_set_bandwidth(WIFI_IF_AP, WIFI_BW_HT20)); //for AP mode
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW_HT20)); //for Station mode

Honestly, you probably need only one of these lines(AP or STA).
But as written, "WITHOUT_ABORT", it will work.
(In Case if you want more fine coding, delete the other one.)

This is valid for both ESP32-CAM-Ai thinker board and espressif ESP32-EYE board.(mines)

Probably yours too.
Good Luck!

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.029
BTC 63788.86
ETH 2476.31
USDT 1.00
SBD 2.66