mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-25 20:02:37 +03:00
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
This commit is contained in:
parent
9fb4a05d67
commit
8ef21ca3ae
@ -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 <generic-examples.rst>`__ dedicated specifically to the Generic Class.
|
||||
|
@ -104,6 +104,9 @@ psk KEYWORD2
|
||||
BSSID KEYWORD2
|
||||
BSSIDstr KEYWORD2
|
||||
RSSI KEYWORD2
|
||||
enableInsecureWEP KEYWORD2
|
||||
getListenInterval KEYWORD2
|
||||
isSleepLevelMax KEYWORD2
|
||||
beginWPSConfig KEYWORD2
|
||||
beginSmartConfig KEYWORD2
|
||||
stopSmartConfig KEYWORD2
|
||||
|
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
@ -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 ---------------------------------------------
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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 -----------------------------------
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
v2.1.0-10-g509eae8
|
||||
v2.2.0-28-g89920dc
|
Loading…
x
Reference in New Issue
Block a user