From 8490240f7f18f58403adb93c05d5583118894c97 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 18 Oct 2022 22:58:07 +0200 Subject: [PATCH] Fix Captive Portal --- src/sys/net/hasp_wifi.cpp | 2 +- src/sys/svc/hasp_http.cpp | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/sys/net/hasp_wifi.cpp b/src/sys/net/hasp_wifi.cpp index d5e52085..48be7be1 100644 --- a/src/sys/net/hasp_wifi.cpp +++ b/src/sys/net/hasp_wifi.cpp @@ -498,7 +498,7 @@ bool wifiEvery5Seconds() return false; } #else - if(WiFi.getMode() == WIFI_AP) { + if(WiFi.getMode() != WIFI_STA) { return false; } #endif diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index c5741676..795137b3 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -1455,12 +1455,15 @@ static void webHandleGuiConfig() httpMessage += getOption(-1, F("None")); #if defined(ARDUINO_ARCH_ESP32) char buffer[10]; - uint8_t pins[] = {0, 5, 12, 13, 15, 16, 17, 18, 19, 21, 22, 23, 26, 27, 32}; - for(uint8_t i = 0; i < sizeof(pins); i++) { - // if(!gpioIsSystemPin(pins[i])) { - snprintf_P(buffer, sizeof(buffer), PSTR("GPIO %d"), pins[i]); - httpMessage += getOption(pins[i], buffer); - // } + // uint8_t pins[] = {0, 5, 12, 13, 15, 16, 17, 18, 19, 21, 22, 23, 26, 27, 32}; + // for(uint8_t i = 0; i < sizeof(pins); i++) { + for(uint8_t gpio = 0; gpio < NUM_DIGITAL_PINS; gpio++) { + if(!gpioIsSystemPin(gpio)) { + snprintf_P(buffer, sizeof(buffer), PSTR("GPIO %d"), gpio); + httpMessage += getOption(gpio, buffer); + } else { + LOG_WARNING(TAG_HTTP, F("pin %d"), gpio); + } } #else httpMessage += getOption(5, F("D1 - GPIO 5")); @@ -2471,13 +2474,11 @@ static inline void webStartConfigPortal() dnsServer.start(DNS_PORT, "*", apIP); #endif // HASP_USE_CAPTIVE_PORTAL -#if HASP_USE_WIFI > 0 - // reply to all requests with same HTML - // webServer.onNotFound([]() { webHandleWifiConfig(); }); -#endif - + webServer.on(F("/vars.css"), httpHandleFileUri); webServer.on(F("/style.css"), httpHandleFileUri); webServer.on(F("/script.js"), httpHandleFileUri); + // reply to all requests with same HTML + webServer.onNotFound(webHandleWifiConfig); LOG_TRACE(TAG_HTTP, F("Wifi access point")); }