ESP8266带有弹出窗口的强制门户

时间:2017-09-18 22:55:56

标签: arduino esp8266 android-popupwindow arduino-esp8266 captiveportal

有没有人成功获得强制网络门户,以便将重定向的内容弹出到Arduino或ESP8266上的特定目标网页? 我已经在阳光下尝试了所有东西,而我的机器人会抱怨没有连接的互联网和其他东西,它实际上从未请求/建议打开浏览器,因为我已经在一些开放的wifi热点上看到了登录页面。 我试图实现实际上是非互联网连接的设备,用户将在远程位置登录以显示他们已经到达,有点像geocache但使用wifi登录。我做了dnsServer glob(所有名称都是本地IP),我已经完成了许多网址重定向。我尝试过提供特定内容(而不是重定向),但没有弹出任何内容。

相关代码:

#include <ESPAsyncWebServer.h>
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>


IPAddress apIp ( 10, 10, 10, 10 );
AsyncWebServer asyncWebServer(80);
DNSServer dnsServer;
const char* captiveRedirect = "/index.htm";
String apSSID = "GeoCache";

dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
dnsServer.start ( DNS_PORT, "*", apIp );

DBG_OUTPUT_PORT.println("Initializing MDNS for local hostname on AP");
if (MDNS.begin(apHostname)) {
    MDNS.addService("http", "tcp", 80);
    DBG_OUTPUT_PORT.println("MDNS responder started");
    DBG_OUTPUT_PORT.print("You can now connect to http://");
    DBG_OUTPUT_PORT.print(apHostname);
    DBG_OUTPUT_PORT.println(".local");
}

//Android captive portal. Maybe not needed. Might be handled by notFound handler.
asyncWebServer.addRewrite( new AsyncWebRewrite("/generate_204", captiveRedirect));
//asyncWebServer.on ( "/generate_204", returnOK );
//Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
asyncWebServer.addRewrite( new AsyncWebRewrite("/fwlink", captiveRedirect));
//asyncWebServer.on ( "/fwlink", returnOK );
//Microsoft windows 10
//asyncWebServer.on ( "/connecttest.txt", returnOK );
asyncWebServer.addRewrite( new AsyncWebRewrite("/connecttest.txt", captiveRedirect));
// apple devices
asyncWebServer.addRewrite( new AsyncWebRewrite("/hotspot-detect.html", captiveRedirect));
//asyncWebServer.on ( "/hotspot-detect.html", returnOK );
asyncWebServer.addRewrite( new AsyncWebRewrite("/library/test/success.html", captiveRedirect));
//asyncWebServer.on ( "/library/test/success.html", returnOK );
// kindle
asyncWebServer.addRewrite( new AsyncWebRewrite("/kindle-wifi/wifistub.html", captiveRedirect));
//asyncWebServer.on ( "/kindle-wifi/wifistub.html", returnOK );

asyncWebServer.on("/delete", HTTP_DELETE, handleDelete);
// upload a file to /upload
asyncWebServer.on("/upload", HTTP_POST, returnOK, handleUpload);
// Catch-All Handlers
asyncWebServer.onFileUpload(handleUpload);
//asyncWebServer.onRequestBody(onBody);

asyncWebServer.on("/signin", HTTP_GET, addLog);

asyncWebServer.onNotFound(handleNotFound);

asyncWebServer.begin();

WiFi.mode(WIFI_AP);
WiFi.softAPConfig ( apIp, apIp, IPAddress ( 255, 255, 255, 0 ) );
WiFi.softAP(apSSID);

1 个答案:

答案 0 :(得分:0)

在loop()中,您必须包括:

dnsServer.processNextRequest();

之前

server.handleClient(); //Handling of incoming requests

然后,创建一个未找到的路由器:

server.onNotFound([]() {
    char * msg = "HELLO<br>Default landing page<br>";
    server.send(200, "text/html", msg );
  });