esp8266 / esp8266/Arduino

DNS lookup problem

Open
#8,780 8 comments 0 reactions 0 assignees View on GitHub
waiting for feedback
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

### Basic Infos

- [ x ] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [ x ] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [ x ] I have tested that the issue is present in current master branch (aka latest git).
- [ x ] I have searched the issue tracker for a similar issue.
- [ x ] If there is a stack dump, I have decoded it.
- [ x ] I have filled out all fields below.

#### Platform

- Hardware: [ESP-12]
- Core Version: [3.0.2]
- Development Env: [Arduino IDE]
- Operating System: [Windows]

### Settings in IDE

- Module: [Generic ESP8266 Module]
- Flash Mode: [DOUT]
- Flash Size: [4MB]
- lwip Variant: [v2 Lower Memory]
- Reset Method: [dtr]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [SERIAL]
- Upload Speed: [115200]

### Problem Description

I have a separate router and modem.
After temporary data loss (modem disconnected, internet reconnection, etc), without WiFi connection loss ESP DNS cant solve any IP addresses.

I have enabled the DEBUG level to WIFI.

### Sketch

```cpp

#include

const char* ssid = "my-ssid";
const char* password = "my-password";

void setup() {
Serial.begin(115200);

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void loop() {
IPAddress ipResult;
int result = WiFi.hostByName("www.google.com", ipResult);
Serial.print("Result: "); Serial.println(result);
Serial.print("Ip: "); Serial.println(ipResult);
Serial.println();
delay(5000);
}

```
Turn on the router WITHOUT DATA (modem connection), and start the ESP.

The output, as expected, is this:

```
[hostByName] request IP for: www.google.com
[hostByName] Host: www.google.com lookup error: -5!
Result: 0
Ip: (IP unset)
```
But after data reestablishing (connecting the router to the modem), ESP still cannot resolve the IP address.

I know there is a DNS cache (I don't know exactly how long it lasts), but I left it running for 24 hours and the output remained the same.

I tried some actions, like reconnecting to WiFi, but is only solves if I restart the device.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.