Skip to content

Commit 64ff4b0

Browse files
committed
Merge branch 'WiFiOffAtBoot' of github.com:d-a-v/Arduino into WiFiOffAtBoot
2 parents 55cee05 + 7756427 commit 64ff4b0

File tree

11 files changed

+23
-114
lines changed

11 files changed

+23
-114
lines changed

cores/esp8266/core_esp8266_features.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define CORE_HAS_UMM
3232

3333
#define WIFI_HAS_EVENT_CALLBACK
34+
#define WIFI_IS_OFF_AT_BOOT
3435

3536
#include <stdlib.h> // malloc()
3637
#include <stddef.h> // size_t
@@ -104,6 +105,8 @@ uint64_t micros64(void);
104105
void delay(unsigned long);
105106
void delayMicroseconds(unsigned int us);
106107

108+
void enableWiFiAtBootTime (void) __attribute__((noinline));
109+
107110
#if defined(F_CPU) || defined(CORE_MOCK)
108111
#ifdef __cplusplus
109112
constexpr

cores/esp8266/core_esp8266_main.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,18 @@ extern "C" void app_entry (void)
332332
extern "C" void preinit (void) __attribute__((weak));
333333
extern "C" void preinit (void)
334334
{
335-
/* do nothing by default */
335+
/* does nothing, kept for backward compatibility */
336+
}
337+
338+
extern "C" void __disableWiFiAtBootTime (void) __attribute__((weak));
339+
extern "C" void __disableWiFiAtBootTime (void)
340+
{
341+
// Starting from arduino core v3: wifi is disabled at boot time
342+
// WiFi.begin() or WiFi.softAP() will wake WiFi up
343+
wifi_set_opmode_current(0/*WIFI_OFF*/);
344+
wifi_fpm_set_sleep_type(MODEM_SLEEP_T);
345+
wifi_fpm_open();
346+
wifi_fpm_do_sleep(0xFFFFFFF);
336347
}
337348

