ESP_igrr wrote:That's about 4.5 Mbit/sec. Are you testing in air or in a shielded box?
Also, please update the code to check the return value from sendto and, in case if the return value is not as expected, the value of errno.
If errno is ENOMEM, you need to perform rate control by setting up a timer or using delay to attempt sending again.
Without this it is impossible to say whether the packets are really lost or just not accepted for transmission.
Thank you for your response!Errno is ENOMEM.I did what you said,But things are not getting better.This bug is complicated.So for debugging, I want to figure out one question at first.Only focused on UDP problems of ESP32.I have a simple project that only send UDP packages constantly.Here is the code.
Code: Select all
static void udp_thread(void *p)
{
int i = 0;
int sock;
struct sockaddr_in toAddr;
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
LWIP_UNUSED_ARG(p);
sock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
if(sock < 0)
{
ESP_LOGI(TAG, "socket err");
}
memset(&toAddr,0,sizeof(toAddr));
toAddr.sin_family=AF_INET;
toAddr.sin_addr.s_addr=inet_addr("192.168.23.1");
toAddr.sin_port = htons(REMOTE_PORT);
while(1)
{
usertimeout.tv_sec=1;
usertimeout.tv_usec=0;
/*******************************start means the start of a frame ********************************************/
sendto(sock,start,SEND_START_LEN,0,(struct sockaddr*)&toAddr,sizeof(toAddr));
/*******************************start contents of a frame ********************************************/
for(i=0; i<LINES; i++)
{
FD_ZERO(&rdfds);
FD_CLR( sock, &rdfds);
FD_SET(sock,&rdfds);
ret=select(sock+1,NULL,&rdfds,NULL,&usertimeout);
if(ret>0)
{
if(FD_ISSET(sock,&rdfds))
{
ret=sendto(sock,image[i],SEND_BUF_LEN,0,(struct sockaddr*)&toAddr,sizeof(toAddr));
if(ret<0)
{
perror("send failed reason");
/*
ets_delay_us(500);
ret=sendto(sock,image[i],SEND_BUF_LEN,0,(struct sockaddr*)&toAddr,sizeof(toAddr));
*/
}
}
}
}
/*******************************end means the end of a frame ********************************************/
sendto(sock,end,SEND_END_LEN,0,(struct sockaddr*)&toAddr,sizeof(toAddr));
gpio_set_level(16, 0);
}
close(sock);
vTaskDelete(NULL);
}
From my test.The result of sending fail is "not enough space".This happens almost 5%.It's not too bad.If I add ets_delay_us(500) and then send the data again,things will getting better.Almost no sending fail happens.But adding delay is not a good method for my camera project.Is there any ohter methods can solve this problem instead of adding delay.