From ab16b8c3749d0f30f871ba36e45da2f8a33fec8e Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 2 Mar 2021 01:45:50 +0100 Subject: [PATCH 01/18] Disable WiFi at boot by default --- cores/esp8266/core_esp8266_main.cpp | 16 +++++++++++-- cores/esp8266/coredecls.h | 4 +++- .../examples/WiFiShutdown/WiFiShutdown.ino | 5 ---- .../ESP8266WiFi/src/ESP8266WiFiGeneric.cpp | 24 +++---------------- .../ESP8266WiFi/src/ESP8266WiFiGeneric.h | 2 +- .../examples/SerialStress/SerialStress.ino | 6 ----- .../examples/TCPClient/TCPClient.ino | 7 ------ tests/device/test_serial/test_serial.ino | 6 ----- .../device/test_spi_flash/test_spi_flash.ino | 6 ----- 9 files changed, 21 insertions(+), 55 deletions(-) diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 417c3f26e8..4630ef6c9c 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -331,7 +331,18 @@ extern "C" void app_entry (void) extern "C" void preinit (void) __attribute__((weak)); extern "C" void preinit (void) { - /* do nothing by default */ + /* does nothing, kept for backward compatibility */ +} + +extern "C" void __disableWiFiAtBootTime (void) __attribute__((weak)); +extern "C" void __disableWiFiAtBootTime (void) +{ + // Starting from arduino core v3: wifi is disabled at boot time + // WiFi.begin() or WiFi.softAP() will wake WiFi up + wifi_set_opmode_current(0/*WIFI_OFF*/); + wifi_fpm_set_sleep_type(MODEM_SLEEP_T); + wifi_fpm_open(); + wifi_fpm_do_sleep(0xFFFFFFF); } extern "C" void user_init(void) { @@ -354,7 +365,8 @@ extern "C" void user_init(void) { #if defined(MMU_IRAM_HEAP) umm_init_iram(); #endif - preinit(); // Prior to C++ Dynamic Init (not related to above init() ). Meant to be user redefinable. + preinit(); // deprecated + __disableWiFiAtBootTime(); // default weak function disables WiFi ets_task(loop_task, LOOP_TASK_PRIORITY, s_loop_queue, diff --git a/cores/esp8266/coredecls.h b/cores/esp8266/coredecls.h index 7186662f0f..c8743ef95b 100644 --- a/cores/esp8266/coredecls.h +++ b/cores/esp8266/coredecls.h @@ -18,6 +18,8 @@ void esp_schedule(); void tune_timeshift64 (uint64_t now_us); void disable_extra4k_at_link_time (void) __attribute__((noinline)); bool sntp_set_timezone_in_seconds(int32_t timezone); +void enableWiFiAtBootTime (void) __attribute__((noinline)); +void __disableWiFiAtBootTime (void) __attribute__((noinline)); void __real_system_restart_local() __attribute__((noreturn)); uint32_t sqrt32 (uint32_t n); @@ -34,6 +36,6 @@ using TrivialCB = std::function; void settimeofday_cb (const BoolCB& cb); void settimeofday_cb (const TrivialCB& cb); -#endif +#endif // __cplusplus #endif // __COREDECLS_H diff --git a/libraries/ESP8266WiFi/examples/WiFiShutdown/WiFiShutdown.ino b/libraries/ESP8266WiFi/examples/WiFiShutdown/WiFiShutdown.ino index 34f26a8b50..7fac16b45d 100644 --- a/libraries/ESP8266WiFi/examples/WiFiShutdown/WiFiShutdown.ino +++ b/libraries/ESP8266WiFi/examples/WiFiShutdown/WiFiShutdown.ino @@ -24,11 +24,6 @@ WiFiState state; const char* ssid = STASSID; const char* password = STAPSK; -void preinit(void) { - // Make sure, wifi stays off after boot. - ESP8266WiFiClass::preinitWiFiOff(); -} - void setup() { Serial.begin(74880); //Serial.setDebugOutput(true); // If you need debug output diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index e583cb2318..04ad7e11e9 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -419,7 +419,7 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m, WiFiState* state) { } if (wifi_fpm_get_sleep_type() != NONE_SLEEP_T) { - // wifi may have been put asleep by ESP8266WiFiGenericClass::preinitWiFiOff + // wifi starts asleep by default wifi_fpm_do_wakeup(); wifi_fpm_close(); } @@ -855,25 +855,7 @@ bool ESP8266WiFiGenericClass::resumeFromShutdown (WiFiState* state) return true; } -//meant to be called from user-defined ::preinit() void ESP8266WiFiGenericClass::preinitWiFiOff () { - // https://github.com/esp8266/Arduino/issues/2111#issuecomment-224251391 - // WiFi.persistent(false); - // WiFi.mode(WIFI_OFF); - // WiFi.forceSleepBegin(); - - //WiFi.mode(WIFI_OFF) equivalent: - // datasheet: - // Set Wi-Fi working mode to Station mode, SoftAP - // or Station + SoftAP, and do not update flash - // (not persistent) - wifi_set_opmode_current(WIFI_OFF); - - //WiFi.forceSleepBegin(/*default*/0) equivalent: - // sleep forever until wifi_fpm_do_wakeup() is called - wifi_fpm_set_sleep_type(MODEM_SLEEP_T); - wifi_fpm_open(); - wifi_fpm_do_sleep(0xFFFFFFF); - - // use WiFi.forceSleepWake() to wake WiFi up + // It was meant to be called from user-defined ::preinit() + // It is now deprecated by enableWiFiAtBootTime() and __disableWiFiAtBootTime() } diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index 6a91001949..1472fc71a4 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -100,7 +100,7 @@ class ESP8266WiFiGenericClass { static uint32_t shutdownCRC (const WiFiState* state); static bool shutdownValidCRC (const WiFiState* state); - static void preinitWiFiOff (); //meant to be called in user-defined preinit() + static void preinitWiFiOff () __attribute__((deprecated("WiFi is off by default at boot, use enableWiFiAtBoot() for legacy behavior"))); protected: static bool _persistent; diff --git a/libraries/esp8266/examples/SerialStress/SerialStress.ino b/libraries/esp8266/examples/SerialStress/SerialStress.ino index 1412abd2be..b06b38e307 100644 --- a/libraries/esp8266/examples/SerialStress/SerialStress.ino +++ b/libraries/esp8266/examples/SerialStress/SerialStress.ino @@ -57,12 +57,6 @@ void error(const char* what) { } } -void preinit() { - // (no C++ in function) - // disable wifi - ESP8266WiFiClass::preinitWiFiOff(); -} - void setup() { pinMode(LED_BUILTIN, OUTPUT); diff --git a/libraries/lwIP_w5500/examples/TCPClient/TCPClient.ino b/libraries/lwIP_w5500/examples/TCPClient/TCPClient.ino index 56dcb8092b..bdece2d88b 100644 --- a/libraries/lwIP_w5500/examples/TCPClient/TCPClient.ino +++ b/libraries/lwIP_w5500/examples/TCPClient/TCPClient.ino @@ -9,7 +9,6 @@ //or #include #include // WiFiClient (-> TCPClient) -#include // ESP8266WiFiClass::preinitWiFiOff() const char* host = "djxmmx.net"; const uint16_t port = 17; @@ -19,12 +18,6 @@ using TCPClient = WiFiClient; #define CSPIN 16 // wemos/lolin/nodemcu D0 Wiznet5500lwIP eth(CSPIN); -void preinit() { - // (no C++ in function) - // disable wifi - ESP8266WiFiClass::preinitWiFiOff(); -} - void setup() { Serial.begin(115200); diff --git a/tests/device/test_serial/test_serial.ino b/tests/device/test_serial/test_serial.ino index 6cdf2b2673..66ec154067 100644 --- a/tests/device/test_serial/test_serial.ino +++ b/tests/device/test_serial/test_serial.ino @@ -33,12 +33,6 @@ static uint64_t in_total = 0, in_prev = 0; static uint64_t start_ms, last_ms; static uint64_t timeout; -void preinit() { - // (no C++ in function) - // disable wifi - ESP8266WiFiClass::preinitWiFiOff(); -} - void setup() { Serial.begin(SSBAUD); diff --git a/tests/device/test_spi_flash/test_spi_flash.ino b/tests/device/test_spi_flash/test_spi_flash.ino index fa7ea767b8..b1e18241f5 100644 --- a/tests/device/test_spi_flash/test_spi_flash.ino +++ b/tests/device/test_spi_flash/test_spi_flash.ino @@ -3,12 +3,6 @@ BS_ENV_DECLARE(); -void preinit() { - // (no C++ in function) - // disable wifi - ESP8266WiFiClass::preinitWiFiOff(); -} - void setup() { Serial.begin(115200); From 6310da8aab0ab17ea3a36bf790c4049a8c933466 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 2 Mar 2021 02:03:05 +0100 Subject: [PATCH 02/18] +define WIFI_IS_OFF_AT_BOOT --- cores/esp8266/core_esp8266_features.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/esp8266/core_esp8266_features.h b/cores/esp8266/core_esp8266_features.h index 5dea897bc0..c90abb9e5b 100644 --- a/cores/esp8266/core_esp8266_features.h +++ b/cores/esp8266/core_esp8266_features.h @@ -31,6 +31,7 @@ #define CORE_HAS_UMM #define WIFI_HAS_EVENT_CALLBACK +#define WIFI_IS_OFF_AT_BOOT #include // malloc() #include // size_t From 330b229a31e780d33af0c503b4683b4ae5e66457 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 3 Mar 2021 01:05:50 +0100 Subject: [PATCH 03/18] remove now useless example --- .../EarlyDisableWiFi/EarlyDisableWiFi.ino | 59 ------------------- 1 file changed, 59 deletions(-) delete mode 100644 libraries/ESP8266WiFi/examples/EarlyDisableWiFi/EarlyDisableWiFi.ino diff --git a/libraries/ESP8266WiFi/examples/EarlyDisableWiFi/EarlyDisableWiFi.ino b/libraries/ESP8266WiFi/examples/EarlyDisableWiFi/EarlyDisableWiFi.ino deleted file mode 100644 index 2025246f3d..0000000000 --- a/libraries/ESP8266WiFi/examples/EarlyDisableWiFi/EarlyDisableWiFi.ino +++ /dev/null @@ -1,59 +0,0 @@ - -#include -#include - -#ifndef STASSID -#define STASSID "your-ssid" -#define STAPSK "your-password" -#endif - -// preinit() is called before system startup -// from nonos-sdk's user entry point user_init() - -void preinit() { - // Global WiFi constructors are not called yet - // (global class instances like WiFi, Serial... are not yet initialized).. - // No global object methods or C++ exceptions can be called in here! - //The below is a static class method, which is similar to a function, so it's ok. - ESP8266WiFiClass::preinitWiFiOff(); -} - -void setup() { - Serial.begin(115200); - Serial.setDebugOutput(true); - Serial.println("sleeping 5s"); - - // during this period, a simple amp meter shows - // an average of 20mA with a Wemos D1 mini - // a DSO is needed to check #2111 - delay(5000); - - Serial.println("waking WiFi up, sleeping 5s"); - WiFi.forceSleepWake(); - - // amp meter raises to 75mA - delay(5000); - - Serial.println("connecting to AP " STASSID); - WiFi.mode(WIFI_STA); - WiFi.begin(STASSID, STAPSK); - - for (bool configured = false; !configured;) { - for (auto addr : addrList) - if ((configured = !addr.isLocal() && addr.ifnumber() == STATION_IF)) { - Serial.printf("STA: IF='%s' hostname='%s' addr= %s\n", - addr.ifname().c_str(), - addr.ifhostname(), - addr.toString().c_str()); - break; - } - Serial.print('.'); - delay(500); - } - - // amp meter cycles within 75-80 mA - -} - -void loop() { -} From b2a53b798b7e6aef1b2a8ff49b6342f0d88eab9d Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 3 Mar 2021 01:19:45 +0100 Subject: [PATCH 04/18] mv enableWiFiAtBootTime() to core_esp8266_features.h --- cores/esp8266/core_esp8266_features.h | 2 ++ cores/esp8266/coredecls.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/core_esp8266_features.h b/cores/esp8266/core_esp8266_features.h index c90abb9e5b..3eba0ac7de 100644 --- a/cores/esp8266/core_esp8266_features.h +++ b/cores/esp8266/core_esp8266_features.h @@ -105,6 +105,8 @@ uint64_t micros64(void); void delay(unsigned long); void delayMicroseconds(unsigned int us); +void enableWiFiAtBootTime (void) __attribute__((noinline)); + #if defined(F_CPU) || defined(CORE_MOCK) #ifdef __cplusplus constexpr diff --git a/cores/esp8266/coredecls.h b/cores/esp8266/coredecls.h index c8743ef95b..b9c771df77 100644 --- a/cores/esp8266/coredecls.h +++ b/cores/esp8266/coredecls.h @@ -18,7 +18,6 @@ void esp_schedule(); void tune_timeshift64 (uint64_t now_us); void disable_extra4k_at_link_time (void) __attribute__((noinline)); bool sntp_set_timezone_in_seconds(int32_t timezone); -void enableWiFiAtBootTime (void) __attribute__((noinline)); void __disableWiFiAtBootTime (void) __attribute__((noinline)); void __real_system_restart_local() __attribute__((noreturn)); From 2d4ca1d043b3e13f6b82643ba65a578a034032ca Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 15 Mar 2021 10:38:39 +0100 Subject: [PATCH 05/18] sync with master --- libraries/esp8266/examples/UartDownload/UartDownload.ino | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libraries/esp8266/examples/UartDownload/UartDownload.ino b/libraries/esp8266/examples/UartDownload/UartDownload.ino index fa8ea0d61e..cf581c8890 100644 --- a/libraries/esp8266/examples/UartDownload/UartDownload.ino +++ b/libraries/esp8266/examples/UartDownload/UartDownload.ino @@ -98,12 +98,6 @@ void proxyEspSync() { // //////////////////////////////////////////////////////////////////////////////// -void preinit() { - // (no C++ in function) - // disable wifi - ESP8266WiFiClass::preinitWiFiOff(); -} - void setup() { // For `proxyEspSync()` to work, the Serial.begin() speed needs to be // 115200bps. This is the data rate used by esptool.py. It expects the Boot From 7fd41169991495483a5867ca88e5b17d9b3f3f3f Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 16 Mar 2021 11:44:58 +0100 Subject: [PATCH 06/18] per @earlephilhower review: a file was missing --- cores/esp8266/enable_wifi_at_boot_time.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cores/esp8266/enable_wifi_at_boot_time.cpp diff --git a/cores/esp8266/enable_wifi_at_boot_time.cpp b/cores/esp8266/enable_wifi_at_boot_time.cpp new file mode 100644 index 0000000000..033b327063 --- /dev/null +++ b/cores/esp8266/enable_wifi_at_boot_time.cpp @@ -0,0 +1,20 @@ +/* + * empty wrappers to play with linker and reenable wifi at boot time + */ + +#include "coredecls.h" + +extern "C" void enableWiFiAtBootTime() +{ + /* + * Called by user from anywhere, does nothing and allows overriding + * the core_esp8266_main.cpp's default disableWiFiAtBootTime() by the + * one below, at link time. + */ +} + +extern "C" void __disableWiFiAtBootTime() +{ + // overrides the default __disableWiFiAtBootTime: + // Does nothing: WiFi is enabled by default in nonos-sdk +} From c15cb5dd76cb71c2519c2b6ca9b323434e00ab59 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 16 Mar 2021 21:27:04 +0100 Subject: [PATCH 07/18] doc --- doc/esp8266wifi/generic-class.rst | 27 +++++++++++++++++++++++++++ doc/faq/readme.rst | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/doc/esp8266wifi/generic-class.rst b/doc/esp8266wifi/generic-class.rst index c75ae231f3..fac7e42686 100644 --- a/doc/esp8266wifi/generic-class.rst +++ b/doc/esp8266wifi/generic-class.rst @@ -35,6 +35,7 @@ A detailed explanation of ``WiFiEventHandler`` can be found in the section with Alternatively, check the example sketch `WiFiEvents.ino `__ available in the examples folder of the ESP8266WiFi library. +.. _wifiOffAtBoot: persistent ~~~~~~~~~~ @@ -42,6 +43,32 @@ persistent WiFi.persistent(persistent) +Starting from version 3 of this core, **persistence is disabled by default +and WiFi does not anymore automatically fires up at boot**. + +(see PR `#7902 `__). + +Previously, SDK was automatically starting WiFi at boot. This was probably +intended for the Espressif AT FW which is interactive and preserves state +accross reboots. This behavior is generally irrelevant with the Arduino +API because sketches start with WiFi.begin() or softAP... + +This change is harmless with standard sketches: Calls to +WiFi.mode()+WiFi.begin/WiFi.softAP(...) do enable radio as usual. It also +smooths current spikes at boot and also decrease DHCP stress. + +Legacy behavior can be restored by calling `enableWiFiAtBoot()` anywhere in +the code (this is a weak void function intended to play with the linker). + +.. code:: cpp + void setup () { + #ifdef WIFI_IS_OFF_AT_BOOT + enableWiFiAtBoot(); // can be called from anywhere with the same effect + #endif + .... + } + +When legacy behavior is restored thanks to this call, ESP8266 is able to reconnect to the last used WiFi network or establishes the same Access Point upon power up or reset. By default, these settings are written to specific sectors of flash memory every time they are changed in ``WiFi.begin(ssid, passphrase)`` or ``WiFi.softAP(ssid, passphrase, channel)``, and when ``WiFi.disconnect`` or ``WiFi.softAPdisconnect`` is invoked. Frequently calling these functions could cause wear on the flash memory (see issue `#1054 `__). diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index 74e2211966..6d653f5a0f 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -177,3 +177,9 @@ will need to implement an additional (short) deep sleep using ``WAKE_RF_DEFAULT``. Ref. `#3072 `__ + +My WiFi was previously automatically connected wight after booting +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This was WiFi persistence. WiFi is now indeed off at boot and is powered on +only when using the regular API. Read more at :ref:`wifiOffAtBoot`. From 9d7eb2ea8035f6562ef65d69683c93aad043c239 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 16 Mar 2021 21:28:47 +0100 Subject: [PATCH 08/18] WiFi persistence is now false by default --- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index 04ad7e11e9..3d79906acf 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -83,7 +83,7 @@ struct WiFiEventHandlerOpaque static std::list sCbEventList; -bool ESP8266WiFiGenericClass::_persistent = true; +bool ESP8266WiFiGenericClass::_persistent = false; WiFiMode_t ESP8266WiFiGenericClass::_forceSleepLastMode = WIFI_OFF; ESP8266WiFiGenericClass::ESP8266WiFiGenericClass() From eca13670dd3a16405d05c1b2e52fa00d3d4e06bd Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 16 Mar 2021 21:40:47 +0100 Subject: [PATCH 09/18] fix doc --- doc/esp8266wifi/generic-class.rst | 22 ++++++++++++---------- doc/faq/readme.rst | 7 +++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/doc/esp8266wifi/generic-class.rst b/doc/esp8266wifi/generic-class.rst index fac7e42686..37b913a4fd 100644 --- a/doc/esp8266wifi/generic-class.rst +++ b/doc/esp8266wifi/generic-class.rst @@ -49,16 +49,18 @@ and WiFi does not anymore automatically fires up at boot**. (see PR `#7902 `__). Previously, SDK was automatically starting WiFi at boot. This was probably -intended for the Espressif AT FW which is interactive and preserves state -accross reboots. This behavior is generally irrelevant with the Arduino -API because sketches start with WiFi.begin() or softAP... - -This change is harmless with standard sketches: Calls to -WiFi.mode()+WiFi.begin/WiFi.softAP(...) do enable radio as usual. It also -smooths current spikes at boot and also decrease DHCP stress. - -Legacy behavior can be restored by calling `enableWiFiAtBoot()` anywhere in -the code (this is a weak void function intended to play with the linker). +intended for the Espressif AT FW which is interactive and preserves WiFi +state accross reboots. This behavior is generally irrelevant with the +Arduino API because sketches start with ``WiFi.begin()`` or +``WiFi.softAP()``. + +This change is harmless with standard sketches: Calls to ``WiFi.mode()`` do +enable radio as usual. It also smooths current spikes at boot and also +decreases DHCP stress. + +Legacy behavior can be restored by calling ``enableWiFiAtBoot()`` from +anywhere in the code (it is a weak void function intended to play with the +linker). .. code:: cpp void setup () { diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index 6d653f5a0f..32c1dc6834 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -181,5 +181,8 @@ Ref. `#3072 `__ My WiFi was previously automatically connected wight after booting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This was WiFi persistence. WiFi is now indeed off at boot and is powered on -only when using the regular API. Read more at :ref:`wifiOffAtBoot`. +This was WiFi persistence. Starting from version 3 of this core, WiFi is +indeed off at boot and is powered on only when starting to be used with the +regular API. + +Read more at :ref:`wifiOffAtBoot <../esp8266wifi/generic-class>`. From 6d9ec263391ae8cc86aa16838fa78ab4d08f39d0 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 16 Mar 2021 21:44:55 +0100 Subject: [PATCH 10/18] ditto --- doc/esp8266wifi/generic-class.rst | 8 +++----- doc/faq/readme.rst | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/esp8266wifi/generic-class.rst b/doc/esp8266wifi/generic-class.rst index 37b913a4fd..d4a49e6f94 100644 --- a/doc/esp8266wifi/generic-class.rst +++ b/doc/esp8266wifi/generic-class.rst @@ -44,9 +44,7 @@ persistent WiFi.persistent(persistent) Starting from version 3 of this core, **persistence is disabled by default -and WiFi does not anymore automatically fires up at boot**. - -(see PR `#7902 `__). +and WiFi does not anymore automatically fires up at boot** (see PR `#7902 `__). Previously, SDK was automatically starting WiFi at boot. This was probably intended for the Espressif AT FW which is interactive and preserves WiFi @@ -55,8 +53,8 @@ Arduino API because sketches start with ``WiFi.begin()`` or ``WiFi.softAP()``. This change is harmless with standard sketches: Calls to ``WiFi.mode()`` do -enable radio as usual. It also smooths current spikes at boot and also -decreases DHCP stress. +enable radio as usual. It also smooths current spikes at boot and decreases +DHCP stress. Legacy behavior can be restored by calling ``enableWiFiAtBoot()`` from anywhere in the code (it is a weak void function intended to play with the diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index 32c1dc6834..11a956ec9b 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -178,7 +178,7 @@ will need to implement an additional (short) deep sleep using Ref. `#3072 `__ -My WiFi was previously automatically connected wight after booting +My WiFi was previously automatically connected right after booting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This was WiFi persistence. Starting from version 3 of this core, WiFi is From 8ecc7f06f91c0db825615518ee9cb4624888c041 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 16 Mar 2021 22:57:44 +0100 Subject: [PATCH 11/18] doc: remove sphinx warnings (fix links and formatting) --- doc/esp8266wifi/generic-class.rst | 2 +- doc/esp8266wifi/readme.rst | 1 + doc/faq/a01-espcomm_sync-failed.rst | 5 ++--- doc/faq/a04-board-generic-is-unknown.rst | 2 +- doc/faq/readme.rst | 2 +- doc/filesystem.rst | 16 ++++++++-------- doc/libraries.rst | 2 +- doc/mmu.rst | 2 -- doc/ota_updates/readme.rst | 2 +- 9 files changed, 16 insertions(+), 18 deletions(-) diff --git a/doc/esp8266wifi/generic-class.rst b/doc/esp8266wifi/generic-class.rst index d4a49e6f94..0255b22356 100644 --- a/doc/esp8266wifi/generic-class.rst +++ b/doc/esp8266wifi/generic-class.rst @@ -35,7 +35,6 @@ A detailed explanation of ``WiFiEventHandler`` can be found in the section with Alternatively, check the example sketch `WiFiEvents.ino `__ available in the examples folder of the ESP8266WiFi library. -.. _wifiOffAtBoot: persistent ~~~~~~~~~~ @@ -61,6 +60,7 @@ anywhere in the code (it is a weak void function intended to play with the linker). .. code:: cpp + void setup () { #ifdef WIFI_IS_OFF_AT_BOOT enableWiFiAtBoot(); // can be called from anywhere with the same effect diff --git a/doc/esp8266wifi/readme.rst b/doc/esp8266wifi/readme.rst index a2fdea701f..b9d309d5fb 100644 --- a/doc/esp8266wifi/readme.rst +++ b/doc/esp8266wifi/readme.rst @@ -164,6 +164,7 @@ WiFi Multi Example: .. code:: cpp + #include ESP8266WiFiMulti wifiMulti; diff --git a/doc/faq/a01-espcomm_sync-failed.rst b/doc/faq/a01-espcomm_sync-failed.rst index a0d575e8ed..df4d0aa177 100644 --- a/doc/faq/a01-espcomm_sync-failed.rst +++ b/doc/faq/a01-espcomm_sync-failed.rst @@ -41,9 +41,8 @@ following three things right: 1. Module is provided with enough power, 2. GPIO0, GPIO15 and CH\_PD are connected using pull up / pull down resistors, 3. Module is put into boot loader mode. -For specific details please refer to section on `Generic ESP8266 -modules <../boards.rst#generic-esp8266-modules>`__. Example modules -without USB to serial converter on board are shown below. +For specific details please refer to section on `Generic ESP8266 module <../boards.rst#generic-esp8266-module>`__. +Example modules without USB to serial converter on board are shown below. .. figure:: pictures/a01-example-boards-without-usb.png :alt: Example ESP8266 modules without USB to serial converter diff --git a/doc/faq/a04-board-generic-is-unknown.rst b/doc/faq/a04-board-generic-is-unknown.rst index b33f75edb5..88e2f3e7be 100644 --- a/doc/faq/a04-board-generic-is-unknown.rst +++ b/doc/faq/a04-board-generic-is-unknown.rst @@ -48,7 +48,7 @@ follows: Error compiling for board Generic ESP8266 Module. Below is an example messages for -`WeMos <../boards.rst#wemos-d1-r2-mini>`__: +`WeMos <../boards.rst#lolin-wemos-d1-r2-mini>`__: :: diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index 11a956ec9b..2f1303b2f5 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -185,4 +185,4 @@ This was WiFi persistence. Starting from version 3 of this core, WiFi is indeed off at boot and is powered on only when starting to be used with the regular API. -Read more at :ref:`wifiOffAtBoot <../esp8266wifi/generic-class>`. +Read more at `wifiOffAtBoot <../esp8266wifi/generic-class.rst#persistent>`__. diff --git a/doc/filesystem.rst b/doc/filesystem.rst index a5a3cffbbe..cc6c51280c 100644 --- a/doc/filesystem.rst +++ b/doc/filesystem.rst @@ -474,8 +474,8 @@ Performs the same operation as ``info`` but allows for reporting greater than 4GB for filesystem size/used/etc. Should be used with the SD and SDFS filesystems since most SD cards today are greater than 4GB in size. -setTimeCallback(time_t (*cb)(void)) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +setTimeCallback(time_t (\*cb)(void)) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: cpp @@ -574,8 +574,8 @@ rewind Resets the internal pointer to the start of the directory. -setTimeCallback(time_t (*cb)(void)) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +setTimeCallback(time_t (\*cb)(void)) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sets the time callback for any files accessed from this Dir object via openNextFile. Note that the SD and SDFS filesystems only support a filesystem-wide callback and @@ -693,7 +693,7 @@ Close the file. No other operations should be performed on *File* object after ``close`` function was called. openNextFile (compatibiity method, not recommended for new code) -~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: cpp @@ -705,7 +705,7 @@ Opens the next file in the directory pointed to by the File. Only valid when ``File.isDirectory() == true``. rewindDirectory (compatibiity method, not recommended for new code) -~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: cpp @@ -718,8 +718,8 @@ rewindDirectory (compatibiity method, not recommended for new code) Resets the ``openNextFile`` pointer to the top of the directory. Only valid when ``File.isDirectory() == true``. -setTimeCallback(time_t (*cb)(void)) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +setTimeCallback(time_t (\*cb)(void)) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sets the time callback for this specific file. Note that the SD and SDFS filesystems only support a filesystem-wide callback and calls to diff --git a/doc/libraries.rst b/doc/libraries.rst index bfdc05d950..2c283814d1 100644 --- a/doc/libraries.rst +++ b/doc/libraries.rst @@ -87,7 +87,7 @@ Some ESP-specific APIs related to deep sleep, RTC and flash memories are availab ``ESP.getHeapFragmentation()`` returns the fragmentation metric (0% is clean, more than ~50% is not harmless) -``ESP.getMaxFreeBlockSize()`` returns the largest contiguous free RAM block in the heap, useful for checking heap fragmentation. **NOTE:** Maximum ``malloc()``able block will be smaller due to memory manager overheads. +``ESP.getMaxFreeBlockSize()`` returns the largest contiguous free RAM block in the heap, useful for checking heap fragmentation. **NOTE:** Maximum ``malloc()`` -able block will be smaller due to memory manager overheads. ``ESP.getChipId()`` returns the ESP8266 chip ID as a 32-bit integer. diff --git a/doc/mmu.rst b/doc/mmu.rst index 41446cf76c..9c3ec48acb 100644 --- a/doc/mmu.rst +++ b/doc/mmu.rst @@ -233,5 +233,3 @@ address range of IRAM or DRAM. uint8_t mmu_set_uint8(void *p8, const uint8_t val); uint16_t mmu_set_uint16(uint16_t *p16, const uint16_t val); int16_t mmu_set_int16(int16_t *p16, const int16_t val); - -:: diff --git a/doc/ota_updates/readme.rst b/doc/ota_updates/readme.rst index 5575d45f24..3ab136cf3d 100755 --- a/doc/ota_updates/readme.rst +++ b/doc/ota_updates/readme.rst @@ -161,7 +161,7 @@ If signing is desired, sign the gzip compressed file *after* compression. Updating apps in the field to support compression ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If you have applications deployed in the field and wish to update them to support compressed OTA uploads, you will need to first recompile the application, then _upload the uncompressed `.bin` file once_. Attempting to upload a `gzip` compressed binary to a legacy app will result in the Updater rejecting the upload as it does not understand the `gzip` format. After this initial upload, which will include the new bootloader and `Updater` class with compression support, compressed updates can then be used. +If you have applications deployed in the field and wish to update them to support compressed OTA uploads, you will need to first recompile the application, then _upload the uncompressed `.bin` file once. Attempting to upload a `gzip` compressed binary to a legacy app will result in the Updater rejecting the upload as it does not understand the `gzip` format. After this initial upload, which will include the new bootloader and `Updater` class with compression support, compressed updates can then be used. Safety From 8332c42a1406c4c5ff9f5c06bca81aecb10b0f99 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 16 Mar 2021 23:02:10 +0100 Subject: [PATCH 12/18] fix link name --- doc/faq/readme.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index 2f1303b2f5..b8447bec0f 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -185,4 +185,4 @@ This was WiFi persistence. Starting from version 3 of this core, WiFi is indeed off at boot and is powered on only when starting to be used with the regular API. -Read more at `wifiOffAtBoot <../esp8266wifi/generic-class.rst#persistent>`__. +Read more at `former WiFi persistent mode <../esp8266wifi/generic-class.rst#persistent>`__. From df8f8a7bbcad3bd04fcfa7a4896beca3d7098e23 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 18 Mar 2021 22:48:39 +0100 Subject: [PATCH 13/18] fix doc --- doc/esp8266wifi/generic-class.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/esp8266wifi/generic-class.rst b/doc/esp8266wifi/generic-class.rst index 0255b22356..28664dbbcc 100644 --- a/doc/esp8266wifi/generic-class.rst +++ b/doc/esp8266wifi/generic-class.rst @@ -55,7 +55,7 @@ This change is harmless with standard sketches: Calls to ``WiFi.mode()`` do enable radio as usual. It also smooths current spikes at boot and decreases DHCP stress. -Legacy behavior can be restored by calling ``enableWiFiAtBoot()`` from +Legacy behavior can be restored by calling ``enableWiFiAtBootTime()`` from anywhere in the code (it is a weak void function intended to play with the linker). @@ -63,7 +63,7 @@ linker). void setup () { #ifdef WIFI_IS_OFF_AT_BOOT - enableWiFiAtBoot(); // can be called from anywhere with the same effect + enableWiFiAtBootTime(); // can be called from anywhere with the same effect #endif .... } From 20020c04909770212a9e649bdbb8583d6bf5159c Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 18 Mar 2021 23:13:49 +0100 Subject: [PATCH 14/18] legacy: restore persistence --- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h | 2 +- .../ESP8266WiFi/src}/enable_wifi_at_boot_time.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) rename {cores/esp8266 => libraries/ESP8266WiFi/src}/enable_wifi_at_boot_time.cpp (55%) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index d648928c9f..0e6a11e39b 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -120,7 +120,7 @@ class ESP8266WiFiGenericClass { void setOutputPower(float dBm); - void persistent(bool persistent); + static void persistent(bool persistent); bool mode(WiFiMode_t, WiFiState* state = nullptr); WiFiMode_t getMode(); diff --git a/cores/esp8266/enable_wifi_at_boot_time.cpp b/libraries/ESP8266WiFi/src/enable_wifi_at_boot_time.cpp similarity index 55% rename from cores/esp8266/enable_wifi_at_boot_time.cpp rename to libraries/ESP8266WiFi/src/enable_wifi_at_boot_time.cpp index 033b327063..575d0317ed 100644 --- a/cores/esp8266/enable_wifi_at_boot_time.cpp +++ b/libraries/ESP8266WiFi/src/enable_wifi_at_boot_time.cpp @@ -4,6 +4,8 @@ #include "coredecls.h" +#include + extern "C" void enableWiFiAtBootTime() { /* @@ -16,5 +18,11 @@ extern "C" void enableWiFiAtBootTime() extern "C" void __disableWiFiAtBootTime() { // overrides the default __disableWiFiAtBootTime: - // Does nothing: WiFi is enabled by default in nonos-sdk + // Does (almost) nothing: WiFi is enabled by default in nonos-sdk + + // ... but restores legacy WiFi credentials persistence to true at boot time + // (can be still overriden by user before setting up WiFi, like before) + + // (note: c++ ctors not called yet at this point) + ESP8266WiFiClass::persistent(true); } From 2eb8bb113a4b15e3927f2b036929b484210cac54 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 31 Mar 2021 02:20:08 +0200 Subject: [PATCH 15/18] undeprecate preinit() --- cores/esp8266/core_esp8266_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 589e44d675..2fdab570d2 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -371,7 +371,7 @@ extern "C" void user_init(void) { #if defined(MMU_IRAM_HEAP) umm_init_iram(); #endif - preinit(); // deprecated + preinit(); // Prior to C++ Dynamic Init (not related to above init() ). Meant to be user redefinable. __disableWiFiAtBootTime(); // default weak function disables WiFi ets_task(loop_task, From da5966bea3a6b7a35667d76ff7d77a119b481ce5 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 31 Mar 2021 02:27:22 +0200 Subject: [PATCH 16/18] move force modem up to when mode has changed (per @mcspr review) --- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index a1219d77bf..02ccaf6d99 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -418,12 +418,6 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m, WiFiState* state) { DEBUG_WIFI("core: state is useless without SHUTDOWN or RESUME\n"); } - if (wifi_fpm_get_sleep_type() != NONE_SLEEP_T) { - // wifi starts asleep by default - wifi_fpm_do_wakeup(); - wifi_fpm_close(); - } - if(_persistent){ if(wifi_get_opmode() == (uint8) m && wifi_get_opmode_default() == (uint8) m){ return true; @@ -432,6 +426,12 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m, WiFiState* state) { return true; } + if (wifi_fpm_get_sleep_type() != NONE_SLEEP_T) { + // wifi starts asleep by default + wifi_fpm_do_wakeup(); + wifi_fpm_close(); + } + bool ret = false; ETS_UART_INTR_DISABLE(); if(_persistent) { From f0f1f550e9fe903324ac0019506545fb7a3c6122 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 31 Mar 2021 02:35:05 +0200 Subject: [PATCH 17/18] do not wake up from sleep when mode if OFF --- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index 02ccaf6d99..7518f3c598 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -426,7 +426,7 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m, WiFiState* state) { return true; } - if (wifi_fpm_get_sleep_type() != NONE_SLEEP_T) { + if (m != WIFI_OFF && wifi_fpm_get_sleep_type() != NONE_SLEEP_T) { // wifi starts asleep by default wifi_fpm_do_wakeup(); wifi_fpm_close(); From 5d12aa2b857ce4dfd1677a87ea964660cd6e79b0 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Fri, 9 Apr 2021 22:52:53 +0200 Subject: [PATCH 18/18] fix doc per review --- doc/esp8266wifi/generic-class.rst | 2 +- doc/faq/readme.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/esp8266wifi/generic-class.rst b/doc/esp8266wifi/generic-class.rst index 28664dbbcc..bf6228d4e1 100644 --- a/doc/esp8266wifi/generic-class.rst +++ b/doc/esp8266wifi/generic-class.rst @@ -43,7 +43,7 @@ persistent WiFi.persistent(persistent) Starting from version 3 of this core, **persistence is disabled by default -and WiFi does not anymore automatically fires up at boot** (see PR `#7902 `__). +and WiFi does not start automatically at boot** (see PR `#7902 `__). Previously, SDK was automatically starting WiFi at boot. This was probably intended for the Espressif AT FW which is interactive and preserves WiFi diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index b8447bec0f..4fb065a38f 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -178,8 +178,8 @@ will need to implement an additional (short) deep sleep using Ref. `#3072 `__ -My WiFi was previously automatically connected right after booting -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +My WiFi was previously automatically connected right after booting, but isn't anymore +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This was WiFi persistence. Starting from version 3 of this core, WiFi is indeed off at boot and is powered on only when starting to be used with the