Skip to content

Commit bc10ad0

Browse files
committed
Updates to WiFi logic to allow mode to work correctly.
espressif#1306
1 parent 1da3138 commit bc10ad0

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,23 +369,32 @@ void WiFiGenericClass::persistent(bool persistent)
369369
*/
370370
bool WiFiGenericClass::mode(wifi_mode_t m)
371371
{
372+
if (!_esp_wifi_started) {
373+
wifiLowLevelInit();
374+
}
372375
wifi_mode_t cm = getMode();
373376
if(cm == WIFI_MODE_MAX){
374377
return false;
375378
}
376379
if(cm == m) {
377380
return true;
378381
}
382+
383+
if(m){
384+
espWiFiStart();
385+
} else {
386+
return espWiFiStop();
387+
}
388+
379389
esp_err_t err;
380390
err = esp_wifi_set_mode(m);
381391
if(err){
382392
log_e("Could not set mode! %u", err);
383393
return false;
384394
}
385-
if(m){
386-
return espWiFiStart();
387-
}
388-
return espWiFiStop();
395+
396+
return true;
397+
389398
}
390399

391400
/**
@@ -394,8 +403,12 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
394403
*/
395404
wifi_mode_t WiFiGenericClass::getMode()
396405
{
397-
if(!wifiLowLevelInit()){
398-
return WIFI_MODE_MAX;
406+
// if(!wifiLowLevelInit()){
407+
// return WIFI_MODE_MAX;
408+
// }
409+
if (!_esp_wifi_started)
410+
{
411+
return WIFI_MODE_NULL;
399412
}
400413
uint8_t mode;
401414
esp_wifi_get_mode((wifi_mode_t*)&mode);

0 commit comments

Comments
 (0)