Skip to content

Commit ac1c001

Browse files
Added WiFi Bandwidth Setting Methods for AP and STA modes. (#7619)
* Added Bandwith setting method * Separted AP and STA on it's own class each * Missing WiFi * Rename for consistency --------- Co-authored-by: Me No Dev <[email protected]>
1 parent 990e3d5 commit ac1c001

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

Diff for: libraries/WiFi/src/WiFiAP.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,25 @@ bool WiFiAPClass::softAPdisconnect(bool wifioff)
235235
return ret;
236236
}
237237

238+
/**
239+
* Sets the working bandwidth of the AP mode
240+
* @param m wifi_bandwidth_t
241+
*/
242+
bool WiFiAPClass::softAPbandwidth(wifi_bandwidth_t bandwidth) {
243+
if(!WiFi.enableAP(true)) {
244+
log_e("AP enable failed!");
245+
return false;
246+
}
247+
248+
esp_err_t err;
249+
err = esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_AP, bandwidth);
250+
if(err){
251+
log_e("Could not set AP bandwidth!");
252+
return false;
253+
}
254+
255+
return true;
256+
}
238257

239258
/**
240259
* Get the count of the Station / client that are connected to the softAP interface

Diff for: libraries/WiFi/src/WiFiAP.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class WiFiAPClass
4545
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = (uint32_t) 0);
4646
bool softAPdisconnect(bool wifioff = false);
4747

48+
bool softAPbandwidth(wifi_bandwidth_t bandwidth);
49+
4850
uint8_t softAPgetStationNum();
4951

5052
IPAddress softAPIP();

Diff for: libraries/WiFi/src/WiFiGeneric.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,6 @@ int32_t WiFiGenericClass::channel(void)
12251225
return primaryChan;
12261226
}
12271227

1228-
12291228
/**
12301229
* store WiFi config in SDK flash area
12311230
* @param persistent

Diff for: libraries/WiFi/src/WiFiSTA.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,26 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
431431
return err == ESP_OK;
432432
}
433433

434+
/**
435+
* Sets the working bandwidth of the STA mode
436+
* @param m wifi_bandwidth_t
437+
*/
438+
bool WiFiSTAClass::bandwidth(wifi_bandwidth_t bandwidth) {
439+
if(!WiFi.enableSTA(true)) {
440+
log_e("STA enable failed!");
441+
return false;
442+
}
443+
444+
esp_err_t err;
445+
err = esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, bandwidth);
446+
if(err){
447+
log_e("Could not set STA bandwidth!");
448+
return false;
449+
}
450+
451+
return true;
452+
}
453+
434454
/**
435455
* Change DNS server for static IP configuration
436456
* @param dns1 Static DNS server 1

Diff for: libraries/WiFi/src/WiFiSTA.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class WiFiSTAClass
5858
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
5959
bool setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000); // sets DNS IP for all network interfaces
6060

61+
bool bandwidth(wifi_bandwidth_t bandwidth);
62+
6163
bool reconnect();
6264
bool disconnect(bool wifioff = false, bool eraseap = false);
6365
bool eraseAP(void);

0 commit comments

Comments
 (0)