How can i modify the landing page of WifiManager library?

rizkiaswangga
Posts: 1
Joined: Thu Sep 21, 2023 4:34 pm

How can i modify the landing page of WifiManager library?

Postby rizkiaswangga » Thu Sep 21, 2023 4:40 pm

Hello everyone...i'm new to this forum


i have a Lolin V3 ESP8266 board, and 've installed the wifimanager library previously by tpazu.

whenever i make the ESP8266 as an AP, it redirects to its default configuration landing page, what i want is the page to be say a custom Hello World as the landing page.

i have read from other forums suggest that the library should be modified. Is it true? which file of the wifimanager library should be modified?

Any assistance are highly respected :)

hobby_guy
Posts: 20
Joined: Sat Jan 29, 2022 3:29 pm

Re: How can i modify the landing page of WifiManager library?

Postby hobby_guy » Thu Oct 12, 2023 9:23 am

Hi!

You don't have to modify the library to get this working. The following works for me: You can declare a callback function for the web server, which is called when the portal is started. In this method, you can add (or change!) routes on the web server inside the WiFiManager library. If you change the base route (just "/") then you can deliver whatever HTML (even a file, if you use the SPIFFS or similar file system library) as a custom default landing page.

There is a quirk I've noticed on this, though. If you do "replace" the base route of the WiFiManager, then (for some reason) the corresponding handle method is repeatedly being invoked -- this can be seen if you Serial.println something. Not sure if this is a problem though.

Code: Select all

WiFiManager wifiManager;

void bindServerCallback(){
  wifiManager.server->on("/", handleSetupRoute);  // overwrite/replace existing/default route
  wifiManager.server->on("/test", handleTestRoute);  // add new route
}

void setup() {
  wifiManager.setWebServerCallback(bindServerCallback);
}

void handleSetupRoute(){
  String data = "<html><body><h1>Hello World!</h1></body></html>";
  wifiManager.server->send(200, "text/html", data);
}

void handleTestRoute(){
  String data = "<html><body><h1>Something else</h1></body></html>";
  wifiManager.server->send(200, "text/html", data);
}

Who is online

Users browsing this forum: No registered users and 27 guests