esp8266 client call to server DNSserver doesn't reply

Hi all,

I have a problem with 2 esp8266 in client /server configuration.

When I send a request to the server using its IP the server responds to client and communication happens with no ‘major’ issues. When I do use the ESP8266mDNS.h to assign a name to the server the calls from the client are answered by the server (I can see this through the serial monitor) but the client reports httpCODE -1 or -5.
After weeks I can’t still make them working using the DNS even if DNS name works well from my browsers on both os x and windows.

I attache the codes if someone has an idea on how to solve this cumbersome.

Any help is much appreciated

Kind regards

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = “xxx”;
const char* pw = “yyy”;

void setup() {

WiFi.begin(ssid, pw); //WiFi connection

while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion

Serial.println(“Waiting for connection”);



void loop() {

if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status

HTTPClient http; //Declare object of class HTTPClient

http.begin(“http://testing.local:80/send_IP”); //Specify request destination IF I REPLACE SERVER DNS NAME WITH CURRENT IP EVERYTHING WORKS
http.addHeader(“Content-Type”, “text/plain”); //Specify content-type header

int httpCode = http.GET();//“Message from ESP8266”); //Send the request
String payload = http.getString(); //Get the response payload

Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload

http.end(); //Close connection

} else {

Serial.println(“Error in WiFi connection”);


delay(30000); //Send a request every 30 seconds



#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h> //
#include <ESP8266mDNS.h>

String version = “revB”; // Version of this program
WiFiClient client;
ESP8266WebServer server(80);

const char* WiFi_hostname = “testing”;

void setup() {
WiFiManager wifiManager;
if(!wifiManager.autoConnect(“ESP8266_AP”)) {
Serial.println(F(“failed to connect and timeout occurred”)); delay(3000);
ESP.reset(); //reset and try again
if (MDNS.begin(WiFi_hostname)) { //Start mDNS
Serial.println(“MDNS started”);


server.on("/", systemSetup);
server.on("/send_IP", send_IP); // reply to client with server’s IP



void loop() {



void systemSetup() {
webpage = “”; // don’t delete this command, it ensures the server works reliably!
String IPaddress = WiFi.localIP().toString();
webpage += “

Automated data logger System, no setup required here

webpage += “<meta http-equiv=“refresh” content=“20”; URL=http://” + IPaddress + “/G>";
webpage += “<form action=“http://”+IPaddress+”" method=“POST”>";
server.send(200, “text/html”, webpage); // Send a response to the client asking for input
webpage = “”;

void send_IP() {
String s;
IPAddress ip = WiFi.localIP();
String ipStr = String(ip[0]) + ‘.’ + String(ip[1]) + ‘.’ + String(ip[2]) + ‘.’ + String(ip[3]);
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\nHello from ESP8266 at ";
s += ipStr;
s += “\r\n\r\n”;
Serial.println(“Sending 200”);

Serial.println(“Done with client”);


void append_page_header() {
webpage = “”;
// if (AUpdate) webpage += “”; // 30-sec refresh time, test needed to prevent auto updates repeating some commands
webpage += " Sensor Readings";
webpage += “body {width:1020px;margin:0 auto;font-family:arial;font-size:14px;text-align:center;color:blue;background-color:#F7F2Fd;}”;
webpage += “

ESP8266_home” + version + “


void append_page_footer(){ // Saves repeating many lines of code for HTML page footers
webpage += “ul{list-style-type:none;margin:0;padding:0;overflow:hidden;background-color:#d8d8d8;font-size:14px;}”;
webpage += “li{float:left;border-right:1px solid #bbb;}last-child {border-right: none;}”;
webpage += “li a{display: block;padding:3px 15px;text-decoration:none;}”;
webpage += “li a:hover{background-color:#FFFFFF;}”;
webpage += “section {font-size:14px;}”;
webpage += “p {background-color:#E3D1E2;}”;
webpage += “h1{background-color:#d8d8d8;}”;
webpage += “h3{color:orange;font-size:24px;}”;
webpage += “”;
webpage += “”;