EDIT: I have created an issue about this here: https://github.com/esp8266/Arduino/issues/4593

I have this server: (Check that it works:

And I have this code in my ESP8266:

#include <ESP8266WiFi.h>

#define HOST ""
#define PORT 80
#define WIFI_SSID "SSID"

const char* ssid = WIFI_SSID;
const char* password = WIFI_PSW;

void setup () {
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("Connecting to Wifi...");

  while(!pingServer()) {
    delay(3000); //Send a request every 3 seconds

void loop() {}

bool pingServer() {
  WiFiClient client;

  if (!client.connect(HOST, PORT)) {
    Serial.println("connection failed");
    return false;

  Serial.println("connection success!");
  return true;

The expected result: Connection success, but got connection failed.

If I try connecting with my PC, it works, only with ESP8266 it doesn't.

Tapping with Wireshark I suspect that there is a problem with ESP8266 TCP packets, here I leave them for you to analyze:

PC TCP connection request (which works):


ESP8266 TCP connection request (which receives no response from server):


What I've also checked:

  • The ESP connects fine to other servers.

  • There is no firewall blocking the connection between ESP and the server.

  • I've tried this in different networks and conditions, the error persists.

  • Other computers can connect to the server, so ESP should be able as well.

  • Tried with different ESP8266 boards to rule out hardware malfunctioning.

  • I am using NODEMCU V0.9 board (original firmware) with Arduino IDE and this ESP8266 library.

How to replicate:

  1. Using the latest Arduino IDE and ESP8266 library.

  2. Check that the test server works at (just open this link basically and see that is running nginx).

  3. Copy and upload the code above to your ESP8266 (NODEMCU or similar).

  4. Open the Arduino IDE console/monitor and confirm that no connection is established to port 80.

  5. Rage in admiration for such a strange bug.

I've opened an Issue for this: https://github.com/esp8266/Arduino/issues/4593

1 Answer 1


Not a cookie cutter answer, I did a quick test and my ESP8266 does connect to you nginx. Of course you do not accept the params from my fridge, but this is what I see in the log.

7007 :
7010 :

For online documentation and support please refer to
7012 : nginx.org.

7015 : Commercial support is available at
7018 : nginx.com.

7020 :
7022 :

Thank you for using nginx.

7024 :
7026 :
7028 : HTTP : closing connection

You should be able to see that on your side as well.

I am using letscontrolit/ESPEASY https://github.com/letscontrolit/ESPEasy

And their code to connect looks like

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  if (!ControllerSettings.connectToHost(client))
    addLog(LOG_LEVEL_ERROR, F("HTTP : connection failed"));
    return false;

  boolean connectToHost(WiFiClient &client) {
    if (!checkHostReachable(true)) {
      return false; // Host not reachable
    byte retry = 2;
    bool connected = false;
    while (retry > 0 && !connected) {
      connected = client.connect(getIP(), Port);
      if (connected) return true;
      if (!checkHostReachable(false))
        return false;
    return false;

I am using generic HTTP for my controller which here: https://github.com/letscontrolit/ESPEasy/blob/503fd3555e010b08b48fb2dc18290ef120005308/src/_C008.ino

You could try the connect to function to see if that works for you.

  • Thank's for helping. I am going to try that. Meanwhile this might be a library problem indeed, I opened an issue in the official esp8266 lib repo: github.com/esp8266/Arduino/issues/4593
    – nemewsys
    Commented Apr 1, 2018 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.