ESP8266带弹出窗口的圈养门户



是否有人成功地获得了一个圈养门户,以使重定向内容的弹出窗口弹出到Arduino或ESP8266上的特定着陆页?我已经在阳光下尝试了所有内容,尽管我的Android会抱怨非连接的互联网和其他东西,但实际上从来没有要求/建议打开浏览器,就像我在一些带有登录页面的Open Wifi热点上所做的那样。我正在尝试实现实际将是一个非Internet连接的设备,用户可以在远程位置登录以显示他们到达的地方,有点像Geocache,但使用WiFi登录。我做了DNSSERVER GLOB(所有名称)对于本地IP),我已经进行了许多URL重定向。我尝试喂食特定内容(而不是重新导向),但没有任何弹出。

相关代码:

#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);

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

dnsServer.processNextRequest();

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

然后,创建一个NotFound路由器:

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

相关内容

  • 没有找到相关文章

最新更新