UDP stream not consistent parsed

nonkeldw
Posts: 6
Joined: Fri Jul 31, 2020 5:50 pm

UDP stream not consistent parsed

Postby nonkeldw » Fri Jul 31, 2020 5:53 pm

Hello Forumuser
I’m currently new to ESP32, this is also my first application that I made, I use the IDF environments from Esspressif.
A little overview of my application, I run 2 tasks, 1 task print the RSSI with a printf, the other task opens a UDP socket and try to process the incoming data. If the application finds valid data I toggle a LED, now when I run the same code (LwIP stuff on a STM32) the LED is consistent toggling when I do this on ESP32, it is more a lightshow than toggling consistently… What are the hidden tricks to make it more stable and improve the performants.

Thanks!

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

Re: UDP stream not consistent parsed

Postby ESP_Sprite » Sat Aug 01, 2020 7:38 am

Can you post your code?

nonkeldw
Posts: 6
Joined: Fri Jul 31, 2020 5:50 pm

Re: UDP stream not consistent parsed

Postby nonkeldw » Sat Aug 01, 2020 10:06 am

Hello

Please find below my source code:

Code: Select all

	static unsigned char rx_buffer[2024];
	unsigned char level =1;
	int opcode;
	//unsigned char addr_str[128];
    while(1){
    	socklen_t socketaddrsize;
    	struct sockaddr_in dest_addr, remotehost;
    	dest_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    	dest_addr.sin_family = AF_INET;
    	dest_addr.sin_port = htons(PORT);
    	remotehost.sin_family = AF_INET;
    	remotehost.sin_port = htons(PORT);
    	socketaddrsize = sizeof(remotehost);
    	remotehost.sin_addr.s_addr = htonl(INADDR_BROADCAST);
		int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
    	int ret = -1;
    	if(sock > 0 ){
    		printf("Socket oke! \r\n");
    		int err = bind(sock, (struct sockaddr*)&dest_addr, sizeof(dest_addr));
    	    	if(err == 0){
    	    		printf("Bind ok \r\n");
    	    		while(1){
    	    			//ret = recv(sock, rx_buffer,sizeof(rx_buffer), 0);
    	    			ret  = recvfrom(sock, rx_buffer, sizeof(rx_buffer), 0, (struct sockaddr *)&remotehost, &socketaddrsize);

    	    			if(ret > 0){
    	    				if(strncmp((char *)rx_buffer, "Art-Net",7) == 0){
    	    					opcode = ((rx_buffer[9]<<8)|rx_buffer[10]);
    	    					switch(opcode){
    	    					case 0x5000:
    	        	    			level = !level;
    	        	    			gpio_set_level(GPIO_NUM_2, level);
    	    						break;
    	    					}
    	    				}
    	    		

    	    			}
    	    	}
    	    	printf("Unable to bind socket: %d \r\n", err);
    	}
    	close(sock);			// Opkuisen die handel
    	printf("Unable to create socket: %d \r\n", sock);
    	vTaskDelay(500 / portTICK_PERIOD_MS);
    }

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

Re: UDP stream not consistent parsed

Postby ESP_Sprite » Sun Aug 02, 2020 10:09 am

Hmm, that looks sane... perhaps disabling power saving (esp_wifi_set_ps(WIFI_PS_NONE)) helps?

nonkeldw
Posts: 6
Joined: Fri Jul 31, 2020 5:50 pm

Re: UDP stream not consistent parsed

Postby nonkeldw » Sun Aug 02, 2020 10:38 am

Hello

Thanks for the reply.
I changed this, without any success!
I changed also this:
Optimization level: Release
WiFi IRAM optimization enabled
UDP mailbox size: 64
FreeRTOS tick rate: 1000
Layer 2 to layer 3 copy enabled

But it is not yet stable.

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

Re: UDP stream not consistent parsed

Postby ESP_Sprite » Sun Aug 02, 2020 1:41 pm

Can you tell if you're dropping packets or merely getting packets late?

nonkeldw
Posts: 6
Joined: Fri Jul 31, 2020 5:50 pm

Re: UDP stream not consistent parsed

Postby nonkeldw » Sun Aug 02, 2020 4:51 pm

Hello

My testsetup: Wireshark, on the PC.
After every received packet (where i toggle the LED) i answer with "Hello world" and een sequence number.
The ESP answer sometimes not on a received packet , but not mediate after receiving... for example i received 3 of 4 or 5 packets then the ESP answer on the 3-4-5 packets... but, with the same sequence number...
I think that's what you mean with "merely getting packets late"?

See below the "vTaskGetRunTimeStats"...

IDLE0 38536271 47%
IDLE1 160336516 49%
main 32571 <1%
tiT 63378 <1%
Tmr Svc 31 <1%
ipc0 4380 <1%
ArtNetReceiver 79842 <1%
wifi 1497135 1%
esp_timer 42387 <1%
ipc1 34709 <1%
sys_evt 10266 <1%

There is no task that consumed to much time, i think?

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

Re: UDP stream not consistent parsed

Postby ESP_Sprite » Mon Aug 03, 2020 8:53 am

for example i received 3 of 4 or 5 packets then the ESP answer on the 3-4-5 packets... but, with the same sequence number...
Wait, how does that work? So as the response, you get three identical packets instead of three packets with increasing seq number?

nonkeldw
Posts: 6
Joined: Fri Jul 31, 2020 5:50 pm

Re: UDP stream not consistent parsed

Postby nonkeldw » Mon Aug 03, 2020 12:36 pm

Yes, that's correct.
I use the sequence number from the broadcast packet.
I print also this sequence number in the terminal.. there increase the number every time there is a packet received.

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

Re: UDP stream not consistent parsed

Postby ESP_Sprite » Tue Aug 04, 2020 7:45 am

Is there any chance you can upload the software somewhere so I can check on an ESP32 here? (No need to clean up any Dutch/Flemish comments, I can read them :) )

Who is online

Users browsing this forum: josephhui and 16 guests