Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tzapu/WiFiManager
Browse files Browse the repository at this point in the history
  • Loading branch information
tablatronix committed Sep 18, 2023
2 parents d6bf07f + eb27c52 commit 0d07e09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
24 changes: 14 additions & 10 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,16 +2386,20 @@ void WiFiManager::handleNotFound() {
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
handleRequest();
String message = FPSTR(S_notfound); // @token notfound
message += FPSTR(S_uri); // @token uri
message += server->uri();
message += FPSTR(S_method); // @token method
message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST);
message += FPSTR(S_args); // @token args
message += server->args();
message += F("\n");

for ( uint8_t i = 0; i < server->args(); i++ ) {
message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n";

bool verbose404 = false; // show info in 404 body, uri,method, args
if(verbose404){
message += FPSTR(S_uri); // @token uri
message += server->uri();
message += FPSTR(S_method); // @token method
message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST);
message += FPSTR(S_args); // @token args
message += server->args();
message += F("\n");

for ( uint8_t i = 0; i < server->args(); i++ ) {
message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n";
}
}
server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate")); // @HTTPHEAD send cache
server->sendHeader(F("Pragma"), F("no-cache"));
Expand Down
5 changes: 4 additions & 1 deletion WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,16 @@ class WiFiManager
void updateConxResult(uint8_t status);

// webserver handlers
public:
void handleNotFound();
private:
void HTTPSend(const String &content);
void handleRoot();
void handleWifi(boolean scan);
void handleWifiSave();
void handleInfo();
void handleReset();
void handleNotFound();

void handleExit();
void handleClose();
// void handleErase();
Expand Down
13 changes: 11 additions & 2 deletions examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,24 @@ void saveParamCallback(){
}

void bindServerCallback(){
wm.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason
// wm.server->on("/info",handleRoute); // you can override wm!
wm.server->on("/custom",handleRoute);

// you can override wm route endpoints, I have not found a way to remove handlers, but this would let you disable them or add auth etc.
// wm.server->on("/info",handleNotFound);
// wm.server->on("/update",handleNotFound);
wm.server->on("/erase",handleNotFound);
}

void handleRoute(){
Serial.println("[HTTP] handle route");
wm.server->send(200, "text/plain", "hello from user code");
}

void handleNotFound(){
Serial.println("[HTTP] handle route");
wm.handleNotFound();
}

void handlePreOtaUpdateCallback(){
Update.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100)));
Expand Down

0 comments on commit 0d07e09

Please sign in to comment.