Skip to content

Commit

Permalink
Handle root within webconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
steadramon committed Apr 15, 2023
1 parent 84b7c5a commit 83a2f0a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ESPGeiger/src/ConfigManager/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,42 @@ void ConfigManager::startWebPortal()
double ratio = atof(ratioChar);
gcounter.set_ratio(ratio);

WiFiManager::setCustomMenuHTML("<form action='/status' method='get'><button>Status</button></form><br/>\n");
WiFiManager::setCustomMenuHTML("<form action='/status' method='get'><button>Status</button></form><br/>");
const char * menu[] = {"custom", "wifi","param","info","update"};
ConfigManager::setMenu(menu,sizeof(menu));
WiFiManager::setWebServerCallback(std::bind(&ConfigManager::bindServerCallback, this));
WiFiManager::setSaveParamsCallback(std::bind(&ConfigManager::saveParams, this));
WiFiManager::startWebPortal();
}

void ConfigManager::handleRoot() {
String page = FPSTR(HTTP_HEAD_START);
page += FPSTR(HTTP_STYLE);
page += FPSTR(faviconHead);
page += FPSTR(HTTP_HEAD_END);
page.replace(FPSTR(T_v), hostName);
String str = FPSTR(HTTP_ROOT_MAIN); // @todo custom title
str.replace(FPSTR(T_t),thingName);
str.replace(FPSTR(T_v), String(hostName) + " - " + WiFi.localIP().toString()); // use ip if ap is not active for heading @todo use hostname?

page += str;
page += FPSTR(HTTP_PORTAL_OPTIONS);

page += "<form action='/status' method='get'><button>Status</button></form><br/>";
page += HTTP_PORTAL_MENU[0];
page += HTTP_PORTAL_MENU[3];
page += HTTP_PORTAL_MENU[2];
page += HTTP_PORTAL_MENU[8];
str = FPSTR(HTTP_STATUS_ON);
str.replace(FPSTR(T_i),WiFi.localIP().toString());
str.replace(FPSTR(T_v),htmlEntities(WiFiManager::getWiFiSSID()));
page += str;
page += FPSTR(HTTP_END);

ConfigManager::server->send(200, FPSTR(HTTP_HEAD_CT), page);

}

void ConfigManager::handleJSReturn()
{
String page = FPSTR(picographJS);
Expand Down Expand Up @@ -410,6 +438,7 @@ const char* ConfigManager::getParamValueFromID(const char* str)

void ConfigManager::bindServerCallback()
{
ConfigManager::server.get()->on(ROOT_URL, HTTP_GET, std::bind(&ConfigManager::handleRoot, this));
ConfigManager::server.get()->on(STATUS_URL, HTTP_GET, std::bind(&ConfigManager::handleStatusPage, this));
ConfigManager::server.get()->on(JSON_URL, HTTP_GET, std::bind(&ConfigManager::handleJsonReturn, this));
ConfigManager::server.get()->on(JS_URL, HTTP_GET, std::bind(&ConfigManager::handleJSReturn, this));
Expand Down
2 changes: 2 additions & 0 deletions ESPGeiger/src/ConfigManager/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ constexpr auto TEMPLATE_LEN = 256;
constexpr auto ADVANCED_LEN = 256;
constexpr auto CB_SELECTED_STR = "selected";

constexpr auto ROOT_URL = "/";
constexpr auto RESTART_URL = "/restart";
constexpr auto CONSOLE_URL = "/cs";
constexpr auto STATUS_URL = "/status";
Expand Down Expand Up @@ -103,6 +104,7 @@ class ConfigManager : public WiFiManager
}
private:
ConfigManager();
void handleRoot();
void handleJSReturn();
void handleJsonReturn();
void handleStatusPage();
Expand Down

0 comments on commit 83a2f0a

Please sign in to comment.