UDP stream not consistent parsed
UDP stream not consistent parsed
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!
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!
-
- Posts: 8926
- Joined: Thu Nov 26, 2015 4:08 am
Re: UDP stream not consistent parsed
Can you post your code?
Re: UDP stream not consistent parsed
Hello
Please find below my source code:
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);
}
-
- Posts: 8926
- Joined: Thu Nov 26, 2015 4:08 am
Re: UDP stream not consistent parsed
Hmm, that looks sane... perhaps disabling power saving (esp_wifi_set_ps(WIFI_PS_NONE)) helps?
Re: UDP stream not consistent parsed
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.
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.
-
- Posts: 8926
- Joined: Thu Nov 26, 2015 4:08 am
Re: UDP stream not consistent parsed
Can you tell if you're dropping packets or merely getting packets late?
Re: UDP stream not consistent parsed
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?
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?
-
- Posts: 8926
- Joined: Thu Nov 26, 2015 4:08 am
Re: UDP stream not consistent parsed
Wait, how does that work? So as the response, you get three identical packets instead of three packets with increasing seq number?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...
Re: UDP stream not consistent parsed
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.
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.
-
- Posts: 8926
- Joined: Thu Nov 26, 2015 4:08 am
Re: UDP stream not consistent parsed
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: Baidu [Spider] and 97 guests