Skip to content

Commit df5e82b

Browse files
committed
Add SYSTEM_EVENT_WIFI_READY call back once wifi service is init. allows you to hook in, as the sdk does not generate this event for you.
As it stands the SDK does not appear to set `WIFI_MODE_NULL` correctly. if the wifi is initialised and set to `WIFI_MODE_NULL` it actually defaults to AP mode. This fix keeps `WIFI_MODE_NULL` within the ESP class if the wifi has not been init yet, and works in my testing. albeit a one sided conversation. espressif#1306
1 parent c92b617 commit df5e82b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

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

+17-6
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ static bool espWiFiStart(){
147147
return false;
148148
}
149149
_esp_wifi_started = true;
150+
system_event_t event;
151+
event.event_id = SYSTEM_EVENT_WIFI_READY;
152+
WiFiGenericClass::_eventCallback(nullptr, &event);
153+
150154
return true;
151155
}
152156

@@ -369,23 +373,30 @@ void WiFiGenericClass::persistent(bool persistent)
369373
*/
370374
bool WiFiGenericClass::mode(wifi_mode_t m)
371375
{
376+
if (!_esp_wifi_started) {
377+
wifiLowLevelInit();
378+
}
372379
wifi_mode_t cm = getMode();
373380
if(cm == WIFI_MODE_MAX){
374381
return false;
375382
}
376383
if(cm == m) {
377384
return true;
378385
}
386+
if(m){
387+
espWiFiStart();
388+
} else {
389+
return espWiFiStop();
390+
}
391+
379392
esp_err_t err;
380393
err = esp_wifi_set_mode(m);
381394
if(err){
382395
log_e("Could not set mode! %u", err);
383396
return false;
384397
}
385-
if(m){
386-
return espWiFiStart();
387-
}
388-
return espWiFiStop();
398+
return true;
399+
389400
}
390401

391402
/**
@@ -394,8 +405,8 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
394405
*/
395406
wifi_mode_t WiFiGenericClass::getMode()
396407
{
397-
if(!wifiLowLevelInit()){
398-
return WIFI_MODE_MAX;
408+
if(!_esp_wifi_started){
409+
return WIFI_MODE_NULL;
399410
}
400411
uint8_t mode;
401412
esp_wifi_get_mode((wifi_mode_t*)&mode);

0 commit comments

Comments
 (0)