The project uses data transfer through 4 sockets at the same time (it determines which socket is free and data is placed there). Everything works fine on ESP32, but it doesn't work on ESP32-S2. After several blocks of data (1408 bytes each) have been sent, function send(...) returns -1 (socket write error).
When using a single socket, data is transmitted normally.
Please help me understand how to fix this?
Code of the data sending function:
Code: Select all
uint8_t PutToSocket(uint8_t * data, uint16_t len_data, uint16_t *len_data_sent)
{
int len = 0;
fd_set fd_write_set;
struct timeval tv;
int retval;
uint8_t return_result = SOCKET_WRITE_IN_PROGRESS;
uint8_t retry_counter = 0;
uint8_t i = 0;
retry_counter = 0;
return_result = SOCKET_WRITE_IN_PROGRESS;
if (!len_data)
{
return return_result;
}
while ( (retry_counter < 3) && (return_result != TRANSFER_OK) )
{
*len_data_sent = 0;
retry_counter++;
FD_ZERO (&fd_write_set);
for(i = 0; i < num_sockets; i++)
{
FD_SET (sock[i], &fd_write_set);
}
tv.tv_sec = 10;
tv.tv_usec = 0;
retval = select (FD_SETSIZE, NULL, &fd_write_set, NULL, &tv); // Block until input arrives on one or more active sockets.
if(retval == -1)
{
printf("Socket error at write data\n");
return_result = ERROR_SOCKET_WRITE_SELECT;
}
else if(retval == 0)
{
printf("Socket timeout %d sec occurred at write\n", (uint8_t)tv.tv_sec);
return_result = ERROR_SOCKET_WRITE_SELECT_TIMEOUT_OCCURRED;
}
else if (retval > 0)
{
for(i = 0; i < num_sockets; i++)
{
if(FD_ISSET(sock[i], &fd_write_set))
{
len = send(sock[i], data, len_data, 0);
break;
}
}
if ((len) < 0)
{
printf("Error write to socket %d\n", len);
return_result = ERROR_SOCKET_WRITE_SEND;
}
else if (len == 0)
{
printf("Write ZERO to socket\n");
return_result = ERROR_SOCKET_WRITE_SEND_ZERO;
}
else if (len > 0)
{
if (len == len_data)
{
*len_data_sent = len;
return_result = TRANSFER_OK;
}
else
{
return_result = SOCKET_WRITE_IN_PROGRESS;
}
}
}
}
return return_result;
}