我正面临着一个特殊的问题。下面的代码片段连接到新的WiFi网络。程序中没有硬编码的ssid或密码.我正在使用AsyncWifiManager和AsyncWebServer模块。当我连接到我的家庭WiFi路由器在自动连接门户中提供ssid和密码时,NodeMCU正在连接,服务器正常工作。但是每当我改变WiFi,连接到我的手机热点,那么服务器就不会运行,尽管我在串行监视器中获得本地IP地址。
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ESPAsyncWiFiManager.h>
#include <FS.h>
#include <Wire.h>
AsyncWiFiManager wifiManager(&server,&dns);
// To clean previous settings. Use one time, then comment
// wifiManager.resetSettings();
// set custom static ip for portal
IPAddress staticIP(192,168,0,20); //ESP static ip
IPAddress gateway(192,168,0,1); //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255,255,255,0); //Subnet mask
wifiManager.setSTAStaticIPConfig(staticIP, gateway, subnet);
// Open WiFi Setup portal
wifiManager.autoConnect();
Serial.println("Connecting to WiFi..");
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
WiFi.begin();
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}我正在通过Arduino IDE编程NodeMCU板。
发布于 2020-05-08 09:38:40
由于您的代码对IP/子网/网关使用fix参数,您必须相应地设置不同的热点,或者在将ESP8266服务器连接到不同的热点时可以选择以下选项:
解决方案的复杂性是由总是在同一个网络/子网和固定网关中的因素造成的,或者所有的(除了MAC地址和设备名称都是固定的)都是固定的,其余的可能是可变的。阅读有关在这里建立一个本地网络的一些基础知识
https://stackoverflow.com/questions/61665434
复制相似问题