Platform
- Hardware: [ESP8285 device]
- Core Version: [latest git]
- Development Env: [Arduino IDE]
- Operating System: [Windows]
Settings in IDE
- Module: [Nodemcu]
- Flash Size: [4MB]
- lwip Variant: [v2 Lower Memory or Higher Bandwidth]
- Reset Method: [nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [SERIAL]
- Upload Speed: 115200
Problem Description
After enabling mdns during setup, ot does not work. Although the ip is available. If you reconnect (by its function) after losing the connection, it is available. Which looks weird.
Setup:
Serial.println(F("WIFIConnectInternet() start"));
WiFi.softAPdisconnect();
if (WiFi.SSID() != "") {
Serial.println(F("WiFi credentials set in flash, wiping them"));
WiFi.disconnect(true);
}
if (WiFi.getAutoConnect()) {
Serial.println(F("Disabling auto-connect"));
WiFi.setAutoConnect(false);
}
WiFi.persistent(false);
WiFi.mode(WIFI_STA);
delay(100);
byte tries = 11;
String _ssid = jsonRead(configSetup, "ssid");
String _password = jsonRead(configSetup, "password");
if (_ssid == "" && _password == "") {
WiFi.begin("null","null");
}
else {
WiFi.begin(_ssid.c_str(), _password.c_str());
}
while (--tries && WiFi.status() != WL_CONNECTED) //ждем подключения.
{
Serial.print(".");
yield();
delay(1000);
}
if (WiFi.status() != WL_CONNECTED) {
//не удалось....
Serial.println(F("NO CONNECT ROUTER!\n"));
} else {
// удалось подключиться, говорим о подключении и выводим адрес IP
connectMode=1;
delay(150);
if (!MDNS.begin(DNS_NAME,WiFi.localIP()))
{
Serial.printf("Cannot restart mDNS responder\n");
}
else
{
Serial.printf("mDNS responder Started, IP is: %s\n", WiFi.localIP().toString().c_str());
}
delay(150);
MDNS.addService("http", "tcp", 80);
MDNS.addService("ws", "tcp", 81);
}
All right, he's connected:
13:18:14.591 -> WIFIConnectInternet() start
13:18:14.694 -> Disabling auto-connect
13:18:14.797 -> ......mDNS responder Started, IP is: 192.168.31.83
but DNS_NAME remains unavailable. Although 192.168.31.83 is available
I also use the connection check function, and if the connection is lost, it disables DNS and connects it when the connection is restored. After that, DNS_NAME works.
loop: CheckConnect();
void CheckConnect(){
static int lastStatus = WiFi.status();
if (WiFi.status() != WL_CONNECTED && lastStatus == WL_CONNECTED ){
Serial.printf("Интернета нет...... OFF MDNS! \n");
MDNS.end(); //завершаем.
delay(150);
}
if (WiFi.status() == WL_CONNECTED && lastStatus != WL_CONNECTED ){ //если интернета небыло, и он появился:
Serial.printf("Connected, IP is: %s\n", WiFi.localIP().toString().c_str());
delay(150);
Serial.printf("MDNS begin 1 \n");
if (!MDNS.begin(DNS_NAME,WiFi.localIP())) //пытаемся запустить днс на новом ип.
{
Serial.printf("Cannot restart mDNS responder\n");
}
else
{
Serial.printf("mDNS responder restarted\n");
}
delay(50);
Serial.printf("MDNS addService 2 \n");
MDNS.addService("http", "tcp", 80); yield(); //запускаем сервисы.
MDNS.addService("ws", "tcp", 81); yield();
delay(150);
}
lastStatus = WiFi.status();
yield();
};
I specifically checked by turning off the Internet:
13:20:07.828 -> Интернета нет...... OFF MDNS!
13:20:13.378 -> FreeHeap: 40504 -- Uptime: 00:02:00
13:20:18.574 -> Connected, IP is: 192.168.31.83
13:20:18.711 -> MDNS begin 1
13:20:18.711 -> mDNS responder restarted
13:20:18.745 -> MDNS addService 2
After that, the DNS works...
Platform
Settings in IDE
Problem Description
After enabling mdns during setup, ot does not work. Although the ip is available. If you reconnect (by its function) after losing the connection, it is available. Which looks weird.
Setup:
MCVE Sketch
All right, he's connected:
but DNS_NAME remains unavailable. Although 192.168.31.83 is available
I also use the connection check function, and if the connection is lost, it disables DNS and connects it when the connection is restored. After that, DNS_NAME works.
loop: CheckConnect();
I specifically checked by turning off the Internet:
After that, the DNS works...