ESP32 Access Point monitoring and redirecting HTML requests

I set up an ESP32 as access point (without an internet connection, because I didn't succeed in that yet. Now I want to make sure that when a connected device tries to enter a webpage (any webpage, not just the ESP32's root URL) the ESP32 detects it and prints something in the serial monitor.

When I succeed in this I'd like to redirect any request to a custom webpage (I'm thinking about running this on the ESP32, but I might run it on another machine because of the limited processing power).

I can't find how to do this anywhere, so if someone can help me I'd really appreciate it!

you are looking at a Captive portal which is a Access Point which redirects the user to a specifice webpage when connected
try a web search for ESP32 Captive Portal you will get plenty of links

1 Like

Set up a handler for not found URLs in the setup() routine

server.onNotFound(handleNotFound);

In the handleNotFound() routine do something like

    // no clue what they sent
    String message = "File Not Found\n\n";
    message += "URI: ";
    message += server.uri();
    message += "\nMethod: ";
    message += (server.method() == HTTP_GET) ? "GET" : "POST";
    message += "\nArguments: ";
    message += server.args();
    message += "\n";
  
    for (uint8_t i = 0; i < server.args(); i++) {
      message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
    }
  
    server.send(404, "text/plain", message);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.