Skip to content

Commit 8ef21ca

Browse files
d-a-vdevyte
authored andcommitted
Update to the last version of nonos-sdk V2, WiFi addons (#5210)
* fwupdate * fw update to latest version: WPA working, WEP+Open disabled by default. Need API change. * helpers to follow sdk updates * remove compare scripts - made a separate PR for them * add wep api, restore original espressif comment (wep enabled does not prevent wpa) * libmain was not up to date * experimental: DTIM setting in WiFi.setSleepMode(WIFI_LIGHT/MODEM_SLEEP, DTIM-value) with new getter: .getListenInterval() / .isSleepLevelMax() * fixes * fix debug message * when not using listenInterval, set wifi sleep level to min * update documentation * update doc
1 parent 9fb4a05 commit 8ef21ca

25 files changed

+150
-8
lines changed

doc/esp8266wifi/generic-class.rst

+39-1
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,46 @@ mode
5555
- ``WiFi.getMode()``: return current Wi-Fi mode (one out of four modes
5656
above)
5757

58+
WiFi power management, DTIM
59+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
60+
61+
.. code:: cpp
62+
63+
bool setSleepMode (WiFiSleepType_t type, int listenInterval=0)
64+
65+
Sleep mode type is ``WIFI_NONE_SLEEP``, ``WIFI_LIGHT_SLEEP`` or ``WIFI_MODEM_SLEEP``.
66+
67+
(``listenInterval`` appeared in esp8266-arduino core v2.5.0 using the last
68+
V2 revision of nonos-sdk before V3)
69+
70+
Quoting nonos-sdk datasheet:
71+
72+
* ``NONE``: disable power saving
73+
74+
* ``LIGHT`` or ``MODEM``: TCP timer rate raised from 250ms to 3s
75+
76+
When ``listenInterval`` is set to 1..10, in ``LIGHT`` or ``MODEM`` mode,
77+
station wakes up every (DTIM-interval * ``listenInterval``). This saves
78+
power but station interface may miss broadcast data.
79+
80+
Otherwise (default value 0), station wakes up at every DTIM-interval
81+
(configured in the access-point).
82+
83+
Quoting wikipedia:
84+
85+
A Delivery Traffic Indication Map (DTIM) is a kind of Traffic Indication Map
86+
(TIM) which informs the clients about the presence of buffered
87+
multicast/broadcast data on the access point. It is generated within the
88+
periodic beacon at a frequency specified by the DTIM Interval. Beacons are
89+
packets sent by an access point to synchronize a wireless network.
90+
91+
5892
Other Function Calls
5993
~~~~~~~~~~~~~~~~~~~~
6094

6195
.. code:: cpp
6296
6397
int32_t channel (void)
64-
bool setSleepMode (WiFiSleepType_t type)
6598
WiFiSleepType_t getSleepMode ()
6699
bool setPhyMode (WiFiPhyMode_t mode)
67100
WiFiPhyMode_t getPhyMode ()
@@ -73,6 +106,11 @@ Other Function Calls
73106
bool forceSleepWake ()
74107
int hostByName (const char *aHostname, IPAddress &aResult)
75108
109+
appeared with SDK pre-V3:
110+
uint8_t getListenInterval ();
111+
bool isSleepLevelMax ();
112+
113+
76114
Documentation for the above functions is not yet prepared.
77115

78116
For code samples please refer to separate section with `examples <generic-examples.rst>`__ dedicated specifically to the Generic Class.

libraries/ESP8266WiFi/keywords.txt

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ psk KEYWORD2
104104
BSSID KEYWORD2
105105
BSSIDstr KEYWORD2
106106
RSSI KEYWORD2
107+
enableInsecureWEP KEYWORD2
108+
getListenInterval KEYWORD2
109+
isSleepLevelMax KEYWORD2
107110
beginWPSConfig KEYWORD2
108111
beginSmartConfig KEYWORD2
109112
stopSmartConfig KEYWORD2

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

+83-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static std::list<WiFiEventHandler> sCbEventList;
8282
bool ESP8266WiFiGenericClass::_persistent = true;
8383
WiFiMode_t ESP8266WiFiGenericClass::_forceSleepLastMode = WIFI_OFF;
8484

85-
ESP8266WiFiGenericClass::ESP8266WiFiGenericClass()
85+
ESP8266WiFiGenericClass::ESP8266WiFiGenericClass()
8686
{
8787
wifi_set_event_handler_cb((wifi_event_handler_cb_t) &ESP8266WiFiGenericClass::_eventCallback);
8888
}
@@ -214,7 +214,7 @@ WiFiEventHandler ESP8266WiFiGenericClass::onSoftAPModeProbeRequestReceived(std::
214214
* callback for WiFi events
215215
* @param arg
216216
*/
217-
void ESP8266WiFiGenericClass::_eventCallback(void* arg)
217+
void ESP8266WiFiGenericClass::_eventCallback(void* arg)
218218
{
219219
System_Event_t* event = reinterpret_cast<System_Event_t*>(arg);
220220
DEBUG_WIFI("wifi evt: %d\n", event->event);
@@ -249,8 +249,71 @@ int32_t ESP8266WiFiGenericClass::channel(void) {
249249
* @param type sleep_type_t
250250
* @return bool
251251
*/
252-
bool ESP8266WiFiGenericClass::setSleepMode(WiFiSleepType_t type) {
253-
return wifi_set_sleep_type((sleep_type_t) type);
252+
bool ESP8266WiFiGenericClass::setSleepMode(WiFiSleepType_t type, uint8_t listenInterval) {
253+
254+
/**
255+
* datasheet:
256+
*
257+
wifi_set_sleep_level():
258+
Set sleep level of modem sleep and light sleep
259+
This configuration should be called before calling wifi_set_sleep_type
260+
Modem-sleep and light sleep mode have minimum and maximum sleep levels.
261+
- In minimum sleep level, station wakes up at every DTIM to receive
262+
beacon. Broadcast data will not be lost because it is transmitted after
263+
DTIM. However, it can not save much more power if DTIM period is short,
264+
as specified in AP.
265+
- In maximum sleep level, station wakes up at every listen interval to
266+
receive beacon. Broadcast data may be lost because station may be in sleep
267+
state at DTIM time. If listen interval is longer, more power will be saved, but
268+
it’s very likely to lose more broadcast data.
269+
- Default setting is minimum sleep level.
270+
Further reading: https://routerguide.net/dtim-interval-period-best-setting/
271+
272+
wifi_set_listen_interval():
273+
Set listen interval of maximum sleep level for modem sleep and light sleep
274+
It only works when sleep level is set as MAX_SLEEP_T
275+
It should be called following the order:
276+
wifi_set_sleep_level(MAX_SLEEP_T)
277+
wifi_set_listen_interval
278+
wifi_set_sleep_type
279+
forum: https://github.com./espressif/ESP8266_NONOS_SDK/issues/165#issuecomment-416121920
280+
default value seems to be 3 (as recommended by https://routerguide.net/dtim-interval-period-best-setting/)
281+
*/
282+
283+
#ifdef DEBUG_ESP_WIFI
284+
if (listenInterval && type == WIFI_NONE_SLEEP)
285+
DEBUG_WIFI_GENERIC("listenInterval not usable with WIFI_NONE_SLEEP\n");
286+
#endif
287+
288+
if (type == WIFI_LIGHT_SLEEP || type == WIFI_MODEM_SLEEP) {
289+
if (listenInterval) {
290+
if (!wifi_set_sleep_level(MAX_SLEEP_T)) {
291+
DEBUG_WIFI_GENERIC("wifi_set_sleep_level(MAX_SLEEP_T): error\n");
292+
return false;
293+
}
294+
if (listenInterval > 10) {
295+
DEBUG_WIFI_GENERIC("listenInterval must be in [1..10]\n");
296+
#ifndef DEBUG_ESP_WIFI
297+
// stay within datasheet range when not in debug mode
298+
listenInterval = 10;
299+
#endif
300+
}
301+
if (!wifi_set_listen_interval(listenInterval)) {
302+
DEBUG_WIFI_GENERIC("wifi_set_listen_interval(%d): error\n", listenInterval);
303+
return false;
304+
}
305+
} else {
306+
if (!wifi_set_sleep_level(MIN_SLEEP_T)) {
307+
DEBUG_WIFI_GENERIC("wifi_set_sleep_level(MIN_SLEEP_T): error\n");
308+
return false;
309+
}
310+
}
311+
}
312+
bool ret = wifi_set_sleep_type((sleep_type_t) type);
313+
if (!ret) {
314+
DEBUG_WIFI_GENERIC("wifi_set_sleep_type(%d): error\n", (int)type);
315+
}
316+
return ret;
254317
}
255318

256319
/**
@@ -426,6 +489,22 @@ bool ESP8266WiFiGenericClass::forceSleepWake() {
426489
return false;
427490
}
428491

492+
/**
493+
* Get listen interval of maximum sleep level for modem sleep and light sleep.
494+
* @return interval
495+
*/
496+
uint8_t ESP8266WiFiGenericClass::getListenInterval () {
497+
return wifi_get_listen_interval();
498+
}
499+
500+
/**
501+
* Get sleep level of modem sleep and light sleep
502+
* @return true if max level
503+
*/
504+
bool ESP8266WiFiGenericClass::isSleepLevelMax () {
505+
return wifi_get_sleep_level() == MAX_SLEEP_T;
506+
}
507+
429508

430509
// -----------------------------------------------------------------------------------------------------------------------
431510
// ------------------------------------------------ Generic Network function ---------------------------------------------

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ class ESP8266WiFiGenericClass {
6666

6767
int32_t channel(void);
6868

69-
bool setSleepMode(WiFiSleepType_t type);
69+
bool setSleepMode(WiFiSleepType_t type, uint8_t listenInterval = 0);
70+
7071
WiFiSleepType_t getSleepMode();
72+
uint8_t getListenInterval ();
73+
bool isSleepLevelMax ();
7174

7275
bool setPhyMode(WiFiPhyMode_t mode);
7376
WiFiPhyMode_t getPhyMode();

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
8686
// -----------------------------------------------------------------------------------------------------------------------
8787

8888
bool ESP8266WiFiSTAClass::_useStaticIp = false;
89+
bool ESP8266WiFiSTAClass::_useInsecureWEP = false;
8990

9091
/**
9192
* Start Wifi connection
@@ -127,6 +128,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
127128
}
128129

129130
conf.threshold.rssi = -127;
131+
conf.open_and_wep_mode_disable = !(_useInsecureWEP || *conf.password == 0);
130132

131133
// TODO(#909): set authmode to AUTH_WPA_PSK if passphrase is provided
132134
conf.threshold.authmode = AUTH_OPEN;

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

+3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ class ESP8266WiFiSTAClass {
8383

8484
int32_t RSSI();
8585

86+
static void enableInsecureWEP (bool enable = true) { _useInsecureWEP = enable; }
87+
8688
protected:
8789

8890
static bool _useStaticIp;
91+
static bool _useInsecureWEP;
8992

9093
// ----------------------------------------------------------------------------------------------
9194
// ------------------------------------ STA remote configure -----------------------------------

tools/sdk/include/user_interface.h

+12
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ struct station_config {
251251
// with both ssid[] and bssid[] matched. Please check about this.
252252
uint8 bssid[6];
253253
wifi_fast_scan_threshold_t threshold;
254+
bool open_and_wep_mode_disable; // Can connect to open/wep router by default.
254255
};
255256

256257
bool wifi_station_get_config(struct station_config *config);
@@ -427,6 +428,17 @@ typedef enum {
427428
MODEM_SLEEP_T
428429
} sleep_type_t;
429430

431+
typedef enum {
432+
MIN_SLEEP_T,
433+
MAX_SLEEP_T
434+
} sleep_level_t;
435+
436+
bool wifi_set_sleep_level(sleep_level_t level);
437+
sleep_level_t wifi_get_sleep_level(void);
438+
439+
bool wifi_set_listen_interval(uint8 interval);
440+
uint8 wifi_get_listen_interval(void);
441+
430442
bool wifi_set_sleep_type(sleep_type_t type);
431443
sleep_type_t wifi_get_sleep_type(void);
432444

tools/sdk/lib/fix_sdk_libs.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -e
33

4+
export PATH=../../xtensa-lx106-elf/bin:$PATH
5+
46
# Remove mem_manager.o from libmain.a to use custom heap implementation,
57
# and time.o to fix redefinition of time-related functions:
68
xtensa-lx106-elf-ar d libmain.a mem_manager.o
@@ -13,4 +15,4 @@ xtensa-lx106-elf-objcopy --redefine-sym hostname=wifi_station_hostname eagle_lwi
1315
xtensa-lx106-elf-objcopy --redefine-sym default_hostname=wifi_station_default_hostname user_interface.o
1416
xtensa-lx106-elf-objcopy --redefine-sym default_hostname=wifi_station_default_hostname eagle_lwip_if.o
1517
xtensa-lx106-elf-ar r libmain.a eagle_lwip_if.o user_interface.o
16-
rm eagle_lwip_if.o user_interface.o
18+
rm -f eagle_lwip_if.o user_interface.o

tools/sdk/lib/libat.a

-404 KB
Binary file not shown.

tools/sdk/lib/libcrypto.a

12 Bytes
Binary file not shown.

tools/sdk/lib/libespnow.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libjson.a

-17.9 KB
Binary file not shown.

tools/sdk/lib/liblwip.a

-315 KB
Binary file not shown.

tools/sdk/lib/liblwip_536.a

-346 KB
Binary file not shown.

tools/sdk/lib/libmain.a

3.76 KB
Binary file not shown.

tools/sdk/lib/libnet80211.a

-204 Bytes
Binary file not shown.

tools/sdk/lib/libpp.a

3.89 KB
Binary file not shown.

tools/sdk/lib/libpwm.a

-27.6 KB
Binary file not shown.

tools/sdk/lib/libsmartconfig.a

0 Bytes
Binary file not shown.

tools/sdk/lib/libssl.a

-269 KB
Binary file not shown.

tools/sdk/lib/libupgrade.a

-40.2 KB
Binary file not shown.

tools/sdk/lib/libwpa.a

2.49 KB
Binary file not shown.

tools/sdk/lib/libwpa2.a

140 Bytes
Binary file not shown.

tools/sdk/lib/libwps.a

480 Bytes
Binary file not shown.

tools/sdk/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.1.0-10-g509eae8
1+
v2.2.0-28-g89920dc

0 commit comments

Comments
 (0)