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.
This commit is contained in:
parent
93c45af256
commit
c24a3404c6
@ -149,6 +149,10 @@ static bool espWiFiStart(bool persistent){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_esp_wifi_started = true;
|
_esp_wifi_started = true;
|
||||||
|
system_event_t event;
|
||||||
|
event.event_id = SYSTEM_EVENT_WIFI_READY;
|
||||||
|
WiFiGenericClass::_eventCallback(nullptr, &event);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,6 +380,9 @@ void WiFiGenericClass::persistent(bool persistent)
|
|||||||
*/
|
*/
|
||||||
bool WiFiGenericClass::mode(wifi_mode_t m)
|
bool WiFiGenericClass::mode(wifi_mode_t m)
|
||||||
{
|
{
|
||||||
|
if (!_esp_wifi_started) {
|
||||||
|
wifiLowLevelInit(_persistent);
|
||||||
|
}
|
||||||
wifi_mode_t cm = getMode();
|
wifi_mode_t cm = getMode();
|
||||||
if(cm == WIFI_MODE_MAX){
|
if(cm == WIFI_MODE_MAX){
|
||||||
return false;
|
return false;
|
||||||
@ -383,6 +390,12 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
|
|||||||
if(cm == m) {
|
if(cm == m) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if(m){
|
||||||
|
espWiFiStart(_persistent);
|
||||||
|
} else {
|
||||||
|
return espWiFiStop();
|
||||||
|
}
|
||||||
|
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
err = esp_wifi_set_mode(m);
|
err = esp_wifi_set_mode(m);
|
||||||
if(err){
|
if(err){
|
||||||
@ -403,6 +416,7 @@ wifi_mode_t WiFiGenericClass::getMode()
|
|||||||
{
|
{
|
||||||
if(!wifiLowLevelInit(_persistent)){
|
if(!wifiLowLevelInit(_persistent)){
|
||||||
return WIFI_MODE_MAX;
|
return WIFI_MODE_MAX;
|
||||||
|
|
||||||
}
|
}
|
||||||
uint8_t mode;
|
uint8_t mode;
|
||||||
esp_wifi_get_mode((wifi_mode_t*)&mode);
|
esp_wifi_get_mode((wifi_mode_t*)&mode);
|
||||||
|
Loading…
Reference in New Issue
Block a user