diff --git a/doc/esp8266wifi/generic-class.rst b/doc/esp8266wifi/generic-class.rst index 4775e83208..e7344284b1 100644 --- a/doc/esp8266wifi/generic-class.rst +++ b/doc/esp8266wifi/generic-class.rst @@ -55,13 +55,46 @@ mode - ``WiFi.getMode()``: return current Wi-Fi mode (one out of four modes above) +WiFi power management, DTIM +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: cpp + + bool setSleepMode (WiFiSleepType_t type, int listenInterval=0) + +Sleep mode type is ``WIFI_NONE_SLEEP``, ``WIFI_LIGHT_SLEEP`` or ``WIFI_MODEM_SLEEP``. + +(``listenInterval`` appeared in esp8266-arduino core v2.5.0 using the last +V2 revision of nonos-sdk before V3) + +Quoting nonos-sdk datasheet: + +* ``NONE``: disable power saving + +* ``LIGHT`` or ``MODEM``: TCP timer rate raised from 250ms to 3s + +When ``listenInterval`` is set to 1..10, in ``LIGHT`` or ``MODEM`` mode, +station wakes up every (DTIM-interval * ``listenInterval``). This saves +power but station interface may miss broadcast data. + +Otherwise (default value 0), station wakes up at every DTIM-interval +(configured in the access-point). + +Quoting wikipedia: + +A Delivery Traffic Indication Map (DTIM) is a kind of Traffic Indication Map +(TIM) which informs the clients about the presence of buffered +multicast/broadcast data on the access point. It is generated within the +periodic beacon at a frequency specified by the DTIM Interval. Beacons are +packets sent by an access point to synchronize a wireless network. + + Other Function Calls ~~~~~~~~~~~~~~~~~~~~ .. code:: cpp int32_t channel (void) - bool setSleepMode (WiFiSleepType_t type) WiFiSleepType_t getSleepMode () bool setPhyMode (WiFiPhyMode_t mode) WiFiPhyMode_t getPhyMode () @@ -73,6 +106,11 @@ Other Function Calls bool forceSleepWake () int hostByName (const char *aHostname, IPAddress &aResult) + appeared with SDK pre-V3: + uint8_t getListenInterval (); + bool isSleepLevelMax (); + + Documentation for the above functions is not yet prepared. For code samples please refer to separate section with `examples `__ dedicated specifically to the Generic Class. diff --git a/libraries/ESP8266WiFi/keywords.txt b/libraries/ESP8266WiFi/keywords.txt index 0610a749b4..29919efc39 100644 --- a/libraries/ESP8266WiFi/keywords.txt +++ b/libraries/ESP8266WiFi/keywords.txt @@ -104,6 +104,9 @@ psk KEYWORD2 BSSID KEYWORD2 BSSIDstr KEYWORD2 RSSI KEYWORD2 +enableInsecureWEP KEYWORD2 +getListenInterval KEYWORD2 +isSleepLevelMax KEYWORD2 beginWPSConfig KEYWORD2 beginSmartConfig KEYWORD2 stopSmartConfig KEYWORD2 diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index bea45bc36e..1582124a37 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -82,7 +82,7 @@ static std::list sCbEventList; bool ESP8266WiFiGenericClass::_persistent = true; WiFiMode_t ESP8266WiFiGenericClass::_forceSleepLastMode = WIFI_OFF; -ESP8266WiFiGenericClass::ESP8266WiFiGenericClass() +ESP8266WiFiGenericClass::ESP8266WiFiGenericClass() { wifi_set_event_handler_cb((wifi_event_handler_cb_t) &ESP8266WiFiGenericClass::_eventCallback); } @@ -214,7 +214,7 @@ WiFiEventHandler ESP8266WiFiGenericClass::onSoftAPModeProbeRequestReceived(std:: * callback for WiFi events * @param arg */ -void ESP8266WiFiGenericClass::_eventCallback(void* arg) +void ESP8266WiFiGenericClass::_eventCallback(void* arg) { System_Event_t* event = reinterpret_cast(arg); DEBUG_WIFI("wifi evt: %d\n", event->event); @@ -249,8 +249,71 @@ int32_t ESP8266WiFiGenericClass::channel(void) { * @param type sleep_type_t * @return bool */ -bool ESP8266WiFiGenericClass::setSleepMode(WiFiSleepType_t type) { - return wifi_set_sleep_type((sleep_type_t) type); +bool ESP8266WiFiGenericClass::setSleepMode(WiFiSleepType_t type, uint8_t listenInterval) { + + /** + * datasheet: + * + wifi_set_sleep_level(): + Set sleep level of modem sleep and light sleep + This configuration should be called before calling wifi_set_sleep_type + Modem-sleep and light sleep mode have minimum and maximum sleep levels. + - In minimum sleep level, station wakes up at every DTIM to receive + beacon. Broadcast data will not be lost because it is transmitted after + DTIM. However, it can not save much more power if DTIM period is short, + as specified in AP. + - In maximum sleep level, station wakes up at every listen interval to + receive beacon. Broadcast data may be lost because station may be in sleep + state at DTIM time. If listen interval is longer, more power will be saved, but + it’s very likely to lose more broadcast data. + - Default setting is minimum sleep level. + Further reading: https://routerguide.net/dtim-interval-period-best-setting/ + + wifi_set_listen_interval(): + Set listen interval of maximum sleep level for modem sleep and light sleep + It only works when sleep level is set as MAX_SLEEP_T + It should be called following the order: + wifi_set_sleep_level(MAX_SLEEP_T) + wifi_set_listen_interval + wifi_set_sleep_type + forum: https://github.com/espressif/ESP8266_NONOS_SDK/issues/165#issuecomment-416121920 + default value seems to be 3 (as recommended by https://routerguide.net/dtim-interval-period-best-setting/) + */ + +#ifdef DEBUG_ESP_WIFI + if (listenInterval && type == WIFI_NONE_SLEEP) + DEBUG_WIFI_GENERIC("listenInterval not usable with WIFI_NONE_SLEEP\n"); +#endif + + if (type == WIFI_LIGHT_SLEEP || type == WIFI_MODEM_SLEEP) { + if (listenInterval) { + if (!wifi_set_sleep_level(MAX_SLEEP_T)) { + DEBUG_WIFI_GENERIC("wifi_set_sleep_level(MAX_SLEEP_T): error\n"); + return false; + } + if (listenInterval > 10) { + DEBUG_WIFI_GENERIC("listenInterval must be in [1..10]\n"); +#ifndef DEBUG_ESP_WIFI + // stay within datasheet range when not in debug mode + listenInterval = 10; +#endif + } + if (!wifi_set_listen_interval(listenInterval)) { + DEBUG_WIFI_GENERIC("wifi_set_listen_interval(%d): error\n", listenInterval); + return false; + } + } else { + if (!wifi_set_sleep_level(MIN_SLEEP_T)) { + DEBUG_WIFI_GENERIC("wifi_set_sleep_level(MIN_SLEEP_T): error\n"); + return false; + } + } + } + bool ret = wifi_set_sleep_type((sleep_type_t) type); + if (!ret) { + DEBUG_WIFI_GENERIC("wifi_set_sleep_type(%d): error\n", (int)type); + } + return ret; } /** @@ -426,6 +489,22 @@ bool ESP8266WiFiGenericClass::forceSleepWake() { return false; } +/** + * Get listen interval of maximum sleep level for modem sleep and light sleep. + * @return interval + */ +uint8_t ESP8266WiFiGenericClass::getListenInterval () { + return wifi_get_listen_interval(); +} + +/** + * Get sleep level of modem sleep and light sleep + * @return true if max level + */ +bool ESP8266WiFiGenericClass::isSleepLevelMax () { + return wifi_get_sleep_level() == MAX_SLEEP_T; +} + // ----------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------ Generic Network function --------------------------------------------- diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index 6264e3a550..eef49d925b 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -66,8 +66,11 @@ class ESP8266WiFiGenericClass { int32_t channel(void); - bool setSleepMode(WiFiSleepType_t type); + bool setSleepMode(WiFiSleepType_t type, uint8_t listenInterval = 0); + WiFiSleepType_t getSleepMode(); + uint8_t getListenInterval (); + bool isSleepLevelMax (); bool setPhyMode(WiFiPhyMode_t mode); WiFiPhyMode_t getPhyMode(); diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index 5f2c2c3b05..03744f363c 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -86,6 +86,7 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh // ----------------------------------------------------------------------------------------------------------------------- bool ESP8266WiFiSTAClass::_useStaticIp = false; +bool ESP8266WiFiSTAClass::_useInsecureWEP = false; /** * Start Wifi connection @@ -127,6 +128,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, } conf.threshold.rssi = -127; + conf.open_and_wep_mode_disable = !(_useInsecureWEP || *conf.password == 0); // TODO(#909): set authmode to AUTH_WPA_PSK if passphrase is provided conf.threshold.authmode = AUTH_OPEN; diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index 58b76ef5ee..6390ac41e0 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -83,9 +83,12 @@ class ESP8266WiFiSTAClass { int32_t RSSI(); + static void enableInsecureWEP (bool enable = true) { _useInsecureWEP = enable; } + protected: static bool _useStaticIp; + static bool _useInsecureWEP; // ---------------------------------------------------------------------------------------------- // ------------------------------------ STA remote configure ----------------------------------- diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index a7733a9548..33b6573d7c 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -251,6 +251,7 @@ struct station_config { // with both ssid[] and bssid[] matched. Please check about this. uint8 bssid[6]; wifi_fast_scan_threshold_t threshold; + bool open_and_wep_mode_disable; // Can connect to open/wep router by default. }; bool wifi_station_get_config(struct station_config *config); @@ -427,6 +428,17 @@ typedef enum { MODEM_SLEEP_T } sleep_type_t; +typedef enum { + MIN_SLEEP_T, + MAX_SLEEP_T +} sleep_level_t; + +bool wifi_set_sleep_level(sleep_level_t level); +sleep_level_t wifi_get_sleep_level(void); + +bool wifi_set_listen_interval(uint8 interval); +uint8 wifi_get_listen_interval(void); + bool wifi_set_sleep_type(sleep_type_t type); sleep_type_t wifi_get_sleep_type(void); diff --git a/tools/sdk/lib/fix_sdk_libs.sh b/tools/sdk/lib/fix_sdk_libs.sh index d0c162d39e..178f08bd2f 100755 --- a/tools/sdk/lib/fix_sdk_libs.sh +++ b/tools/sdk/lib/fix_sdk_libs.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e +export PATH=../../xtensa-lx106-elf/bin:$PATH + # Remove mem_manager.o from libmain.a to use custom heap implementation, # and time.o to fix redefinition of time-related functions: 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 xtensa-lx106-elf-objcopy --redefine-sym default_hostname=wifi_station_default_hostname user_interface.o xtensa-lx106-elf-objcopy --redefine-sym default_hostname=wifi_station_default_hostname eagle_lwip_if.o xtensa-lx106-elf-ar r libmain.a eagle_lwip_if.o user_interface.o -rm eagle_lwip_if.o user_interface.o +rm -f eagle_lwip_if.o user_interface.o diff --git a/tools/sdk/lib/libat.a b/tools/sdk/lib/libat.a deleted file mode 100644 index 7567719117..0000000000 Binary files a/tools/sdk/lib/libat.a and /dev/null differ diff --git a/tools/sdk/lib/libcrypto.a b/tools/sdk/lib/libcrypto.a index 1c3feaba43..d0aea338e8 100644 Binary files a/tools/sdk/lib/libcrypto.a and b/tools/sdk/lib/libcrypto.a differ diff --git a/tools/sdk/lib/libespnow.a b/tools/sdk/lib/libespnow.a index 400d3bd9d5..2ed7994e1d 100644 Binary files a/tools/sdk/lib/libespnow.a and b/tools/sdk/lib/libespnow.a differ diff --git a/tools/sdk/lib/libjson.a b/tools/sdk/lib/libjson.a deleted file mode 100644 index e9f365ba1d..0000000000 Binary files a/tools/sdk/lib/libjson.a and /dev/null differ diff --git a/tools/sdk/lib/liblwip.a b/tools/sdk/lib/liblwip.a deleted file mode 100644 index e77e304d77..0000000000 Binary files a/tools/sdk/lib/liblwip.a and /dev/null differ diff --git a/tools/sdk/lib/liblwip_536.a b/tools/sdk/lib/liblwip_536.a deleted file mode 100644 index 5ea340be2e..0000000000 Binary files a/tools/sdk/lib/liblwip_536.a and /dev/null differ diff --git a/tools/sdk/lib/libmain.a b/tools/sdk/lib/libmain.a index c0e70cafef..e93201c520 100644 Binary files a/tools/sdk/lib/libmain.a and b/tools/sdk/lib/libmain.a differ diff --git a/tools/sdk/lib/libnet80211.a b/tools/sdk/lib/libnet80211.a index d3ecbd68a9..576304be26 100644 Binary files a/tools/sdk/lib/libnet80211.a and b/tools/sdk/lib/libnet80211.a differ diff --git a/tools/sdk/lib/libpp.a b/tools/sdk/lib/libpp.a index 6135231c79..fbf3e85636 100644 Binary files a/tools/sdk/lib/libpp.a and b/tools/sdk/lib/libpp.a differ diff --git a/tools/sdk/lib/libpwm.a b/tools/sdk/lib/libpwm.a deleted file mode 100644 index 1913f1604e..0000000000 Binary files a/tools/sdk/lib/libpwm.a and /dev/null differ diff --git a/tools/sdk/lib/libsmartconfig.a b/tools/sdk/lib/libsmartconfig.a index c217cc5b98..34598d36a6 100644 Binary files a/tools/sdk/lib/libsmartconfig.a and b/tools/sdk/lib/libsmartconfig.a differ diff --git a/tools/sdk/lib/libssl.a b/tools/sdk/lib/libssl.a deleted file mode 100644 index 6ff625bf6a..0000000000 Binary files a/tools/sdk/lib/libssl.a and /dev/null differ diff --git a/tools/sdk/lib/libupgrade.a b/tools/sdk/lib/libupgrade.a deleted file mode 100644 index ee219cbec8..0000000000 Binary files a/tools/sdk/lib/libupgrade.a and /dev/null differ diff --git a/tools/sdk/lib/libwpa.a b/tools/sdk/lib/libwpa.a index 7ea69a61f4..3a58113a1a 100644 Binary files a/tools/sdk/lib/libwpa.a and b/tools/sdk/lib/libwpa.a differ diff --git a/tools/sdk/lib/libwpa2.a b/tools/sdk/lib/libwpa2.a index 1f7aabb688..b868608a14 100644 Binary files a/tools/sdk/lib/libwpa2.a and b/tools/sdk/lib/libwpa2.a differ diff --git a/tools/sdk/lib/libwps.a b/tools/sdk/lib/libwps.a index 0c3503350a..1f6b365e3a 100644 Binary files a/tools/sdk/lib/libwps.a and b/tools/sdk/lib/libwps.a differ diff --git a/tools/sdk/version b/tools/sdk/version index d7849d9e1b..06e014650a 100644 --- a/tools/sdk/version +++ b/tools/sdk/version @@ -1 +1 @@ -v2.1.0-10-g509eae8 \ No newline at end of file +v2.2.0-28-g89920dc \ No newline at end of file