Packets arriving delayed and grouped (TCP/UDP server)

Fardenco
Posts: 1
Joined: Mon Jun 05, 2023 10:24 am

Packets arriving delayed and grouped (TCP/UDP server)

Postby Fardenco » Mon Jun 05, 2023 11:19 am

Hi,
I'm creating a robot I want to control in real time over WiFi but I'm encountering some delay wen receiving packets.
I tried on an ESP32-C3 and on an ESP32-WROOM-32, I get the same issue.
I wrote a very simplified version of the code to eliminate other variables, same deal.
The ESP32 is acting as the server, and the client is written in C#.
Here is the problem :
The client connects to the server, and sends a payload of 1 bytes (smallest payload possible, just for testing), every 25ms.
But on the server side, the datas are received grouped, here is an example of what I receive :

Char p received at 58913
Char p received at 58913
Char p received at 58933
Char p received at 58953
Char p received at 58983
Char p received at 59184
Char p received at 59184
Char p received at 59184
Char p received at 59184
Char p received at 59185
Char p received at 59190
Char p received at 59200
Char p received at 59230
Char p received at 59260
Char p received at 59507
Char p received at 59507
Char p received at 59507
Char p received at 59508
Char p received at 59508
Char p received at 59518
Char p received at 59519
Char p received at 59519

you can see that the data are arriving grouped.

The code of the server is here :

void loop() {

WiFiClient client = wifiServer.available();
client.setNoDelay(true);

if (client)
{
while (client.connected())
{
while (client.available()>0)
{
char c = client.read();
Serial.print("Char ");
Serial.print(c);
Serial.print(" received at ");
Serial.println(millis());
}
delay(5);
}

client.stop();
Serial.println("Client disconnected");

}
}

I'm pretty sure the client is working great, I checked it by creating a server with C# running on another computer in the netword and the datas are arriving well in time and not grouped.

I've been searching for a solution for a few days, I've found some peoples talking about using the noDelay tag to avoid small packet delay, I added it to my code but it doesn't seem like it did much.
I've found some peoples suggesting to increase the priority of the thread that is handling TCP, but I have no idea about how to do that and my code is so simple I don't see how it could need a high priority, but I might be wrong
I've found people saying they achieved more that 10Mb/s with TCP, so I can't see how half a kb/s could be so hard to get consistently, so I guess I must be missing something.
If you have any suggestion, I'd be happy to hear it
Thanks

Who is online

Users browsing this forum: Google [Bot], lor_pig2 and 79 guests