Skip to content

Commit 455e998

Browse files
committed
Added ESP32 compatible methods for setting/getting sleep mode
1 parent e3fe7a5 commit 455e998

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h

+33
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,39 @@ class ESP8266WiFiGenericClass {
7777
uint8_t channel(void);
7878

7979
bool setSleepMode(WiFiSleepType_t type, uint8_t listenInterval = 0);
80+
/**
81+
* Set modem sleep mode (ESP32 compatibility)
82+
* @param enable true to enable
83+
* @return true if succeeded
84+
*/
85+
bool setSleep(bool enable)
86+
{
87+
if (enable)
88+
{
89+
return setSleepMode(WIFI_MODEM_SLEEP);
90+
}
91+
else
92+
{
93+
return setSleepMode(WIFI_NONE_SLEEP);
94+
}
95+
}
96+
/**
97+
* Set sleep mode (ESP32 compatibility)
98+
* @param mode wifi_ps_type_t
99+
* @return true if succeeded
100+
*/
101+
bool setSleep(wifi_ps_type_t mode)
102+
{
103+
return setSleepMode((WiFiSleepType_t)mode);
104+
}
105+
/**
106+
* Get current sleep state (ESP32 compatibility)
107+
* @return true if modem sleep is enabled
108+
*/
109+
bool getSleep()
110+
{
111+
return getSleepMode() == WIFI_MODEM_SLEEP;
112+
}
80113

81114
WiFiSleepType_t getSleepMode();
82115
uint8_t getListenInterval ();

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFiType.h

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ typedef enum WiFiSleepType
4848
WIFI_NONE_SLEEP = 0, WIFI_LIGHT_SLEEP = 1, WIFI_MODEM_SLEEP = 2
4949
} WiFiSleepType_t;
5050

51+
// ESP32 compatibility
52+
typedef enum wifi_ps_type
53+
{
54+
WIFI_PS_NONE = WIFI_NONE_SLEEP,
55+
WIFI_PS_MIN_MODEM = WIFI_MODEM_SLEEP,
56+
WIFI_PS_MAX_MODEM = WIFI_LIGHT_SLEEP,
57+
} wifi_ps_type_t;
5158

5259
typedef enum WiFiEvent
5360
{

0 commit comments

Comments
 (0)