From e5e2c83fc3e193fd01f5a8c0ce2372d04e054786 Mon Sep 17 00:00:00 2001 From: Tolentino Cotesta Date: Thu, 24 Oct 2024 09:39:11 +0200 Subject: [PATCH] set captive --- library.properties | 2 +- src/AsyncFsWebServer.cpp | 7 +++---- src/AsyncFsWebServer.h | 28 ++++++++++++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/library.properties b/library.properties index ef13dddc..97a7ba11 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AsyncEspFsWebserver -version=1.0.7 +version=1.0.8 author=Tolentino Cotesta maintainer=Tolentino Cotesta sentence=ESPAsyncWebserver with steroids diff --git a/src/AsyncFsWebServer.cpp b/src/AsyncFsWebServer.cpp index bbca8301..2cb095ee 100644 --- a/src/AsyncFsWebServer.cpp +++ b/src/AsyncFsWebServer.cpp @@ -130,7 +130,6 @@ bool AsyncFsWebServer::startCaptivePortal(const char* ssid, const char* pass, co else m_captiveRun = WiFi.softAP(ssid); -#if ESP_FS_WS_SETUP_HTM if (!m_captiveRun) { log_error("Captive portal failed to start: WiFi.softAP failed!"); return false; @@ -151,7 +150,7 @@ bool AsyncFsWebServer::startCaptivePortal(const char* ssid, const char* pass, co m_captive = new CaptiveRequestHandler(redirectTargetURL); addHandler(m_captive).setFilter(ON_AP_FILTER); //only when requested from AP log_info("Captive portal started. Redirecting all requests to %s", redirectTargetURL); -#endif + return m_captiveRun; } @@ -584,7 +583,7 @@ void AsyncFsWebServer::update_first(AsyncWebServerRequest *request, String file } } -IPAddress AsyncFsWebServer::startWiFi(uint32_t timeout, CallbackF fn, bool skipAP ) { +IPAddress AsyncFsWebServer::startWiFi(uint32_t timeout, CallbackF fn, bool skipAP) { // Check if we need to config wifi connection IPAddress local_ip, subnet, gateway; @@ -674,7 +673,7 @@ IPAddress AsyncFsWebServer::startWiFi(uint32_t timeout, CallbackF fn, bool skipA } // No connection, start AP and then captive portal - startCaptivePortal(m_apSSID.c_str(), m_apPsk.c_str(), "/setup"); + startCaptivePortal(m_apSSID.c_str(), m_apPsk.c_str(), m_captiveUrl.c_str()); ip = m_captiveIp; } return ip; diff --git a/src/AsyncFsWebServer.h b/src/AsyncFsWebServer.h index 6128b6a9..2f3ce00b 100644 --- a/src/AsyncFsWebServer.h +++ b/src/AsyncFsWebServer.h @@ -45,7 +45,6 @@ #define ESP_FS_WS_CONFIG_FILE ESP_FS_WS_CONFIG_FOLDER "/config.json" #include "setup_htm.h" #include "SetupConfig.hpp" - #include "CaptivePortal.hpp" #endif #define ARDUINOJSON_USE_LONG_LONG 1 @@ -55,6 +54,7 @@ #else #define JSON_DOC(x) DynamicJsonDocument doc((size_t)x) #endif +#include "CaptivePortal.hpp" #define LIB_URL "https://github.com/cotestatnt/async-esp-fs-webserver/" #define MIN_F -3.4028235E+38 @@ -113,6 +113,7 @@ class AsyncFsWebServer : public AsyncWebServer char* m_pageUser = nullptr; char* m_pagePswd = nullptr; String m_host = "esphost"; + String m_captiveUrl = "/setup"; uint16_t m_port; uint32_t m_timeout = 10000; @@ -192,11 +193,18 @@ class AsyncFsWebServer : public AsyncWebServer /* Start WiFi connection, if fails to in AP mode (backward compatibility) */ - IPAddress startWiFi(uint32_t timeout, const char *apSSID, const char *apPsw, CallbackF fn=nullptr) { + inline IPAddress startWiFi(uint32_t timeout, const char *apSSID, const char *apPsw, CallbackF fn=nullptr) { setAP(apSSID, apPsw, m_captiveIp); return startWiFi(timeout, fn); } + /* + * Set captive portal endpoint + */ + inline void setCaptiveUrl(const String& url) { + m_captiveUrl = url; + } + /* * Redirect to captive portal if we got a request for another domain. */ @@ -217,7 +225,7 @@ class AsyncFsWebServer : public AsyncWebServer /* * Need to be run in loop to handle DNS requests */ - void updateDNS() { + inline void updateDNS() { m_dnsServer->processNextRequest(); } @@ -226,21 +234,21 @@ class AsyncFsWebServer : public AsyncWebServer * This it is necessary due to the different implementation of * libraries for the filesystem (LittleFS, FFat, SPIFFS etc etc) */ - void setFsInfoCallback(FsInfoCallbackF fsCallback) { + inline void setFsInfoCallback(FsInfoCallbackF fsCallback) { getFsInfo = fsCallback; } /* * Set current firmware version (shown in /setup webpage) */ - void setFirmwareVersion(char* version) { + inline void setFirmwareVersion(char* version) { strlcpy(m_version, version, sizeof(m_version)); } /* * Set hostmane */ - void setHostname(const char * host) { + inline void setHostname(const char * host) { m_host = host; } @@ -252,14 +260,14 @@ class AsyncFsWebServer : public AsyncWebServer /* * Get status of captive portal */ - bool getCaptivePortal() { + inline bool getCaptivePortal() { return m_captiveRun; } /* * Set Access Point SSID and password */ - void setAP(const char *ssid, const char *psk, IPAddress ip = IPAddress(192,168,4,1)) { + inline void setAP(const char *ssid, const char *psk, IPAddress ip = IPAddress(192,168,4,1)) { m_apSSID = ssid; m_apPsk = psk; m_captiveIp = ip; @@ -272,7 +280,7 @@ class AsyncFsWebServer : public AsyncWebServer /* * Get reference to current config.json file */ - File getConfigFile(const char* mode) { + inline File getConfigFile(const char* mode) { File file = m_filesystem->open(ESP_FS_WS_CONFIG_FILE, mode); return file; } @@ -280,7 +288,7 @@ class AsyncFsWebServer : public AsyncWebServer /* * Get complete path of config.json file */ - const char* getConfiFileName() { + inline const char* getConfiFileName() { return ESP_FS_WS_CONFIG_FILE; }