Skip to content

Commit 9f99c76

Browse files
committed
use netif callback to restart mDNS
1 parent 89068d3 commit 9f99c76

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

libraries/ESP8266mDNS/examples/LEAmDNS/mDNS_Clock_v2/mDNS_Clock_v2.ino

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <ESP8266WiFi.h>
3636
#include <WiFiClient.h>
3737
#include <ESP8266WebServer.h>
38+
#include <LwipIntf.h>
3839
#include <time.h>
3940

4041
// uses API MDNSApiVersion::LEAv2
@@ -62,6 +63,7 @@
6263
#define DST_OFFSET 1 // CEST
6364
#define UPDATE_CYCLE (1 * 1000) // every second
6465

66+
#define START_AP_AFTER_MS 10000 //60000 // start AP after delay
6567
#define SERVICE_PORT 80 // HTTP port
6668

6769
#ifndef STASSID
@@ -186,8 +188,23 @@ void setup(void) {
186188
Serial.begin(115200);
187189

188190
// 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);
191208
WiFi.begin(ssid, password);
192209
Serial.println("");
193210

@@ -246,4 +263,17 @@ void loop(void) {
246263
responder.announce();
247264
}
248265
}
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+
}
249279
}

0 commit comments

Comments
 (0)