|
164 | 164 | #endif
|
165 | 165 |
|
166 | 166 | #define HTTP_PORT 80
|
| 167 | +#define DNS_PORT 53 |
167 | 168 |
|
168 |
| -#include <DNSServer.h> |
| 169 | +#include <ESPAsyncDNSServer.h> |
169 | 170 | #include <memory>
|
170 | 171 | #undef min
|
171 | 172 | #undef max
|
@@ -544,6 +545,11 @@ class ESPAsync_WiFiManager_Lite
|
544 | 545 |
|
545 | 546 | ~ESPAsync_WiFiManager_Lite()
|
546 | 547 | {
|
| 548 | + if (dnsServer) |
| 549 | + { |
| 550 | + delete dnsServer; |
| 551 | + } |
| 552 | + |
547 | 553 | if (server)
|
548 | 554 | {
|
549 | 555 | delete server;
|
@@ -818,7 +824,7 @@ class ESPAsync_WiFiManager_Lite
|
818 | 824 |
|
819 | 825 | #if USING_MRD
|
820 | 826 | //// New MRD ////
|
821 |
| - // Call the mulyi reset detector loop method every so often, |
| 827 | + // Call the multi reset detector loop method every so often, |
822 | 828 | // so that it can recognise when the timeout expires.
|
823 | 829 | // You can also call mrd.stop() when you wish to no longer
|
824 | 830 | // consider the next reset as a multi reset.
|
@@ -940,12 +946,26 @@ class ESPAsync_WiFiManager_Lite
|
940 | 946 | }
|
941 | 947 | else if (configuration_mode)
|
942 | 948 | {
|
| 949 | + // WiFi is connected and we are in configuration_mode |
943 | 950 | configuration_mode = false;
|
944 | 951 | ESP_WML_LOGINFO(F("run: got WiFi back"));
|
| 952 | + |
945 | 953 | #if USE_LED_BUILTIN
|
946 | 954 | // turn the LED_BUILTIN OFF to tell us we exit configuration mode.
|
947 | 955 | digitalWrite(LED_BUILTIN, LED_OFF);
|
948 | 956 | #endif
|
| 957 | + |
| 958 | + if (dnsServer) { |
| 959 | + dnsServer->stop(); |
| 960 | + delete dnsServer; |
| 961 | + dnsServer = nullptr; |
| 962 | + } |
| 963 | + |
| 964 | + if (server) { |
| 965 | + server->end(); |
| 966 | + delete server; |
| 967 | + server = nullptr; |
| 968 | + } |
949 | 969 | }
|
950 | 970 | }
|
951 | 971 |
|
@@ -1255,7 +1275,8 @@ class ESPAsync_WiFiManager_Lite
|
1255 | 1275 | private:
|
1256 | 1276 | String ipAddress = "0.0.0.0";
|
1257 | 1277 |
|
1258 |
| - AsyncWebServer *server = NULL; |
| 1278 | + AsyncWebServer *server = nullptr; |
| 1279 | + AsyncDNSServer *dnsServer = nullptr; |
1259 | 1280 |
|
1260 | 1281 | //KH, for ESP32
|
1261 | 1282 | #ifdef ESP8266
|
@@ -2964,18 +2985,24 @@ class ESPAsync_WiFiManager_Lite
|
2964 | 2985 |
|
2965 | 2986 | delay(100); // ref: https://github.com/espressif/arduino-esp32/issues/985#issuecomment-359157428
|
2966 | 2987 |
|
2967 |
| - // Move up for ESP8266 |
2968 |
| - //WiFi.softAPConfig(portal_apIP, portal_apIP, IPAddress(255, 255, 255, 0)); |
2969 |
| - |
2970 | 2988 | if (!server)
|
2971 | 2989 | {
|
2972 | 2990 | server = new AsyncWebServer(HTTP_PORT);
|
2973 | 2991 | }
|
2974 | 2992 |
|
| 2993 | + if (!dnsServer) |
| 2994 | + { |
| 2995 | + dnsServer = new AsyncDNSServer(); |
| 2996 | + } |
| 2997 | + |
2975 | 2998 | //See https://stackoverflow.com/questions/39803135/c-unresolved-overloaded-function-type?rq=1
|
2976 |
| - if (server) |
| 2999 | + if (server && dnsServer) |
2977 | 3000 | {
|
2978 |
| - server->on("/", HTTP_GET, [this](AsyncWebServerRequest * request) |
| 3001 | + // CaptivePortal |
| 3002 | + // if DNSServer is started with "*" for domain name, it will reply with provided IP to all DNS requests |
| 3003 | + dnsServer->start(DNS_PORT, "*", portal_apIP); |
| 3004 | + // replay to all requests with same HTML |
| 3005 | + server->onNotFound([this](AsyncWebServerRequest *request) |
2979 | 3006 | {
|
2980 | 3007 | handleRequest(request);
|
2981 | 3008 | });
|
|
0 commit comments