|
164 | 164 | #endif
|
165 | 165 |
|
166 | 166 | #define HTTP_PORT 80
|
| 167 | +#define DNS_PORT 53 |
167 | 168 |
|
168 | 169 | #include <DNSServer.h>
|
169 | 170 | #include <memory>
|
@@ -828,6 +829,11 @@ class ESPAsync_WiFiManager_Lite
|
828 | 829 | //// New DRD ////
|
829 | 830 | #endif
|
830 | 831 |
|
| 832 | + if ( configuration_mode && dnsServer) |
| 833 | + { |
| 834 | + dnsServer->processNextRequest(); |
| 835 | + } |
| 836 | + |
831 | 837 | if ( !configuration_mode && (curMillis > checkstatus_timeout) )
|
832 | 838 | {
|
833 | 839 | if (WiFi.status() == WL_CONNECTED)
|
@@ -936,6 +942,16 @@ class ESPAsync_WiFiManager_Lite
|
936 | 942 | ESP_WML_LOGINFO(F("run: got WiFi back"));
|
937 | 943 | // turn the LED_BUILTIN OFF to tell us we exit configuration mode.
|
938 | 944 | digitalWrite(LED_BUILTIN, LED_OFF);
|
| 945 | + if (dnsServer) { |
| 946 | + dnsServer->stop(); |
| 947 | + delete dnsServer; |
| 948 | + dnsServer = nullptr; |
| 949 | + } |
| 950 | + if (server) { |
| 951 | + server->end(); |
| 952 | + delete server; |
| 953 | + server = nullptr; |
| 954 | + } |
939 | 955 | }
|
940 | 956 | }
|
941 | 957 |
|
@@ -1248,6 +1264,7 @@ class ESPAsync_WiFiManager_Lite
|
1248 | 1264 | String ipAddress = "0.0.0.0";
|
1249 | 1265 |
|
1250 | 1266 | AsyncWebServer *server = NULL;
|
| 1267 | + DNSServer *dnsServer = nullptr; |
1251 | 1268 |
|
1252 | 1269 | //KH, for ESP32
|
1253 | 1270 | #ifdef ESP8266
|
@@ -2967,10 +2984,21 @@ class ESPAsync_WiFiManager_Lite
|
2967 | 2984 | server = new AsyncWebServer(HTTP_PORT);
|
2968 | 2985 | }
|
2969 | 2986 |
|
| 2987 | + if (!dnsServer) |
| 2988 | + { |
| 2989 | + dnsServer = new DNSServer(); |
| 2990 | + } |
| 2991 | + |
2970 | 2992 | //See https://stackoverflow.com/questions/39803135/c-unresolved-overloaded-function-type?rq=1
|
2971 | 2993 | if (server)
|
2972 | 2994 | {
|
2973 |
| - server->on("/", HTTP_GET, [this](AsyncWebServerRequest * request) |
| 2995 | + // CaptivePortal |
| 2996 | + // if DNSServer is started with "*" for domain name, it will reply with provided IP to all DNS requests |
| 2997 | + dnsServer->start(DNS_PORT, "*", portal_apIP); |
| 2998 | + //server->addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); //only when requested from AP |
| 2999 | + // replay to all requests with same HTML |
| 3000 | + //server->on("/", HTTP_GET, [this](AsyncWebServerRequest * request) |
| 3001 | + server->onNotFound([this](AsyncWebServerRequest *request) |
2974 | 3002 | {
|
2975 | 3003 | handleRequest(request);
|
2976 | 3004 | });
|
|
0 commit comments