ESP32 TCP latency: ~200–300ms delay between send and recv despite optimizations

danielbr3
Posts: 2
Joined: Wed Jun 22, 2022 11:28 am

ESP32 TCP latency: ~200–300ms delay between send and recv despite optimizations

Postby danielbr3 » Thu Mar 27, 2025 12:54 pm

I need help in shortening the time it takes to read the response from the server on a TCP socket because I have tried many methods and none of them worked and I do not know what is really causing the delay. My communication looks like this: I send a single message on a given socket and then I expect an ACK response. M

Code: Untitled.c Select all

y processing time is quite fast, but after sending the message I usually observe about 300ms until the response is read, despite the fact that in wireshark I see that the server responds about 30-50ms after sending the message.

The task in which I handle the TCP connection has a high priority in FreeRTOS support and during this time nothing serious is being done by other processes.

I have tried the following approaches:

Disable Nagle’s Algorithm (TCP_NODELAY).

Reduce/Remove Delay in the Main Loop (lower vTaskDelay or no delay).

Use select() instead of repeatedly polling sockets with delays.

Increase Task Priority for the recv/select handler.
Reduce Number of Sockets and simplify code logic.
Short recv() Timeout (via SO_RCVTIMEO with 1ms or similar).

In attachment I share the code and ask for some advice on how I can reduce the response time, because it is crucial in my application. On another modem operating via GSM this time was a maximum of 50ms.
Attachments
cms_tcp_udp_client.c
(19.56 KiB) Downloaded 67 times

Bryght-Richard
Posts: 103
Joined: Thu Feb 22, 2024 3:59 pm

Re: ESP32 TCP latency: ~200–300ms delay between send and recv despite optimizations

Postby Bryght-Richard » Fri Mar 28, 2025 8:21 pm

Ethernet or WiFi? If WiFi, what's the AP DTIM interval and beacon rate? esp_wifi_get_ps() result?

feixiao123
Posts: 4
Joined: Sun Sep 07, 2025 11:42 pm

Re: ESP32 TCP latency: ~200–300ms delay between send and recv despite optimizations

Postby feixiao123 » Mon Sep 08, 2025 1:24 am

hi,
have you find the way to minimize the latency?
I am using the AT command to send data in TCP passthrough mode, and suffering the same problem.

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest