|
| 1 | + |
| 2 | +#include <ESP8266WiFi.h> |
| 3 | + |
| 4 | +#ifndef STASSID |
| 5 | +#define STASSID "your-ssid" |
| 6 | +#define STAPSK "your-password" |
| 7 | +#endif |
| 8 | + |
| 9 | +// preinit() is called before system startup |
| 10 | +// from nonos-sdk's user entry point user_init() |
| 11 | + |
| 12 | +void preinit() { |
| 13 | + // Global WiFi constructors are not called yet |
| 14 | + // (global class instances like WiFi, Serial... are not yet initialized).. |
| 15 | + // No global object methods or C++ exceptions can be called in here! |
| 16 | + //The below is a static class method, which is similar to a function, so it's ok. |
| 17 | + ESP8266WiFiClass::preinitWiFiOff(); |
| 18 | +} |
| 19 | + |
| 20 | +void setup() { |
| 21 | + Serial.begin(115200); |
| 22 | + Serial.setDebugOutput(true); |
| 23 | + Serial.println("sleeping 5s"); |
| 24 | + |
| 25 | + // during this period, a simple amp meter shows |
| 26 | + // an average of 20mA with a Wemos D1 mini |
| 27 | + // a DSO is needed to check #2111 |
| 28 | + delay(5000); |
| 29 | + |
| 30 | + Serial.println("waking WiFi up, sleeping 5s"); |
| 31 | + WiFi.forceSleepWake(); |
| 32 | + |
| 33 | + // amp meter raises to 75mA |
| 34 | + delay(5000); |
| 35 | + |
| 36 | + Serial.println("connecting to AP " STASSID); |
| 37 | + WiFi.mode(WIFI_STA); |
| 38 | + WiFi.begin(STASSID, STAPSK); |
| 39 | + |
| 40 | + for (bool configured = false; !configured;) { |
| 41 | + for (auto addr : addrList) |
| 42 | + if ((configured = !addr.isLocal() && addr.ifnumber() == STATION_IF)) { |
| 43 | + Serial.printf("STA: IF='%s' hostname='%s' addr= %s\n", |
| 44 | + addr.ifname().c_str(), |
| 45 | + addr.ifhostname(), |
| 46 | + addr.toString().c_str()); |
| 47 | + break; |
| 48 | + } |
| 49 | + Serial.print('.'); |
| 50 | + delay(500); |
| 51 | + } |
| 52 | + |
| 53 | + // amp meter cycles within 75-80 mA |
| 54 | + |
| 55 | +} |
| 56 | + |
| 57 | +void loop() { |
| 58 | +} |
0 commit comments