Skip to content

Commit 1e4cbdd

Browse files
author
blue-2357
committed
Add SYSTEM_EVENT_WIFI_READY call back + WiFiMode fixes (#1322)
* 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/arduino-esp32#1306 * make changes compatible with new _persistent behaviour.
1 parent db36e2b commit 1e4cbdd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ static bool espWiFiStart(bool persistent){
149149
return false;
150150
}
151151
_esp_wifi_started = true;
152+
system_event_t event;
153+
event.event_id = SYSTEM_EVENT_WIFI_READY;
154+
WiFiGenericClass::_eventCallback(nullptr, &event);
155+
152156
return true;
153157
}
154158

@@ -376,13 +380,22 @@ void WiFiGenericClass::persistent(bool persistent)
376380
*/
377381
bool WiFiGenericClass::mode(wifi_mode_t m)
378382
{
383+
if (!_esp_wifi_started) {
384+
wifiLowLevelInit(_persistent);
385+
}
379386
wifi_mode_t cm = getMode();
380387
if(cm == WIFI_MODE_MAX){
381388
return false;
382389
}
383390
if(cm == m) {
384391
return true;
385392
}
393+
if(m){
394+
espWiFiStart(_persistent);
395+
} else {
396+
return espWiFiStop();
397+
}
398+
386399
esp_err_t err;
387400
err = esp_wifi_set_mode(m);
388401
if(err){
@@ -403,6 +416,7 @@ wifi_mode_t WiFiGenericClass::getMode()
403416
{
404417
if(!wifiLowLevelInit(_persistent)){
405418
return WIFI_MODE_MAX;
419+
406420
}
407421
uint8_t mode;
408422
esp_wifi_get_mode((wifi_mode_t*)&mode);

0 commit comments

Comments
 (0)