Skip to content

Commit

Permalink
Update to the last version of nonos-sdk V2, WiFi addons (esp8266#5210)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
d-a-v authored and devyte committed Oct 9, 2018
1 parent 9fb4a05 commit 8ef21ca
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 8 deletions.
40 changes: 39 additions & 1 deletion doc/esp8266wifi/generic-class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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 <generic-examples.rst>`__ dedicated specifically to the Generic Class.
3 changes: 3 additions & 0 deletions libraries/ESP8266WiFi/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ psk KEYWORD2
BSSID KEYWORD2
BSSIDstr KEYWORD2
RSSI KEYWORD2
enableInsecureWEP KEYWORD2
getListenInterval KEYWORD2
isSleepLevelMax KEYWORD2
beginWPSConfig KEYWORD2
beginSmartConfig KEYWORD2
stopSmartConfig KEYWORD2
Expand Down
87 changes: 83 additions & 4 deletions libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static std::list<WiFiEventHandler> 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);
}
Expand Down Expand Up @@ -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<System_Event_t*>(arg);
DEBUG_WIFI("wifi evt: %d\n", event->event);
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 ---------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------------------
Expand Down
12 changes: 12 additions & 0 deletions tools/sdk/include/user_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion tools/sdk/lib/fix_sdk_libs.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Binary file removed tools/sdk/lib/libat.a
Binary file not shown.
Binary file modified tools/sdk/lib/libcrypto.a
Binary file not shown.
Binary file modified tools/sdk/lib/libespnow.a
Binary file not shown.
Binary file removed tools/sdk/lib/libjson.a
Binary file not shown.
Binary file removed tools/sdk/lib/liblwip.a
Binary file not shown.
Binary file removed tools/sdk/lib/liblwip_536.a
Binary file not shown.
Binary file modified tools/sdk/lib/libmain.a
Binary file not shown.
Binary file modified tools/sdk/lib/libnet80211.a
Binary file not shown.
Binary file modified tools/sdk/lib/libpp.a
Binary file not shown.
Binary file removed tools/sdk/lib/libpwm.a
Binary file not shown.
Binary file modified tools/sdk/lib/libsmartconfig.a
Binary file not shown.
Binary file removed tools/sdk/lib/libssl.a
Binary file not shown.
Binary file removed tools/sdk/lib/libupgrade.a
Binary file not shown.
Binary file modified tools/sdk/lib/libwpa.a
Binary file not shown.
Binary file modified tools/sdk/lib/libwpa2.a
Binary file not shown.
Binary file modified tools/sdk/lib/libwps.a
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/sdk/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.1.0-10-g509eae8
v2.2.0-28-g89920dc

0 comments on commit 8ef21ca

Please sign in to comment.