1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

weak hook preinit() #2111 #2133 #2136 (#5395)

* weak hook early_setup() #2111 #2133 #2136

* rename to early_init (more "c" vs early_setup which is more "c++arduino")

* example

* improve earlyWiFi example, slightly change AddrList interface, move WiFi sketches into WiFi examples

* fix CI

* fix local CI runner

* fix local CI runner

* rename early_init() to preinit()

* + static ESP8266WiFiClass::preinit_wifi_off()

* update early disable wifi example

* example update

* IPv6 example update

* Update ESP8266WiFiGeneric.h

camelCase for static method name

* Update ESP8266WiFiGeneric.cpp

camelCase for static method name

* Update EarlyDisableWiFi.ino

Expand comment, fix static method name

* Update core_esp8266_main.cpp

Expanded comment.

* Update core_esp8266_main.cpp

Expanded comment

* Update EarlyDisableWiFi.ino

Expanded comment
This commit is contained in:
david gauchard
2018-12-04 05:54:27 +01:00
committed by Earle F. Philhower, III
parent 2ec3daa225
commit 216680bb57
5 changed files with 92 additions and 2 deletions

View File

@ -0,0 +1,58 @@
#include <ESP8266WiFi.h>
#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() {
}