gpt4 book ai didi

arduino - ESP8266 带弹出窗口的强制门户

转载 作者:行者123 更新时间:2023-12-05 07:40:18 25 4
gpt4 key购买 nike

有没有人成功地让强制门户在 Arduino 或 ESP8266 上的特定登录页面上弹出重定向内容?我已经在阳光下尝试了一切,虽然我的 android 会提示未连接互联网和其他事情,但它实际上从未请求/建议打开浏览器,就像我在一些带有登录页面的开放式 wifi 热点上看到的那样.我正在尝试实现实际上是一个非互联网连接设备,用户可以在远程位置登录以显示他们已经到达,有点像地理缓存但使用 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

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

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

关于arduino - ESP8266 带弹出窗口的强制门户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46289283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com