mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-19 01:11:31 +10:00
DFTE docs, single root library.json, optional DFTE logging bridge
- Document fork/DFTE in README; WiFiManager template setup API forwards to server - Remove nested lib/WiFiManager/library.json; rely on root library.json only - Delete legacy extras/ tooling; point HTML help link at this fork - Add WiFiManagerDfteLogger and WM_DFTE_LOGGING integration in WiFiManagerServer - Pin ESP8266 Arduino core (postmortem jump fix) in platformio.ini for tests
This commit is contained in:
@@ -21,9 +21,11 @@
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
#include "WiFiManagerParameter.h"
|
||||
|
||||
// #define WM_DFTE_LOGGING // opt-in: register a DFTE log sink that forwards to DEBUG_WM (see README)
|
||||
// #define WM_MDNS // includes MDNS, also set MDNS with sethostname
|
||||
// #define WM_FIXERASECONFIG // use erase flash fix
|
||||
// #define WM_ERASE_NVS // esp32 erase(true) will erase NVS
|
||||
@@ -126,7 +128,7 @@
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
#include <TemplateEngine.h>
|
||||
|
||||
// Include utility functions
|
||||
#include "WiFiManagerUtils.h"
|
||||
@@ -196,10 +198,12 @@ const char WM_VERSION_STR[] PROGMEM = "v2.0.18";
|
||||
// Forward declarations
|
||||
class WiFiManagerServer;
|
||||
class WiFiManagerHandlers;
|
||||
class WiFiManagerDfteLogger;
|
||||
|
||||
class WiFiManager
|
||||
{
|
||||
public:
|
||||
|
||||
// Forward declare nested class - defined later after WM_WebServer is available
|
||||
class WiFiManagerRequestArgs;
|
||||
|
||||
@@ -432,6 +436,13 @@ class WiFiManager
|
||||
// set the webapp title, default WiFiManager
|
||||
void setTitle(String title);
|
||||
|
||||
// DFTE (portal HTML): register extra placeholders or override defaults (%STYLES%, %PAGE_TITLE%, …).
|
||||
// Call before startConfigPortal / startWebPortal to have it applied when the server starts; if the
|
||||
// portal is already running, the shared registry is rebuilt immediately.
|
||||
void registerTemplateSetupCallback(std::function<void(PlaceholderRegistry&)> cb);
|
||||
// Rebuild the server’s shared PlaceholderRegistry (defaults + registerTemplateSetupCallback, or customizer if passed).
|
||||
void rebuildPlaceholderRegistry(std::function<void(PlaceholderRegistry&)> customizer = nullptr);
|
||||
|
||||
// add params to its own menu page and remove from wifi, NOT TO BE COMBINED WITH setMenu!
|
||||
void setParamsPage(bool enable);
|
||||
|
||||
@@ -565,6 +576,7 @@ class WiFiManager
|
||||
protected:
|
||||
// vars
|
||||
std::unique_ptr<WiFiManagerServer> _serverManager;
|
||||
std::function<void(PlaceholderRegistry&)> _templateSetupCallback;
|
||||
|
||||
// ip configs @todo struct ?
|
||||
IPAddress _ap_static_ip;
|
||||
@@ -827,6 +839,7 @@ protected:
|
||||
#endif
|
||||
|
||||
protected:
|
||||
friend class WiFiManagerDfteLogger; // WM_DFTE_LOGGING: bridge calls protected DEBUG_WM
|
||||
|
||||
//helpers (rendering methods moved to WiFiManagerHandlers)
|
||||
boolean isIp(String str);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* WiFiManagerDfteLogger.h
|
||||
*
|
||||
* Optional bridge from DFTE's logging hooks to WiFiManager::DEBUG_WM.
|
||||
* Enabled only when the sketch / library build defines WM_DFTE_LOGGING.
|
||||
*/
|
||||
|
||||
#ifndef WiFiManagerDfteLogger_h
|
||||
#define WiFiManagerDfteLogger_h
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
|
||||
#include <DeviceFrameworkTemplateEngineDebug.h>
|
||||
#include "WiFiManager.h"
|
||||
|
||||
/**
|
||||
* Forwards DeviceFrameworkTemplateEngineLogger calls to WiFiManager's
|
||||
* existing DEBUG_WM pipeline (respects _debug, _debugLevel, _debugPrefix, _debugPort).
|
||||
*/
|
||||
class WiFiManagerDfteLogger : public DeviceFrameworkTemplateEngineLogger {
|
||||
public:
|
||||
explicit WiFiManagerDfteLogger(WiFiManager* wm) : _wm(wm) {}
|
||||
|
||||
void error(const String& msg) override {
|
||||
logLine(WM_DEBUG_ERROR, msg);
|
||||
}
|
||||
void warn(const String& msg) override {
|
||||
logLine(WM_DEBUG_NOTIFY, msg);
|
||||
}
|
||||
void info(const String& msg) override {
|
||||
logLine(WM_DEBUG_VERBOSE, msg);
|
||||
}
|
||||
void debug(const String& msg) override {
|
||||
logLine(WM_DEBUG_DEV, msg);
|
||||
}
|
||||
|
||||
private:
|
||||
WiFiManager* _wm;
|
||||
|
||||
void logLine(wm_debuglevel_t level, const String& msg) {
|
||||
if (!_wm) {
|
||||
return;
|
||||
}
|
||||
String line;
|
||||
line.reserve(static_cast<unsigned>(msg.length()) + 12u);
|
||||
line += F("[DFTE] ");
|
||||
line += msg;
|
||||
_wm->DEBUG_WM(level, line);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ESP8266 || ESP32
|
||||
|
||||
#endif // WiFiManagerDfteLogger_h
|
||||
@@ -32,6 +32,10 @@ class WiFiManager;
|
||||
// Forward declaration - full definition needed in .cpp file
|
||||
class WiFiManagerHandlers;
|
||||
|
||||
#ifdef WM_DFTE_LOGGING
|
||||
class WiFiManagerDfteLogger;
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// HTTP ROUTES
|
||||
|
||||
@@ -57,6 +61,7 @@ class WiFiManagerServer {
|
||||
static WiFiManagerServer* instance();
|
||||
|
||||
WiFiManagerServer(WiFiManager* wm);
|
||||
~WiFiManagerServer();
|
||||
|
||||
// Template engine setup and access
|
||||
void setupTemplateEngine();
|
||||
@@ -115,6 +120,12 @@ class WiFiManagerServer {
|
||||
// Shared DFTE placeholder registry
|
||||
std::unique_ptr<PlaceholderRegistry> _tplRegistry;
|
||||
std::function<void(PlaceholderRegistry&)> _tplSetupCallback;
|
||||
|
||||
#ifdef WM_DFTE_LOGGING
|
||||
// DFTE -> DEBUG_WM bridge (only installed when WM_DFTE_LOGGING and no other logger registered)
|
||||
std::unique_ptr<WiFiManagerDfteLogger> _dfteLogger;
|
||||
bool _wmOwnsDfteLogSink = false;
|
||||
#endif
|
||||
|
||||
// Singleton instance
|
||||
static WiFiManagerServer* s_instance;
|
||||
|
||||
@@ -58,7 +58,7 @@ const char HTML_HELP[] PROGMEM =
|
||||
"<tr><td>/erase</td>"
|
||||
"<td>Erase WiFi configuration and reboot device. Device will not reconnect to a network until new WiFi configuration data is entered.</td></tr>"
|
||||
"</table>"
|
||||
"<p/>Github <a href='https://github.com/tzapu/WiFiManager'>https://github.com/tzapu/WiFiManager</a>.";
|
||||
"<p/>Fork <a href='https://github.com/alexhopeoconnor/WiFiManager'>https://github.com/alexhopeoconnor/WiFiManager</a>.";
|
||||
#else
|
||||
const char HTML_HELP[] PROGMEM = "";
|
||||
#endif
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
{
|
||||
"name": "WiFiManager",
|
||||
"version": "2.0.18",
|
||||
"keywords": [
|
||||
"wifi",
|
||||
"wi-fi",
|
||||
"esp",
|
||||
"esp8266",
|
||||
"esp32",
|
||||
"espressif8266",
|
||||
"espressif32",
|
||||
"nodemcu",
|
||||
"wemos",
|
||||
"arduino"
|
||||
],
|
||||
"description": "WiFi Configuration manager with web configuration portal for ESP boards",
|
||||
"authors": [
|
||||
{
|
||||
"name": "tzapu",
|
||||
"url": "https://github.com/tzapu"
|
||||
},
|
||||
{
|
||||
"name": "tablatronix",
|
||||
"url": "https://github.com/tablatronix",
|
||||
"maintainer": true
|
||||
},
|
||||
{
|
||||
"name": "Alex Hope-O'Connor",
|
||||
"url": "https://github.com/alexhopeoconnor"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alexhopeoconnor/WiFiManager.git"
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": [
|
||||
"espressif8266",
|
||||
"espressif32"
|
||||
],
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "ESP32Async/ESPAsyncWebServer",
|
||||
"version": "3.9.1"
|
||||
},
|
||||
"https://github.com/alexhopeoconnor/DFTE.git"
|
||||
],
|
||||
"export": {
|
||||
"include": "include"
|
||||
}
|
||||
}
|
||||
@@ -499,6 +499,7 @@ void WiFiManager::setupConfigPortal() {
|
||||
// Lazy initialization: only create server manager when config portal is actually needed
|
||||
if (!_serverManager) {
|
||||
_serverManager = std::make_unique<WiFiManagerServer>(this);
|
||||
_serverManager->registerTemplateSetupCallback(_templateSetupCallback);
|
||||
}
|
||||
_serverManager->createServer(_httpPort);
|
||||
_serverManager->registerRoutes();
|
||||
@@ -1969,6 +1970,20 @@ void WiFiManager::setTitle(String title){
|
||||
_title = title;
|
||||
}
|
||||
|
||||
void WiFiManager::registerTemplateSetupCallback(std::function<void(PlaceholderRegistry&)> cb) {
|
||||
_templateSetupCallback = std::move(cb);
|
||||
if (_serverManager) {
|
||||
_serverManager->registerTemplateSetupCallback(_templateSetupCallback);
|
||||
_serverManager->rebuildPlaceholderRegistry();
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiManager::rebuildPlaceholderRegistry(std::function<void(PlaceholderRegistry&)> customizer) {
|
||||
if (_serverManager) {
|
||||
_serverManager->rebuildPlaceholderRegistry(std::move(customizer));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set params as separate page not in wifi
|
||||
* NOT COMPATIBLE WITH setMenu!
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "WiFiManagerServer.h"
|
||||
#include "WiFiManager.h"
|
||||
#include "WiFiManagerHandlers.h" // Full definition needed for unique_ptr
|
||||
#ifdef WM_DFTE_LOGGING
|
||||
#include "WiFiManagerDfteLogger.h"
|
||||
#include <DeviceFrameworkTemplateEngineDebug.h>
|
||||
#endif
|
||||
#include "templates/CSS.h"
|
||||
#include "templates/JS.h"
|
||||
#include "templates/Root.h"
|
||||
@@ -28,6 +32,8 @@ WiFiManagerServer::WiFiManagerServer(WiFiManager* wm)
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
WiFiManagerServer::~WiFiManagerServer() = default;
|
||||
|
||||
// Static getters for RAM placeholders (registry requires zero-arg functions) using singleton
|
||||
const char* WiFiManagerServer::tplGetPageTitle() {
|
||||
auto srv = WiFiManagerServer::instance();
|
||||
@@ -128,6 +134,17 @@ void WiFiManagerServer::setupTemplateEngine() {
|
||||
|
||||
// Allow consumers to customize placeholders
|
||||
applyTemplateSetupCallback(*_tplRegistry);
|
||||
|
||||
#ifdef WM_DFTE_LOGGING
|
||||
// Install DFTE log sink only if nothing else registered yet (e.g. DeviceFramework's bridge).
|
||||
if (!deviceFrameworkTemplateEngineIsLoggingEnabled()) {
|
||||
if (!_dfteLogger) {
|
||||
_dfteLogger = std::make_unique<WiFiManagerDfteLogger>(_wm);
|
||||
}
|
||||
deviceFrameworkTemplateEngineEnableLogging(_dfteLogger.get());
|
||||
_wmOwnsDfteLogSink = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void WiFiManagerServer::createServer(uint16_t port) {
|
||||
@@ -274,6 +291,16 @@ void WiFiManagerServer::processDNS() {
|
||||
}
|
||||
|
||||
void WiFiManagerServer::shutdownServer() {
|
||||
#ifdef WM_DFTE_LOGGING
|
||||
if (_wmOwnsDfteLogSink) {
|
||||
if (deviceFrameworkTemplateEngineGetLogger() == _dfteLogger.get()) {
|
||||
deviceFrameworkTemplateEngineDisableLogging();
|
||||
}
|
||||
_dfteLogger.reset();
|
||||
_wmOwnsDfteLogSink = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// AsyncWebServer doesn't have stop(), just reset the unique_ptr to free resources
|
||||
if (server) {
|
||||
server.reset();
|
||||
|
||||
Reference in New Issue
Block a user