338349
extern "C" void user_init(void) {
@@ -360,7 +371,8 @@ extern "C" void user_init(void) {
360371
#if defined(MMU_IRAM_HEAP)
361372
umm_init_iram();
362373
#endif
363-
preinit(); // Prior to C++ Dynamic Init (not related to above init() ). Meant to be user redefinable.
374+
preinit(); // deprecated
375+
__disableWiFiAtBootTime(); // default weak function disables WiFi
364376

365377
ets_task(loop_task,
366378
LOOP_TASK_PRIORITY, s_loop_queue,

cores/esp8266/coredecls.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void esp_schedule();
1818
void tune_timeshift64 (uint64_t now_us);
1919
void disable_extra4k_at_link_time (void) __attribute__((noinline));
2020
bool sntp_set_timezone_in_seconds(int32_t timezone);
21+
void __disableWiFiAtBootTime (void) __attribute__((noinline));
2122
void __real_system_restart_local() __attribute__((noreturn));
2223

2324
uint32_t sqrt32 (uint32_t n);
@@ -34,6 +35,6 @@ using TrivialCB = std::function<void()>;
3435
void settimeofday_cb (const BoolCB& cb);
3536
void settimeofday_cb (const TrivialCB& cb);
3637

37-
#endif
38+
#endif // __cplusplus
3839

3940
#endif // __COREDECLS_H

libraries/ESP8266WiFi/examples/EarlyDisableWiFi/EarlyDisableWiFi.ino

Lines changed: 0 additions & 59 deletions
This file was deleted.

libraries/ESP8266WiFi/examples/WiFiShutdown/WiFiShutdown.ino

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ WiFiState state;
2424
const char* ssid = STASSID;
2525
const char* password = STAPSK;
2626

27-
void preinit(void) {
28-
// Make sure, wifi stays off after boot.
29-
ESP8266WiFiClass::preinitWiFiOff();
30-
}
31-
3227
void setup() {
3328
Serial.begin(74880);
3429
//Serial.setDebugOutput(true); // If you need debug output

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m, WiFiState* state) {
419419
}
420420

421421
if (wifi_fpm_get_sleep_type() != NONE_SLEEP_T) {
422-
// wifi may have been put asleep by ESP8266WiFiGenericClass::preinitWiFiOff
422+
// wifi starts asleep by default
423423
wifi_fpm_do_wakeup();
424424
wifi_fpm_close();
425425
}
@@ -855,25 +855,7 @@ bool ESP8266WiFiGenericClass::resumeFromShutdown (WiFiState* state)
855855
return true;
856856
}
857857

858-
//meant to be called from user-defined ::preinit()
859858
void ESP8266WiFiGenericClass::preinitWiFiOff () {
860-
// https://github.com/esp8266/Arduino/issues/2111#issuecomment-224251391
861-
// WiFi.persistent(false);
862-
// WiFi.mode(WIFI_OFF);
863-
// WiFi.forceSleepBegin();
864-
865-
//WiFi.mode(WIFI_OFF) equivalent:
866-
// datasheet:
867-
// Set Wi-Fi working mode to Station mode, SoftAP
868-
// or Station + SoftAP, and do not update flash
869-
// (not persistent)
870-
wifi_set_opmode_current(WIFI_OFF);
871-
872-
//WiFi.forceSleepBegin(/*default*/0) equivalent:
873-
// sleep forever until wifi_fpm_do_wakeup() is called
874-
wifi_fpm_set_sleep_type(MODEM_SLEEP_T);
875-
wifi_fpm_open();
876-
wifi_fpm_do_sleep(0xFFFFFFF);
877-
878-
// use WiFi.forceSleepWake() to wake WiFi up
859+
// It was meant to be called from user-defined ::preinit()
860+
// It is now deprecated by enableWiFiAtBootTime() and __disableWiFiAtBootTime()
879861
}

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class ESP8266WiFiGenericClass {
133133

134134
static uint32_t shutdownCRC (const WiFiState* state);
135135
static bool shutdownValidCRC (const WiFiState* state);
136-
static void preinitWiFiOff (); //meant to be called in user-defined preinit()
136+
static void preinitWiFiOff () __attribute__((deprecated("WiFi is off by default at boot, use enableWiFiAtBoot() for legacy behavior")));
137137

138138
protected:
139139
static bool _persistent;

libraries/esp8266/examples/SerialStress/SerialStress.ino

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ void error(const char* what) {
5757
}
5858
}
5959

60-
void preinit() {
61-
// (no C++ in function)
62-
// disable wifi
63-
ESP8266WiFiClass::preinitWiFiOff();
64-
}
65-
6660
void setup() {
6761
pinMode(LED_BUILTIN, OUTPUT);
6862

libraries/lwIP_w5500/examples/TCPClient/TCPClient.ino

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//or #include <ENC28J60lwIP.h>
1010

1111
#include <WiFiClient.h> // WiFiClient (-> TCPClient)
12-
#include <ESP8266WiFi.h> // ESP8266WiFiClass::preinitWiFiOff()
1312

1413
const char* host = "djxmmx.net";
1514
const uint16_t port = 17;
@@ -19,12 +18,6 @@ using TCPClient = WiFiClient;
1918
#define CSPIN 16 // wemos/lolin/nodemcu D0
2019
Wiznet5500lwIP eth(CSPIN);
2120

22-
void preinit() {
23-
// (no C++ in function)
24-
// disable wifi
25-
ESP8266WiFiClass::preinitWiFiOff();
26-
}
27-
2821
void setup() {
2922
Serial.begin(115200);
3023

tests/device/test_serial/test_serial.ino

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ static uint64_t in_total = 0, in_prev = 0;
3333
static uint64_t start_ms, last_ms;
3434
static uint64_t timeout;
3535

36-
void preinit() {
37-
// (no C++ in function)
38-
// disable wifi
39-
ESP8266WiFiClass::preinitWiFiOff();
40-
}
41-
4236
void setup()
4337
{
4438
Serial.begin(SSBAUD);

0 commit comments

Comments
 (0)