在ESP8266代码中有任何方法可以向路由器请求特定的IP吗?我的意思是,在下面的例子(我从网络复制)中,它得到了"192.168.1.3“。部分"3“是自动分配,并可能改变下一次。我希望这个号码是一个特定的数字。我知道我可以修改路由器设置来添加静态IP,但至少对我的路由器来说,添加静态IP是缓慢和不方便的。我可以交换ESP8266板并运行相同的代码。路由器是我的,并且只被我使用,所以如果我需要改变路由器的一些设置来批准来自客户端的这种请求,我可以这样做。
如果没有这样的特性,我是否可以通过特定的名称来发现ESP8266 (同样,在路由器设置中没有创建翻译条目,而是在ESP代码中)?例如,如果ESP8266运行的是web服务器,我是否可以通过类似于"http://myserver1“而不是"http://192.168.1.3"?”的方式访问web服务器?
#include <ESP8266WiFi.h> // Include the Wi-Fi library
const char* ssid = "SSID"; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "PASSWORD"; // The password of the Wi-Fi network
void setup() {
Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
}发布于 2021-09-12 08:56:28
几乎所有的路由器都有DHCP Server。您可以做的是为您的DHCP Reservation的MAC地址创建一个ESP8266。
对于域名,您可以做的是在您的本地PC机箱主机条目。就像这样,
192.168.1.3 myserver1更新
我已经找到了这教程,它可以回答静态IP配置。
域名的解析是由DNS Server.完成的,因为您没有公共IP或实际域,您的IP不会被任何DNS Servers解析。因此,您可以做的是在您的路由器中设置一个DHCP主机条目(在上面的教程中也会创建这个主机条目),或者在您的本地PC中创建一个主机条目。
注意:我目前没有NodeMCU模块。否则我可以自己试一试。
https://stackoverflow.com/questions/69149363
复制相似问题