-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[BREAKING] Disable WiFi at boot by default #7902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ab16b8c
6310da8
330b229
68d338e
253bbc5
5ead6a2
b2a53b7
7756427
64ff4b0
2d4ca1d
8510670
1059beb
7fd4116
c15cb5d
9d7eb2e
227e557
eca1367
8b0d641
6d9ec26
8ecc7f0
8332c42
df8f8a7
20020c0
4e5abc6
2eb8bb1
da5966b
f0f1f55
77087f0
5d12aa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,7 @@ WiFi Multi | |
Example: | ||
|
||
.. code:: cpp | ||
|
||
#include <ESP8266WiFiMulti.h> | ||
|
||
ESP8266WiFiMulti wifiMulti; | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ struct WiFiEventHandlerOpaque | |
|
||
static std::list<WiFiEventHandler> sCbEventList; | ||
|
||
bool ESP8266WiFiGenericClass::_persistent = true; | ||
bool ESP8266WiFiGenericClass::_persistent = false; | ||
WiFiMode_t ESP8266WiFiGenericClass::_forceSleepLastMode = WIFI_OFF; | ||
|
||
ESP8266WiFiGenericClass::ESP8266WiFiGenericClass() | ||
|
@@ -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 may have been put asleep by ESP8266WiFiGenericClass::preinitWiFiOff | ||
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 (m != WIFI_OFF && wifi_fpm_get_sleep_type() != NONE_SLEEP_T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small side note / question, will test some time later today |
||
// wifi starts asleep by default | ||
wifi_fpm_do_wakeup(); | ||
wifi_fpm_close(); | ||
} | ||
|
||
bool ret = false; | ||
ETS_UART_INTR_DISABLE(); | ||
if(_persistent) { | ||
|
@@ -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() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* empty wrappers to play with linker and reenable wifi at boot time | ||
*/ | ||
|
||
#include "coredecls.h" | ||
|
||
#include <ESP8266WiFi.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 (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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest highlighting here that the prior to v3 persistent was defaulted to true, and so the wifi creds were always stored to flash when the WiFi was configured, which could lead to a reduced life of the wifi config flash sector, and hence the entire ESP. Starting with v3, persistent defaults to false, so creds aren't stored by the SDK in the flash sector and hence don't survive across reboots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devyte I think this is not precisely correct. Settings that were once persisted, remain that way, so thereafter,
WiFi.begin()
, with noWiFi.persistent(true)
in the sketch, as long asenableWiFiAtBootTime()
is somewhere in the sketch, will suffice to auto-connect to the AP.