Skip to content

No CaptivePortal page comes up on ESP32 Dev. board #3740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
williamesp2015 opened this issue Feb 13, 2020 · 20 comments · Fixed by #4080
Closed

No CaptivePortal page comes up on ESP32 Dev. board #3740

williamesp2015 opened this issue Feb 13, 2020 · 20 comments · Fixed by #4080

Comments

@williamesp2015
Copy link

Board: ESP32 Dev Module
Core Installation version: Latest
IDE name: Platform.io Arduino
Flash Frequency: 40Mhz?
Computer OS: Windows 10? And iPhone
I searched to find the resone for failing captive Portal to popup on the Chrome/Internet Explorer /iphone/Adnroid Tablet but I couldn't solve. The code is:
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
ESP8266WebServer server(80);
#else
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <DNSServer.h>
WebServer server(80);
DNSServer dnsServer;
#endif
const byte DNS_PORT = 53;
IPAddress apIP(8, 8, 4, 4);
//IPAddress apIP(192, 168, 4, 4);

String responseHTML = ""
"<title>CaptivePortal</title>"
"

Hello World!

This is a captive portal example. All requests will "
"be redirected here.

";
void handleRoot() {
// digitalWrite(led, 1);
#ifdef ESP8266
server.send(200, "text/plain", "hello from esp8266!");
#else
server.send(200, "text/plain", "hello from esp32!");
#endif
// digitalWrite(led, 0);
}
void handleNotFound(){
// digitalWrite(led, 1);
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);
// digitalWrite(led, 0);
}
void setup() {
Serial.begin(115200);
delay(2000);
WiFi.disconnect(); //added to start with the wifi off, avoid crashing
delay(500);
WiFi.mode(WIFI_OFF); //added to start with the wifi off, avoid crashing
WiFi.mode(WIFI_AP);
delay(100);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("CaptivePortal");
delay(2000); // VERY IMPORTANT
#ifdef ESP8266
if (MDNS.begin("esp8266")) {
#else
if (MDNS.begin("esp32")) {
#endif
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", {
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
delay(1);
}

@mntolia
Copy link

mntolia commented Feb 18, 2020

There are 3 ways captive portal detectors will get triggered. The easiest is an HTTP redirect for all requests and a DNS server redirection. I have generally found that using both the implementations triggers the captive portal detector in all devices.

Make the server.onNotFound() redirect to the captive portal.

Make sure the DNS resolver resolves to the said IP. BTW 8.8.4.4 is the IP address for google DNS.

Check this example for DNS redirection:
https://github.com/espressif/arduino-esp32/blob/master/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino

@G6EJD
Copy link

G6EJD commented Apr 10, 2020

The example you listed @mntolia does not work, there is an issue in the Dnsserver library

@mntolia
Copy link

mntolia commented Apr 11, 2020

The example you listed @mntolia does not work, there is an issue in the Dnsserver library

I am currently using it in a project. It works fine for me. I didn't implement that example exactly though.

@G6EJD
Copy link

G6EJD commented Apr 11, 2020

How did it differ?

@mntolia
Copy link

mntolia commented Apr 11, 2020

I am using this web server library:
https://github.com/me-no-dev/ESPAsyncWebServer

This is my setup:

    dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
    dnsServer.start(53, "*", apIP);

On the AsyncWebServer I redirected all 404s to the defined IP address.
The captive portals pop up on every device I tried(MacOS, iPad, Android, Windows)

@G6EJD
Copy link

G6EJD commented Apr 11, 2020

Yes, that one works well, but the in-built variant / dnsserver doesn’t so it’s still an issue.

@stale
Copy link

stale bot commented Jun 10, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Jun 10, 2020
@G6EJD
Copy link

G6EJD commented Jun 10, 2020

Still does not work!

@stale
Copy link

stale bot commented Jun 10, 2020

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the Status: Stale Issue is stale stage (outdated/stuck) label Jun 10, 2020
@lbernstone
Copy link
Contributor

@G6EJD You hijacked an issue and never posted your problem code. CaptivePortal works for thousands of users, so your issue is likely specific to your environment. Why don't you provide some information about it?

@G6EJD
Copy link

G6EJD commented Jun 10, 2020

I used the example captive portal and it doesn’t not work, it did do. There is no hijacking. Why provide code or open my own issue and double up the effort when it’s exactly the same as the example, there are no error messages, it simply does not work!

What more do you want me to say? Have you tried the example, if so perhaps let me know the environment, I’m using the latest ESP32 extension and Arduino IDE.

If it now works then the issue can be closed!

@atanisoft
Copy link
Collaborator

@G6EJD what exact behavior are you trying to reproduce? If you are expecting the example to force a notification on mobile devices when they connect then you are 100% correct it will not work with the example, but that is not the point of the example either. To make a notification popup on mobile devices (even Windows) you must respond to very specific URLs with an HTTP 302 to force them to your page.

@atanisoft
Copy link
Collaborator

I also don't see any such example combining WebServer.h and DNSServer.h so there is no example sketch that provides the Captive Portal for mobile use currently. Feel free to submit a PR that implements what you feel will make this work though.

@lbernstone
Copy link
Contributor

Oh, fer pete's sake...
The SSID in SoftAP can't have a space in it.
WiFi.softAP("esp32");

@G6EJD
Copy link

G6EJD commented Jun 10, 2020

No mobile devices used when I used it, noting it’s a limitation. What’s the point of a captive portal example if it does not work? As it happens I used another method that does work, I find there’s a lot of hostility in both responses for what was a genuine reporting of an issue, if it does not work just say so and we can all move on.

@atanisoft
Copy link
Collaborator

What’s the point of a captive portal example if it does not work?

I agree that it doesn't work as a traditional Captive Portal like you would see at a coffee shop or business. It is more of a catch-all DNS responder which is only half of a Captive Portal.

if it does not work just say so and we can all move on.

Well, it does work but it is poorly named since it is not a Captive Portal that is being implemented.

I find there’s a lot of hostility in both responses for what was a genuine reporting of an issue

One downside of the internet, it is challenging to convey intent in statements. My comment was not intended as hostility, just that there is no example today that combines the two libraries as the original reporter has posted (though, wish it was formatted as code since it would be a lot easier to follow). The code as written will never work as it doesn't service the DNS server in loop as shown here, without that call to process the next request it won't ever respond to the DNS requests that may be sent from the clients.

@stale
Copy link

stale bot commented Aug 9, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 9, 2020
@gluehbirnenkopf
Copy link

gluehbirnenkopf commented Aug 23, 2020

I agree that this is not a captive portal example and as the other issue comments say this is:

A) poorly named - would suggest something like "DNSResponseSender"
B) if the name stays the functionality should work

@stale
Copy link

stale bot commented Aug 23, 2020

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the Status: Stale Issue is stale stage (outdated/stuck) label Aug 23, 2020
@mariano22
Copy link

Maybe this comment would help to others.
I tried the code firstly posted and it worked on PC but no completly good in Android (version 10 kernal 4.4.205-perf+). It doesn't trigger the "Touch it to log in the network" message.

By adding a handler for the error case on server was solved:

server.onNotFound(handleRoot);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants