|
35 | 35 | #include <ESP8266WiFi.h>
|
36 | 36 | #include <WiFiClient.h>
|
37 | 37 | #include <ESP8266WebServer.h>
|
| 38 | +#include <LwipIntf.h> |
38 | 39 | #include <time.h>
|
39 | 40 |
|
40 | 41 | // uses API MDNSApiVersion::LEAv2
|
|
62 | 63 | #define DST_OFFSET 1 // CEST
|
63 | 64 | #define UPDATE_CYCLE (1 * 1000) // every second
|
64 | 65 |
|
| 66 | +#define START_AP_AFTER_MS 10000 //60000 // start AP after delay |
65 | 67 | #define SERVICE_PORT 80 // HTTP port
|
66 | 68 |
|
67 | 69 | #ifndef STASSID
|
@@ -186,8 +188,23 @@ void setup(void) {
|
186 | 188 | Serial.begin(115200);
|
187 | 189 |
|
188 | 190 | // Connect to WiFi network
|
189 |
| - WiFi.mode(WIFI_AP_STA); |
190 |
| - WiFi.softAP(APSSID, APPSK); |
| 191 | + |
| 192 | + WiFi.persistent(false); |
| 193 | + |
| 194 | + // useless informative callback |
| 195 | + if (!LwipIntf::stateUpCB([](netif* nif) |
| 196 | + { |
| 197 | + Serial.printf("New interface %c%c(%d) is up(%d)\n", |
| 198 | + nif->name[0], |
| 199 | + nif->name[1], |
| 200 | + netif_get_index(nif), |
| 201 | + netif_is_up(nif)); |
| 202 | + })) |
| 203 | + { |
| 204 | + Serial.println("Error: could not add useless informative callback\n"); |
| 205 | + } |
| 206 | + |
| 207 | + WiFi.mode(WIFI_STA); |
191 | 208 | WiFi.begin(ssid, password);
|
192 | 209 | Serial.println("");
|
193 | 210 |
|
@@ -246,4 +263,17 @@ void loop(void) {
|
246 | 263 | responder.announce();
|
247 | 264 | }
|
248 | 265 | }
|
| 266 | + |
| 267 | + static bool AP_started = false; |
| 268 | + if (!AP_started && millis() > START_AP_AFTER_MS) |
| 269 | + { |
| 270 | + AP_started = true; |
| 271 | + Serial.printf("Starting AP...\n"); |
| 272 | + WiFi.mode(WIFI_AP_STA); |
| 273 | + WiFi.softAP(APSSID, APPSK); |
| 274 | + Serial.printf("AP started...(%s:%s, %s)\n", |
| 275 | + WiFi.softAPSSID().c_str(), |
| 276 | + WiFi.softAPPSK().c_str(), |
| 277 | + WiFi.softAPIP().toString().c_str()); |
| 278 | + } |
249 | 279 | }
|
0 commit comments