ESP32 Multicast UDP High losses (receiving)

Multi tool use
Multi tool use


ESP32 Multicast UDP High losses (receiving)



I'm developing device base on ESP32 module that have a UDP socket open only to receive broadcast packets on one port (7890 to be exact). The problem is that the data losses are high - around 90%. My test setup is:



When I send something from PC or mobile phone there is no data lossage between Mobile phone and PC but ESP32 receive around 10% of data that I transmit from both of senders. If I change from multicast to unicast on PC or Phone to send data to ESP32, it work without problem.



I know that UDP does not guarantee the delivery but 10% efficiency seems for me to be super low, especially when it seems that there is no problem with busy network because PC and mobile received the data all the time.



Do you have any suggestion to the code or some setting that can be changed in menu config ?
At the moment my application have only two tasks:



Update 04.07.2018 (13:15)



Problem disappear when I don't initialize bluetooth. Sorry that I didn't mention previously about BT being initialized but I kept me initializing function from my normal program that have a lot more tasks (BT included) and totally forgot about this myself.



Anyway - do you think that there is some issue with sharing the resource or is it some physical interference ? I'm using ESP32-DevKitC that is on the breadboard, so no additional shielding is present.


#define PORT_NUMBER 7890
#define BUFLEN 100

void udp_task(void *pvParameter)
{
struct sockaddr_in clientAddress;
struct sockaddr_in serverAddress;
struct sockaddr_in si_other;
unsigned int slen = sizeof(si_other);
unsigned int recv_len;
char buf[BUFLEN];
int sock;

printf("UDP Task: Opening..n");

int ret;
ret = UDP_List_Open(&clientAddress, &serverAddress, &sock);

if(ret == 0)
{
printf("UDP Task: Openn");
}
else
{
printf("UDP Task: Can't openn");
}


while(1)
{
memset(buf,0,100);

if ((recv_len = recvfrom(sock, buf, 100, 0, (struct sockaddr *) &si_other, &slen)) == -1)
{
printf("UDP errorn");
break;
}

sendto(sock, buf, recv_len, 0, (struct sockaddr *)&si_other, sizeof(si_other));

printf("UDP Task: Received packet from %s:%dn", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port));
printf("UDP Task: Data: %s -- %dn" , buf, recv_len);
}

while(1)
{
vTaskDelay(100 / portTICK_RATE_MS);
}
}


int UDP_List_Open(struct sockaddr_in* clientAddress, struct sockaddr_in* serverAddress, int* sock)
{
// Create a socket that we will listen upon.
*sock = socket(AF_INET, SOCK_DGRAM, 0);
if (*sock < 0)
{
printf("UDP List Open: Socket errorn");
return 1;
}

// Bind our server socket to a port.
serverAddress->sin_family = AF_INET;
serverAddress->sin_addr.s_addr = htonl(INADDR_ANY);
serverAddress->sin_port = htons(PORT_NUMBER);
int rc = bind(*sock, serverAddress, sizeof(*serverAddress));
if (rc < 0)
{
printf("UDP List Open: Bind errorn");
return 2;
}

return 0;
}




1 Answer
1



Even though UDP is considered fire and forget, (unlike TCP), unicast UDP through WiFi is reliable because reliability is built into the WiFi protocol. But this can work for Unicast only because there is one known recipient. Multicast UDP is unreliable because there are no checks and retries.



I had the same problem when I was trying to use multicast UDP with the ESP8266. It caused me to dig deeper into the issue. In the end I use UDP multicast for discovery but then switch to Unicast UDP for subsequent transfers.



See Multicast Wifi Problem Statement
https://tools.ietf.org/id/draft-mcbride-mboned-wifi-mcast-problem-statement-01.html





Thanks, My idea was the same: use server broadcast to discover the device and after that connect them with unicast, but discovery can take a lot of time with such losses (for ex. 15s interval in broadcast can end up in 150s of discovery time). I'm aware that UDP in multicast is not reliable but 90% of packet error rate (PER) seems to me too high, in every article they are mentioning 5, 10 or 15% of PER but not 90%.
– Konrad
Jul 4 at 6:10





It really depends on the specific situation. How much activity is happening on that band of frequencies. The physical position of the radio (on both ends). I had a few modules active in my tests and some would have a harder time than others. And moving the radio changed things.
– Rudy
Jul 4 at 13:03





At work we have a WiFi for testing, and on of the software developers told me that he knows when I use the microwave oven at lunch time because the WiFi stops working. When you switch to Unicast you see the difference. And as far as the radio transmissions go, there is no difference between multicast and unicast. The difference is in the retries.
– Rudy
Jul 4 at 13:10





That is funny and terrible at the same time. Anyway, it turns out that the bluetooth is responsible for losses, I'm not sure though whether it is some software or physical issue.
– Konrad
Jul 5 at 6:11






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

1AtunEZ WIX81b 9nQ vD4ae V FED,Dc9ltsibxcFc cfcoOKL3OxMt,JzrGP2JkaCy HtzYfRbjswO
8wEBqqhn,A,RF7yPirho6aHMEp,PUgh4A7D ePh49zYH59B9v72Epyt4d8A4joe92,bbzFDjxbcvmyih

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications