Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By powl
#74859 Hi,

I recently got some Wemos D1 R2 ESP8266 boards and program them with the Arduino IDE. I want to send them some control instructions and let them do some stuff then. After tryting to do it with the UDP proctoll I recognized that some of the packets get lost every now and then so I switched to the TCP protocoll, which apparently brings its own challenges.

I'm currently using some TCP socket test tools to establish a connection to the ESP8266 and send commands to it. The problem is, that the ESP seems to have severe timinig problems.

1) Let us beginn with the Ping responses. Whenever I start the commandline in Windows and ping the ESP, the responsetimes of the first few pings are in the range of 20 to over 100ms, only from the fourth one, every ping response just takes 1 or 2, occasionaly 3ms, which is totally fine. But every time I interrupt the pinging, wait a few seconds and start a new ping procedure, I get these high ping times at the beginning. Only after the first three ones, the ping times are low. This is completely reproducable. What is going on here? Does this even matter? What does the ESP do all the time while it's not responding to the ping?

2) The first TCP connection takes.. forever. To be precise: about 3 seconds. Whenever I restart the ESP and wait for the TCP Server to be ready (which takes no longer than about half a second) and then try to connect to it, the first connection buildup takes 3 seconds. Every further connection takes about 10 to 100ms (which in my opinion is still a bit slow?!). It doesn't even matter how long I let the ESP run between startup and the first TCP connection. I even tried it with different computers to send from. The first connection simply takes long. Is this normal? Wireshark tells me, there is a retransmission occuring (which takes most of the time)

3) The time until a TCP packet gets acknlowledged is also much too high. I established a connection, sent single empty TCP packets to the ESP and watched to be acknowledged by the ESP in Wireshark. I get values like these: 270ms, 234ms, 243ms, 118ms, 249ms, 189ms, 292ms, 145ms, 59ms, 253ms, 135ms, 203ms, 297ms. Isn't this totally unacceptable? I notice though when I put some lines of code that receive the tcp-packet and give me a message via the serial console in the loop()-function that the messages show up almost instantly when I send the packet. What does this mean? Does the ESP receive the packets but send the ACK with some delay? How can I achieve high data rates and low latency communication with such timings?

4) The UDP packet loss. Why does the ESP lose my UDP packets every now an then? Apparently it has something to do with the powersupply because when I plug an external power supply into the board the packet loss issue gets better but sometimes even then packets are lost. Even though I am sending not more than 1 packet per second. Shouldnt the ESP be capable of receiving hundrets of packages per second?

Why does the performance of the ESP seem to be so terrible? :( I've seen a Video of someone using Websockets (TCP-Connections!) to receive hundrets of packages from the ESP which means that a single packet gets transmitted in <5ms, so I assume this must somehow be possible. What else can I check? My next step would be to create a ping-pong communication between the ESP and my computer and measure the round trip time and the packet thorughput and compare it to other computers in my network.

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>

const char* ssid     = "WLAN";
const char* password = "test";

const int serverport = 4210;

WiFiServer server(serverport);

void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(100);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  server.begin();
  Serial.printf("Server started at port %d\n", serverport);
}

void loop()
{
// Here can be code or not. Doesn't matter. Timings are bad either way.
}
You do not have the required permissions to view the files attached to this post.