From e6d21b84364524f474f05b1fddf97541bd174e7a Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 24 Feb 2022 12:15:11 -0600 Subject: [PATCH] use macro for webserver routes fstring helper --- WiFiManager.cpp | 33 ++++++++++++++++----------------- WiFiManager.h | 2 ++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index bc68815..652723f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -587,28 +587,27 @@ void WiFiManager::setupHTTPServer(){ } server.reset(new WM_WebServer(_httpPort)); + - #define G(string_literal) (String(FPSTR(string_literal)).c_str()) - - // workaround for Uri() bug https://github.com/esp8266/Arduino/issues/7102 - /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ + + // G macro workaround for Uri() bug https://github.com/esp8266/Arduino/issues/7102 server->on(G(R_root), std::bind(&WiFiManager::handleRoot, this)); - server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); - server->on(String(FPSTR(R_wifinoscan)).c_str(), std::bind(&WiFiManager::handleWifi, this, false)); - server->on(String(FPSTR(R_wifisave)).c_str(), std::bind(&WiFiManager::handleWifiSave, this)); - server->on(String(FPSTR(R_info)).c_str(), std::bind(&WiFiManager::handleInfo, this)); - server->on(String(FPSTR(R_param)).c_str(), std::bind(&WiFiManager::handleParam, this)); - server->on(String(FPSTR(R_paramsave)).c_str(), std::bind(&WiFiManager::handleParamSave, this)); - server->on(String(FPSTR(R_restart)).c_str(), std::bind(&WiFiManager::handleReset, this)); - server->on(String(FPSTR(R_exit)).c_str(), std::bind(&WiFiManager::handleExit, this)); - server->on(String(FPSTR(R_close)).c_str(), std::bind(&WiFiManager::handleClose, this)); - server->on(String(FPSTR(R_erase)).c_str(), std::bind(&WiFiManager::handleErase, this, false)); - server->on(String(FPSTR(R_status)).c_str(), std::bind(&WiFiManager::handleWiFiStatus, this)); + server->on(G(R_wifi), std::bind(&WiFiManager::handleWifi, this, true)); + server->on(G(R_wifinoscan), std::bind(&WiFiManager::handleWifi, this, false)); + server->on(G(R_wifisave), std::bind(&WiFiManager::handleWifiSave, this)); + server->on(G(R_info), std::bind(&WiFiManager::handleInfo, this)); + server->on(G(R_param), std::bind(&WiFiManager::handleParam, this)); + server->on(G(R_paramsave), std::bind(&WiFiManager::handleParamSave, this)); + server->on(G(R_restart), std::bind(&WiFiManager::handleReset, this)); + server->on(G(R_exit), std::bind(&WiFiManager::handleExit, this)); + server->on(G(R_close), std::bind(&WiFiManager::handleClose, this)); + server->on(G(R_erase), std::bind(&WiFiManager::handleErase, this, false)); + server->on(G(R_status), std::bind(&WiFiManager::handleWiFiStatus, this)); server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); - server->on(String(FPSTR(R_update)).c_str(), std::bind(&WiFiManager::handleUpdate, this)); - server->on(String(FPSTR(R_updatedone)).c_str(), HTTP_POST, std::bind(&WiFiManager::handleUpdateDone, this), std::bind(&WiFiManager::handleUpdating, this)); + server->on(G(R_update), std::bind(&WiFiManager::handleUpdate, this)); + server->on(G(R_updatedone), HTTP_POST, std::bind(&WiFiManager::handleUpdateDone, this), std::bind(&WiFiManager::handleUpdating, this)); server->begin(); // Web server start #ifdef WM_DEBUG_LEVEL diff --git a/WiFiManager.h b/WiFiManager.h index 5c13511..641f88e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -46,6 +46,8 @@ #define WM_WEBSERVERSHIM // use webserver shim lib +#define G(string_literal) (String(FPSTR(string_literal)).c_str()) + #ifdef ESP8266 extern "C" {