Commit c24a3404 authored by sticilface's avatar sticilface Committed by Me No Dev

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.
https://github.com/espressif/arduino-esp32/issues/1306

* make changes compatible with new _persistent behaviour.
parent 93c45af2
......@@ -149,6 +149,10 @@ static bool espWiFiStart(bool persistent){
return false;
}
_esp_wifi_started = true;
system_event_t event;
event.event_id = SYSTEM_EVENT_WIFI_READY;
WiFiGenericClass::_eventCallback(nullptr, &event);
return true;
}
......@@ -376,6 +380,9 @@ void WiFiGenericClass::persistent(bool persistent)
*/
bool WiFiGenericClass::mode(wifi_mode_t m)
{
if (!_esp_wifi_started) {
wifiLowLevelInit(_persistent);
}
wifi_mode_t cm = getMode();
if(cm == WIFI_MODE_MAX){
return false;
......@@ -383,6 +390,12 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
if(cm == m) {
return true;
}
if(m){
espWiFiStart(_persistent);
} else {
return espWiFiStop();
}
esp_err_t err;
err = esp_wifi_set_mode(m);
if(err){
......@@ -403,6 +416,7 @@ wifi_mode_t WiFiGenericClass::getMode()
{
if(!wifiLowLevelInit(_persistent)){
return WIFI_MODE_MAX;
}
uint8_t mode;
esp_wifi_get_mode((wifi_mode_t*)&mode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment