Skip to content

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

Open
@cziter15

Description

@cziter15

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.

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 Sketch

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions