-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Comments
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: |
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. |
How did it differ? |
I am using this web server library: This is my setup:
On the AsyncWebServer I redirected all 404s to the defined IP address. |
Yes, that one works well, but the in-built variant / dnsserver doesn’t so it’s still an issue. |
[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. |
Still does not work! |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
@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? |
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! |
@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. |
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. |
Oh, fer pete's sake... |
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. |
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.
Well, it does work but it is poorly named since it is not a Captive Portal that is being implemented.
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_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. |
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" |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
Maybe this comment would help to others. By adding a handler for the error case on server was solved:
|
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);
}
The text was updated successfully, but these errors were encountered: