EDIT: I have created an issue about this here: https://github.com/esp8266/Arduino/issues/4593
I have this server: 185.205.210.197
(Check that it works: http://185.205.210.197/)
And I have this code in my ESP8266:
#include <ESP8266WiFi.h>
#define HOST "185.205.210.197"
#define PORT 80
#define WIFI_SSID "SSID"
#define WIFI_PSW "PASSWORD"
const char* ssid = WIFI_SSID;
const char* password = WIFI_PSW;
void setup () {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(5000);
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):
000030006b081c001a48ea4c0000000010009e098004dba400000000800401009e090b221f000000c603000004000000880254009801a7ad45b7000af5f4e90c000af5f4e90c603c0000aaaa0300000008004500003c000040003706cb37b9cdd2c5c0a82b490050df312dfea1498c6ac92aa0120000079c00000204058c0402080a336f35554aeb0fe90103030700ead7d1
ESP8266 TCP connection request (which receives no response from server):
000019006f080000952a9f520000000012049e098004daa1000801a200000af5f4e90c2c3ae80f137f000af5f4e90c5000aaaa0300000008004500002c00030000ff06431dc0a82b70b9cdd2c5c00100500000196d000000006002086040f80000020402189ccdd933
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:
Using the latest Arduino IDE and ESP8266 library.
Check that the test server works at http://185.205.210.197:80/ (just open this link basically and see that is running nginx).
Copy and upload the code above to your ESP8266 (NODEMCU or similar).
Open the Arduino IDE console/monitor and confirm that no connection is established to port 80.
Rage in admiration for such a strange bug.
I've opened an Issue for this: https://github.com/esp8266/Arduino/issues/4593