s00500 / ESPUI

A simple web user interface library for ESP32 and ESP8266

Home Page:https://valencia.lbsfilm.at/midterm-presentation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fixed a bug with iOS Captive Portal Not Loading

blackpressinc opened this issue · comments

Sorry, I'm very new to github and I don't know how to do pull/push(?) requests. I was working on a project where I needed a captive portal to pop up in android and ios. By default the ESPUI does not pop up in iOS (Tested on my iphone 14). I fixed this by changing lines 1493 in ESPUI.ccp. iOS expects some content or else it wont follow the captive portal request. I just added a simple script to pop up a link followed by a redirect to the default ESPUI

server->onNotFound([this](AsyncWebServerRequest* request) {
    if (captivePortal)
    {
		AsyncResponseStream *response = request->beginResponseStream("text/html");
		response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
		response->printf("<p>If site does not re-direct click here <a href='http://%s'>this link</a></p>", WiFi.softAPIP().toString().c_str());
		response->print("</body></html>");
		response->print("<head>");
		response->printf("<meta http-equiv=\"Refresh\" content=\"0; URL='http://%s'\" />", WiFi.softAPIP().toString().c_str());
		response->print("</head>");
		request->send(response);
		request->redirect("/");
    }
    else
    {
        request->send(404);
    }
});

Hey, that is a cool input. Please make a fork of the project, then make the change on your fork and finally open a Pull Request on github.

Hello,
this is defenatelly a good bug fix which solved the problem for iOS and macOS for me too.
On Windows 10/11 it is still not showing the correct page, but this seems to be related to the Windows OS...

Thanks in advance for adding this to the general function. =)

Hi AWSW-de, I have a similar challenge in Mac that captive portal not loading. could u please help me with that

Hi AWSW-de, I have a similar challenge in Mac that captive portal not loading. could u please help me with that

Hi,
I just changed the lines 1493 in ESPUI.ccp like named in the 1st post from blackpressinc.

In my “void OfflinePotalSetup()“ in here https://github.com/AWSW-de/WordClock-16x16-LED-matrix-2023/blob/main/Code/Code.ino#L4298 You will find a working captive portal function.

@blackpressinc: If you like I can try to create the pull request for the change if you don’t find the time.

Hope to help.

Kind regards
AWSW

how we can implement this in our mac through MDM?

how we can implement this in our mac through MDM?

Such captive portal actions are part of every modern operating system/browser.

They just try a bunch of known pages / URLs to see if this is a captive portal WiFi. The challenge seems to be that there is no full list of different URLs to react on - or let’s say I could not find one even with a long period of searching…

How it works (with this patch) with ESPUI is shown here: https://youtu.be/-pJWRE3K3IY?si=d-3nyKEezCBAAnmj&t=115

Not sure how you are making your changes. ESPUI.cpp is only 1452 lines long.

I would propose this as an alternative coding that uses less ram at runtime.

        AsyncResponseStream *response = request->beginResponseStream("text/html");
        String responseText;
        responseText.reserve(1024);
        responseText += F("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
        responseText += ("<p>If site does not re-direct click here <a href='http://" +  WiFi.softAPIP().toString() + "'>this link</a></p>");
        responseText += ("</body></html><head><meta http-equiv=\"Refresh\" content=\"0; URL='http://" +  WiFi.softAPIP().toString() + "'\" /></head>");
        response->write(responseText.c_str(), responseText.length());
        request->send(response);
        request->redirect("/");