【发布时间】:2018-04-24 18:11:20
【问题描述】:
我正在使用ESP8266 web server。我正在创建一个 Wifi AP,并使用一个网络服务器来托管一个我想从我的手机浏览器访问的网站:
void wifi::access_point::begin() {
WiFi.mode(WIFI_AP_STA);
WiFi.softAPConfig(ap_ip, ap_gateway, ap_subnet);
WiFi.softAP(ap_ssid, ap_password);
server.on ( "/", [this]() {
handle_root();
});
server.on( "/submit", [this]() {
handle_submit();
});
server.begin();
dns_server.start(dns_port, "my_wifi_config.com", ap_ip);
}
void wifi::access_point::handle_root() {
char html[1000];
snprintf (html, 1000,
"<html>\
<head>\
<title>Wifi Configuration</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; font-size: 1.5em; Color: #000000; }\
h1 { Color: #AA0000; }\
</style>\
</head>\
<body>\
<center>\
<h1>Wifi Configuration</h1>\
<form action='/submit' method='POST'>\
<p> Wifi SSID: </p>\
<input type='text' name='ssid'>\
<p> Wifi password: <\p>\
<input type='text' name='password'>\
<br>\
<input type='submit' name='Submit'>\
</form>\
</center>\
</body>\
</html>"
);
server.send(200, "text/html", html);
}
我可以从我的桌面连接到 AP 并访问ap_ip,一切正常。在我的手机中,我也可以连接到 WiFi AP,但如果我连接到移动网络,浏览器不会加载网站,它会显示“找不到网页”。如果将其关闭,则网站加载正常。
我需要能够加载由我的 ESP8266 网络服务器托管的网站,而无需关闭我的移动数据。知道为什么会发生这种情况,我该如何避免这个问题?
【问题讨论】:
-
由于您的 ESP 创建了本地网络,因此无法从外部访问。您需要在手机上打开 wifi,并将其设为优先网络 - 我很长时间没有看到这个了,但我曾经有手机可以选择哪个是优先网络。也许这就是你手机的问题?
-
就没有别的办法了吗?我的意思是,即使我尝试访问本地 ip 192.168.1.123 它也会尝试使用移动网络...
标签: arduino esp8266 arduino-esp8266