-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Description
Basic Info
- This issue complies with the issue POLICY doc.
- I have read the documentation at readthedocs and the issue is not addressed there.
- I have tested that the issue is present in current master branch (aka latest git).
- I have searched the issue tracker for a similar issue.
- If there is a stack dump, I have decoded it.
- I have filled out all fields below.
Platform
- Hardware: NodeMCU V0.9 (ESP-12E Module) (Compatible)
- Core Version: [2.4.1]
- Development Env: [Arduino IDE 1.8.5]
- Operating System: [Windows, OSX]
Settings in IDE
- Board: NodeMCU V0.9 (ESP-12E Module)
- Flash Size: 4MB (1M SPIFFS)
- Debug Port: Serial
- Debug Level: None
- lwIP Variant: v2 Lower Memory
- CPU Frequency: 80Mhz
- Upload Speed: 115200
- Erase Flash: Only Sketch
- Programmer: AVRISP mkII
The Problem
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.
Wireshark
Tapping with Wireshark I suspect that there is a problem with ESP8266 TCP packets, here I leave them for you to analyze:
Success TCP Packet
PC TCP connection request (which works):
000af5f4e90c9801a7ad45b708004500004057b6400040066a7dc0a82b49b9cdd2c5dc6d1b3932f96fd800000000b002ffffc71e0000020405b4010303050101080a4ab5122c0000000004020000
(captured using basic ethernet)
Screenshot of an example of a TCP packet that is able to get a server's response.
ESP8266 TCP Packet (Not Success)
ESP8266 TCP connection request (which receives no response from server):
000019006f080000794c5e9b00000000126c9e098004d4a10008013c00000af5f4e90c2c3ae80f137f000af5f4e90c9002aaaa0300000008004500002c00270000ff0642f9c0a82b70b9cdd2c5c00d1b3900001c77000000006002086022f9000002040218a9636c75
(captured using monitor mode in Wireshark - has radiotap headers)
Screenshot example of an ESP8266 packet.
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.
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.
Possible Workaround
@Pablo2048 Suggested setting the Arduino IDE board option lwIP Variant
from v2 Lower Memory
to v2 Higher Bandwidth
. This increases the TCP MSS (http://lwip.wikia.com/wiki/Tuning_TCP) that goes from around 500 bytes to around 1400 bytes, which is accepted by this server.
Therefore by increasing the MSS, the server starts responding and a TCP connection is established, whereas with a low MSS the server wouldn't even answer back with an error packet (complete silence).