Skip to content

Getting [E][WiFiGeneric.cpp:658] hostByName(): DNS Failed randomly #2778

Closed
@GeorgeFlorian

Description

@GeorgeFlorian

Hello !

I am using a HTTP Client inside loop to check for the body of a URL.
It worked fine until it didn't.
Today the ESP crashed and restarted. After the restart it connected to the WiFi using SSID and Password, so using DHCP. But it behaved like it did not connect.

  • The web-pages that I have on the ESPAsyncWebServer didn't work.
  • And I repeatedly got:
[E][WiFiGeneric.cpp:658] hostByName(): DNS Failed
[HTTP] GET... failed, error: connection refused

This is a part of the code that runs in void loop():

if (WiFi.status() == WL_CONNECTED && SPIFFS.exists("/configFile.txt")) {  //Check the current connection status 
      if(URL.length() > 15) {
        HTTPClient http;
        http.begin(URL); //Specify the URL
        int httpCode = http.GET(); //Make the request  
        if (httpCode > 0) { //Check for the returning code
          logOutput((String)"[HTTP] GET... code: " + httpCode);
          if(httpCode == HTTP_CODE_OK) {
              String payload = http.getString();
              logOutput(payload);
              signPlace = getPlaces(payload);
              oldSignPlace = signPlace;
            }
        } else {
            logOutput((String)"[HTTP] GET... failed, error: " + http.errorToString(httpCode).c_str());
          }  
        http.end(); //Free the resources
        } else {
            logOutput("URL Link is invalid ! Please enter another URL");
        }
    } // if (WiFi.status() == WL_CONNECTED)

Manually restarting the ESP, by pressing on the EN button, did fix the issue, however I still get this randomly. The only fix is to restart again !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions