手机 phone 的浏览器在连接移动网络时无法加载 ESP8266 托管的网站
Mobile phone's browser cannot load website hosted by ESP8266 when mobile network is connected
我正在使用 ESP8266 web server。我正在创建一个 Wifi AP,我使用网络服务器来托管我想从我的手机 phone 的浏览器访问的网站:
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
,一切正常。在我的 phone 中,我也可以连接到 WiFi AP,但是如果我连接到移动网络,浏览器不会加载网站,它显示 "web page not found"。如果关闭它,网站加载正常。
我需要能够加载由我的 ESP8266 网络服务器托管的网站,而无需关闭我的移动数据。知道为什么会这样吗?我该如何避免这个问题?
您的 ESP 创建了自己的小型 LAN,当您成为该 LAN 的一部分时就可以访问它。但是当你连接到移动网络时,你就是全球互联网的一部分,它对你的 ESP 的局域网一无所知。
所以,你需要以某种方式连接它们。
例如 - 您有家庭互联网提供商,假设您有无线路由器 D-Link。这意味着您可以通过 D-Link 动态 DNS 服务使您的家庭局域网对互联网可见。因此,您可以 运行 您的 ESP 作为家庭 LAN 的客户端(而不是作为 AP),并且您可以将 ESP 的本地 IP 映射到某个全球可用的地址。
是的,您将失去很好的域 'my_wifi_config.com',但您将能够访问 ESP 的功能,无论它是什么(带有温度计值的网页或开灯按钮)。
我正在使用 ESP8266 web server。我正在创建一个 Wifi AP,我使用网络服务器来托管我想从我的手机 phone 的浏览器访问的网站:
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
,一切正常。在我的 phone 中,我也可以连接到 WiFi AP,但是如果我连接到移动网络,浏览器不会加载网站,它显示 "web page not found"。如果关闭它,网站加载正常。
我需要能够加载由我的 ESP8266 网络服务器托管的网站,而无需关闭我的移动数据。知道为什么会这样吗?我该如何避免这个问题?
您的 ESP 创建了自己的小型 LAN,当您成为该 LAN 的一部分时就可以访问它。但是当你连接到移动网络时,你就是全球互联网的一部分,它对你的 ESP 的局域网一无所知。
所以,你需要以某种方式连接它们。
例如 - 您有家庭互联网提供商,假设您有无线路由器 D-Link。这意味着您可以通过 D-Link 动态 DNS 服务使您的家庭局域网对互联网可见。因此,您可以 运行 您的 ESP 作为家庭 LAN 的客户端(而不是作为 AP),并且您可以将 ESP 的本地 IP 映射到某个全球可用的地址。
是的,您将失去很好的域 'my_wifi_config.com',但您将能够访问 ESP 的功能,无论它是什么(带有温度计值的网页或开灯按钮)。