Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cda6fac

Browse files
committed
Disable modem sleep by default on S2 for now.
1 parent eccbfdb commit cda6fac

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,13 @@ static std::vector<WiFiEventCbList_t> cbEventList;
619619
bool WiFiGenericClass::_persistent = true;
620620
bool WiFiGenericClass::_long_range = false;
621621
wifi_mode_t WiFiGenericClass::_forceSleepLastMode = WIFI_MODE_NULL;
622+
#if CONFIG_IDF_TARGET_ESP32S2
623+
wifi_ps_type_t WiFiGenericClass::_sleepEnabled = WIFI_PS_NONE;
624+
#else
625+
wifi_ps_type_t WiFiGenericClass::_sleepEnabled = WIFI_PS_MIN_MODEM;
626+
#endif
622627

623-
WiFiGenericClass::WiFiGenericClass()
628+
WiFiGenericClass::WiFiGenericClass()
624629
{
625630

626631
}
@@ -789,6 +794,9 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event)
789794
} else if(event->event_id == ARDUINO_EVENT_WIFI_STA_START) {
790795
WiFiSTAClass::_setStatus(WL_DISCONNECTED);
791796
setStatusBits(STA_STARTED_BIT);
797+
if(esp_wifi_set_ps(_sleepEnabled) != ESP_OK){
798+
log_e("esp_wifi_set_ps failed");
799+
}
792800
} else if(event->event_id == ARDUINO_EVENT_WIFI_STA_STOP) {
793801
WiFiSTAClass::_setStatus(WL_NO_SHIELD);
794802
clearStatusBits(STA_STARTED_BIT | STA_CONNECTED_BIT | STA_HAS_IP_BIT | STA_HAS_IP6_BIT);
@@ -1053,30 +1061,31 @@ bool WiFiGenericClass::enableAP(bool enable)
10531061
* @param enable bool
10541062
* @return ok
10551063
*/
1056-
bool WiFiGenericClass::setSleep(bool enable)
1064+
bool WiFiGenericClass::setSleep(bool enabled){
1065+
return setSleep(enabled?WIFI_PS_MIN_MODEM:WIFI_PS_NONE);
1066+
}
1067+
1068+
bool WiFiGenericClass::setSleep(wifi_ps_type_t sleepType)
10571069
{
1058-
if((getMode() & WIFI_MODE_STA) == 0){
1059-
log_w("STA has not been started");
1060-
return false;
1070+
if(sleepType != _sleepEnabled){
1071+
_sleepEnabled = sleepType;
1072+
if((getMode() & WIFI_MODE_STA) != 0){
1073+
if(esp_wifi_set_ps(_sleepEnabled) != ESP_OK){
1074+
log_e("esp_wifi_set_ps failed!");
1075+
}
1076+
}
1077+
return true;
10611078
}
1062-
return esp_wifi_set_ps(enable?WIFI_PS_MIN_MODEM:WIFI_PS_NONE) == ESP_OK;
1079+
return false;
10631080
}
10641081

10651082
/**
10661083
* get modem sleep enabled
10671084
* @return true if modem sleep is enabled
10681085
*/
1069-
bool WiFiGenericClass::getSleep()
1086+
wifi_ps_type_t WiFiGenericClass::getSleep()
10701087
{
1071-
wifi_ps_type_t ps;
1072-
if((getMode() & WIFI_MODE_STA) == 0){
1073-
log_w("STA has not been started");
1074-
return false;
1075-
}
1076-
if(esp_wifi_get_ps(&ps) == ESP_OK){
1077-
return ps == WIFI_PS_MIN_MODEM;
1078-
}
1079-
return false;
1088+
return _sleepEnabled;
10801089
}
10811090

10821091
/**

libraries/WiFi/src/WiFiGeneric.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ class WiFiGenericClass
163163
bool enableSTA(bool enable);
164164
bool enableAP(bool enable);
165165

166-
bool setSleep(bool enable);
167-
bool getSleep();
166+
bool setSleep(bool enabled);
167+
bool setSleep(wifi_ps_type_t sleepType);
168+
wifi_ps_type_t getSleep();
168169

169170
bool setTxPower(wifi_power_t power);
170171
wifi_power_t getTxPower();
@@ -178,10 +179,11 @@ class WiFiGenericClass
178179
static bool _persistent;
179180
static bool _long_range;
180181
static wifi_mode_t _forceSleepLastMode;
182+
static wifi_ps_type_t _sleepEnabled;
181183

182184
static int setStatusBits(int bits);
183185
static int clearStatusBits(int bits);
184-
186+
185187
public:
186188
static int hostByName(const char *aHostname, IPAddress &aResult);
187189

0 commit comments

Comments
 (0)