esp8266 / esp8266/Arduino

Device is unable to retrieve domain IP after DNS change on router without interrupting the WiFi network

Open
#9,138 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

#### Platform

- Hardware: ESP8266 generic / own PCB
- Core Version: Release 3.1.2
- Development Env: Platformio, but it doesn't matter
- Operating System: Windows / Linux (I have automatic pipeline)

### Settings in IDE

- Module: Generic ESP8266 Module
- Flash Mode: qio
- Flash Size: 4MB
- lwip Variant: default
- Reset Method: n/a
- Flash Frequency: 40Mhz
- CPU Frequency: 80Mhz
- Upload Using: OTA

### Problem Description - short
After pulling out SIM card from my LTE router and plugging it back again, the esp8266 based device is unable to reconnect to the server via domain name - **getHostByName** fails with timeout (-3). **WiFi is uninterrupted during this operation (no reconnection etc.)**

The workaround is to set fixed DNS just after WiFi connection setup.

```cpp
inline void overrideDnsWithGoogleDns()
{
/* Define override DNS addresses. */
static const ip_addr primaryDns{LWIP_MAKEU32(8, 8, 8, 8)};
static const ip_addr secondaryDns{LWIP_MAKEU32(8, 8, 4, 4)};

/* Set DNS servers. */
dns_setserver(0, &primaryDns);
dns_setserver(1, &secondaryDns);
}
```

### Problem Description - long

I'm working on home automation system since 2017 or so. My hardware platform is based on various ESP versions. I've also built a library that integrates shared device functionality, like MQTT and so on. The library is open source: https://github.com/cziter15/ksIotFrameworkLib.

The issue appear only on arduino for esp8266 and is not observed on esp32 arduino core.

I have ksMqttConnector component in the library that manages MQTT connection. The user can pass domain name, which will be used to retry connection after disconnect. It's very flexible, because it also handles the case when domain's IP changes (dyn DNS configurations or public domains).

For refrence, please check:
https://github.com/cziter15/ksIotFrameworkLib/blob/master/src/ksf/comp/ksMqttConnector.cpp

Reproduction steps:
- Start the device and wait until it connects to the MQTT.
- Pull out the SIM from the LTE router and wait few seconds.
- Plug in the card and wait until the network is back again on the PC.
- Notice that arduino-esp8266 based device is unable to reconnect to the target.

### [MCVE](https://stackoverflow.com/help/mcve) Sketch
N/A

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.