Page 1 of 2
UDP stream not consistent parsed
Posted: Fri Jul 31, 2020 5:53 pm
by nonkeldw
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!
Re: UDP stream not consistent parsed
Posted: Sat Aug 01, 2020 7:38 am
by ESP_Sprite
Can you post your code?
Re: UDP stream not consistent parsed
Posted: Sat Aug 01, 2020 10:06 am
by nonkeldw
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);
}
Re: UDP stream not consistent parsed
Posted: Sun Aug 02, 2020 10:09 am
by ESP_Sprite
Hmm, that looks sane... perhaps disabling power saving (esp_wifi_set_ps(WIFI_PS_NONE)) helps?
Re: UDP stream not consistent parsed
Posted: Sun Aug 02, 2020 10:38 am
by nonkeldw
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.
Re: UDP stream not consistent parsed
Posted: Sun Aug 02, 2020 1:41 pm
by ESP_Sprite
Can you tell if you're dropping packets or merely getting packets late?
Re: UDP stream not consistent parsed
Posted: Sun Aug 02, 2020 4:51 pm
by nonkeldw
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?
Re: UDP stream not consistent parsed
Posted: Mon Aug 03, 2020 8:53 am
by ESP_Sprite
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?
Re: UDP stream not consistent parsed
Posted: Mon Aug 03, 2020 12:36 pm
by nonkeldw
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.
Re: UDP stream not consistent parsed
Posted: Tue Aug 04, 2020 7:45 am
by ESP_Sprite
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
)