@@ -378,6 +378,10 @@ static bool espWiFiStart() {
378
378
log_e (" esp_wifi_start 0x%x: %s" , err, esp_err_to_name (err));
379
379
return _esp_wifi_started;
380
380
}
381
+ #if SOC_WIFI_SUPPORT_5G
382
+ log_v (" Setting Band Mode to AUTO" );
383
+ esp_wifi_set_band_mode (WIFI_BAND_MODE_AUTO);
384
+ #endif
381
385
return _esp_wifi_started;
382
386
}
383
387
@@ -729,6 +733,90 @@ wifi_ps_type_t WiFiGenericClass::getSleep() {
729
733
return _sleepEnabled;
730
734
}
731
735
736
+ /* *
737
+ * control wifi band mode
738
+ * @param band_mode enum possible band modes
739
+ * @return ok
740
+ */
741
+ bool WiFiGenericClass::setBandMode (wifi_band_mode_t band_mode) {
742
+ #if SOC_WIFI_SUPPORT_5G
743
+ if (!WiFi.STA .started () && !WiFi.AP .started ()) {
744
+ log_e (" You need to start WiFi first" );
745
+ return false ;
746
+ }
747
+ wifi_band_mode_t bm = WIFI_BAND_MODE_AUTO;
748
+ esp_err_t err = esp_wifi_get_band_mode (&bm);
749
+ if (err != ESP_OK) {
750
+ log_e (" Failed to get Current Band Mode: 0x%x: %s" , err, esp_err_to_name (err));
751
+ return false ;
752
+ } else if (bm == band_mode) {
753
+ log_d (" No change in Band Mode" );
754
+ return true ;
755
+ } else {
756
+ log_d (" Switching Band Mode from %d to %d" , bm, band_mode);
757
+ }
758
+ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
759
+ if (WiFi.STA .connected () || WiFi.AP .connected ()) {
760
+ log_e (" Your network will get disconnected!" );
761
+ }
762
+ #endif
763
+ err = esp_wifi_set_band_mode (band_mode);
764
+ if (err != ESP_OK) {
765
+ log_e (" Failed to set Band Mode: 0x%x: %s" , err, esp_err_to_name (err));
766
+ return false ;
767
+ }
768
+ delay (100 );
769
+ return true ;
770
+ #else
771
+ if (band_mode == WIFI_BAND_MODE_5G_ONLY) {
772
+ log_e (" This chip supports only 2.4GHz WiFi" );
773
+ }
774
+ return band_mode != WIFI_BAND_MODE_5G_ONLY;
775
+ #endif
776
+ }
777
+
778
+ /* *
779
+ * get the current enabled wifi band mode
780
+ * @return enum band mode
781
+ */
782
+ wifi_band_mode_t WiFiGenericClass::getBandMode () {
783
+ #if SOC_WIFI_SUPPORT_5G
784
+ wifi_band_mode_t band_mode = WIFI_BAND_MODE_AUTO;
785
+ if (!WiFi.STA .started () && !WiFi.AP .started ()) {
786
+ log_e (" You need to start WiFi first" );
787
+ return band_mode;
788
+ }
789
+ esp_err_t err = esp_wifi_get_band_mode (&band_mode);
790
+ if (err != ESP_OK) {
791
+ log_e (" Failed to get Band Mode: 0x%x: %s" , err, esp_err_to_name (err));
792
+ }
793
+ return band_mode;
794
+ #else
795
+ return WIFI_BAND_MODE_2G_ONLY;
796
+ #endif
797
+ }
798
+
799
+ /* *
800
+ * get the current active wifi band
801
+ * @return enum band
802
+ */
803
+ wifi_band_t WiFiGenericClass::getBand () {
804
+ #if SOC_WIFI_SUPPORT_5G
805
+ wifi_band_t band = WIFI_BAND_2G;
806
+ if (!WiFi.STA .started () && !WiFi.AP .started ()) {
807
+ log_e (" You need to start WiFi first" );
808
+ return band;
809
+ }
810
+ esp_err_t err = esp_wifi_get_band (&band);
811
+ if (err != ESP_OK) {
812
+ log_e (" Failed to get Band: 0x%x: %s" , err, esp_err_to_name (err));
813
+ }
814
+ return band;
815
+ #else
816
+ return WIFI_BAND_2G;
817
+ #endif
818
+ }
819
+
732
820
/* *
733
821
* control wifi tx power
734
822
* @param power enum maximum wifi tx power
0 commit comments