[En-Nut-Discussion] Having problems with UDP reception

SOUMEILLAN, Thomas Thomas.SOUMEILLAN at astrium.eads.net
Thu Aug 25 13:20:38 CEST 2011


Hello, 

I'm using the 2.1b Ethernut board for 4 months with the v.4.8.9 of the Nut/OS.
The board is used : 
*	as a web server to provide a web interface to the user, 
*	for data transmission (received using UDP through ethernet and sent using the UART link).

I having problem with the data reception using UDP : some of the packets sent to the UDP socket are lost (1 among 15000), I'm forced to use UDP and I can't lose data.

So, I will first inform you about the context of this problem.
The main thread aside, I have created 3 threads for my program :
*	2 HTTP threads each one has 512 Bytes of RAM and theirs priorities are set at 150 (to process HTTP requests) .
*	1 UDP reception thread which has 512  Bytes of RAM and priority is 1 because it is the most critical function (to process the reception and to store the last n data in a ring buffer).

The web interface processes AJAX request every 5 seconds in order to collect informations about the board status.

The client sends a 13-bytes long data every 7.8 ms to the UDP socket I have created in a initialization phase.
I haven't modified the size of the UDP reception buffer using the function : NutUdpSetSockOpt(...). I let the default parameters.
The reception of the data is performed like that :

#define Rec_buff_UDP2UART_SIZE 13
#define IP_ADDR "192.168.1.1"
#define REMOTE_PORT 1234

...
/* In the UDP init function */
UDPSOCKET* Rec_sock_UDP = 0;
uint8_t Rec_buff_UDP2UART[Rec_buff_UDP2UART_SIZE];
...
Rec_sock_UDP = NutUdpCreateSocket(REMOTE_PORT));
...
NutThreadCreate("Rec_Udp2Uartd", Rec_Udp2Uartd, 0, 512);

/* In the UDP thread */
int Rec_nb_UDP2UART = 0;
for (;;) {
	
		Rec_nb_UDP2UART = NutUdpReceiveFrom(Rec_sock_UDP, &ipAddr, &remotePort,
				Rec_buff_UDP2UART, Rec_buff_UDP2UART_SIZE, NUT_WAIT_INFINITE);

		if ((Rec_nb_UDP2UART < 0) || (Rec_sock_UDP == NULL)
				|| (stimFOGbox.connection != CONNECTED)) {
			puts("Data reception problem \r\n");
			break;
		}
		if (Rec_nb_UDP2UART > 0) { /* If data is OK */
			/* Check and stores the data in a ring buffer. */
		}
}
			
Every 5 seconds, the web interface processes AJAX request.

int Form_StatusUpdate(FILE * stream, REQUEST * req) {
	char* arg_s = NULL;

	NutHttpSendHeaderTop(stream, req, 200, "Ok");
	NutHttpSendHeaderBottom(stream, req, "xml", -1);
	NutSleep(1); /* I put some NutSleep(1) to let the highest priority thread get the CPU if it needs it. */
	arg_s = NutHttpGetParameter(req, "reset");

	if (arg_s) {
		if (strncmp(arg_s, "ok", 2) == 0) {
			FOG_Box_status.Data_Contiguity = OK;
			FOG_Box_status.Reception_Timing = OK;
		}
	}
	NutSleep(1);
	/* Writes the xml data onto the stream. */
	fputs("...", stream);
	fprintf(stream, "...");
	NutSleep(1);
	fprintf(stream, "...");
	NutSleep(1);
	fprintf(stream, "...");
	NutSleep(1);
	fprintf(stream, "...");
	NutSleep(1);
	return 0;
}

With all those precautions I still lose UDP packets.
So, I have used the software WireShark in order to spy my ethernet connection between the board and my computer.
I have noticed that the packet loss occurs when TCP requests are sent to the board (to process the AJAX method). Not every time but each time there is a data loss it corresponds to the UDP packet which arrives just after the TCP communication. (the one lost is underlined in orange in attachment)
 <<Capture.png>> 
I don't know if there is a problem with the UDP reception buffer or something else. But it seems the UDP thread has enough time to process before another packet arrives.
So if you have any idea of where is the problem or if you have already encountered that kind of problem... I need some help.
Thank you for your time.


Thomas.

Ce courriel (incluant ses eventuelles pieces jointes) peut contenir des informations confidentielles et/ou protegees ou dont la diffusion est restreinte. Si vous avez recu ce courriel par erreur, vous ne devez ni le copier, ni l'utiliser, ni en divulguer le contenu a quiconque. Merci d'en avertir immediatement l'expediteur et d'effacer ce courriel de votre systeme. Astrium decline toute responsabilite en cas de corruption par virus, d'alteration ou de falsification de ce courriel lors de sa transmission par voie electronique.
This email (including any attachments) may contain confidential and/or privileged information or information otherwise protected from disclosure. If you are not the intended recipient, please notify the sender immediately, do not copy this message or any attachments and do not use it for any purpose or disclose its content to any person, but delete this message and any attachments from your system. Astrium disclaims any and all liability if this email transmission was virus corrupted, altered or falsified. 
---------------------------------------------------------------------
Astrium SAS (393 341 516 RCS Paris) - Siege social: 6 rue Laurent Pichat, 75016 Paris, France


More information about the En-Nut-Discussion mailing list