ESP-32 TCP/IP server freezes when trying to send data to client out of range

barrerar
Posts: 4
Joined: Tue May 31, 2022 10:59 pm

ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby barrerar » Tue May 31, 2022 11:15 pm

Good evening,

I currently have an application where an ESP-32 is configured as a TCP/IP server, allowing multiple clients connections. The server is the only one sending data. Therefore, all the clients are only receiving information and not sending anything to the server.

When a client connects, it starts to receive data. Everytime the server sends data, it receives the OK and SEND OK replies. However, if we place the client out of range from the server, the server freezes waiting the SEND OK or SEND FAIL reply. At this point, I am not able to send any data to the esp-32. It takes about 3 minutes for the esp-32 server to understand that the client is out of range, to close the connection and to provide the SEND FAIL reply. Only after this the esp-32 comes back to accept the commands.

Since I am dealing with multiple clients, I must be able to continue sending data to the clients that are in range eventhough there is a client that lost range. I cannot wait 3 minutes without sending data to any client in order to regain control of the esp-32 server.

Any thoughts in how to solve this issue?

Thank you,

Rodrigo

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby ESP_Sprite » Wed Jun 01, 2022 1:35 am

I assume you use standard sockets to send this? The way to go would be either to use select() to wait for the socket to be writable, or to make your sockets non-blocking.

barrerar
Posts: 4
Joined: Tue May 31, 2022 10:59 pm

Re: ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby barrerar » Wed Jun 01, 2022 1:46 am

I am using the ESP-32 AT command set list to perform all the configurations. In order to send data i am using the AT+CIPSEND command. How can i configure a non-blocking socket using the AT command set?

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby ESP_Sprite » Wed Jun 01, 2022 3:57 am

Ah, never mind then, I have no idea about the AT command set. I'll move your post to the forum that discusses it, perhaps someone else does.

ESP_Sun
Posts: 326
Joined: Thu Dec 30, 2021 9:52 am

Re: ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby ESP_Sun » Wed Jun 01, 2022 11:04 am

Hi, maybe you can set the <so_sndtimeo> parameter of the AT+CIPTCPOPT (https://docs.espressif.com/projects/esp ... et-options) command, when the device is out of range, it will return SEND FAIL and close the connection at the time you set.

barrerar
Posts: 4
Joined: Tue May 31, 2022 10:59 pm

Re: ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby barrerar » Wed Jun 01, 2022 2:49 pm

Hi ESP_SUN,

I have tried what you suggested. After setting the <so_sndtimeo> to 500 ms, I received the following answer from the module:

+CIPTCPOPT:0,-1,0,500
+CIPTCPOPT:1,-1,0,500
+CIPTCPOPT:2,-1,0,500
+CIPTCPOPT:3,-1,0,500
+CIPTCPOPT:4,-1,0,500

OK

However, after performing the same tests, the so_sndtimeo setted is not respected. After the client goes out of range, the server takes about 90 seconds to close the connection and to allow me to talk to it again. After several trials, this timeout of 90 s is always respected after client is out of range.

Do you know which time constant is setted to 90 s in the source code? Which command AT should I use in order to change this value?

Thank you,

Rodrigo

ESP_Sun
Posts: 326
Joined: Thu Dec 30, 2021 9:52 am

Re: ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby ESP_Sun » Thu Jun 02, 2022 12:46 pm

Hi Rodrigo,

1. Yes, I reproduced your problem too. The AT+CIPTCPOPT command does not currently work with a device acting as a server. It is being improved internally. If there is any progress, I will let you know as soon as possible.

2. 90 seconds is because it takes time to retransmit data at the protocol layer, which is a normal phenomenon.

Thank you very much for your question

sun

barrerar
Posts: 4
Joined: Tue May 31, 2022 10:59 pm

Re: ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby barrerar » Thu Jun 02, 2022 3:58 pm

Hi Sun,

I understand that your protocol probably have a number of retries to be performed if an ACK is not received from the Client. However, 90 s is a little high.

That would be excellent if the maximum number of retries / retry times could be configured.

As far as I understood, this cannot be configure using the AT commands within a TCP server, correct? If I code into the module directly, without using the AT commands, would I be able to change this configuration?


Sorry for bothering asking, however, since I have a real-time application, I cannot stop sending data to the other clients on the network if only one client is out of range.

Thank you,

Rodrigo

ESP_Sun
Posts: 326
Joined: Thu Dec 30, 2021 9:52 am

Re: ESP-32 TCP/IP server freezes when trying to send data to client out of range

Postby ESP_Sun » Mon Jun 13, 2022 2:51 am

Hi,

Maybe you can try changing the number of retransmissions in menuconfig to reduce this time.
388c2a8af5167c0e84b5f19c9f986fc3.jpg
388c2a8af5167c0e84b5f19c9f986fc3.jpg (1011.34 KiB) Viewed 6093 times

Who is online

Users browsing this forum: No registered users and 27 guests