Bursty UDP traffic from ESP32-C3

ihabawad
Posts: 9
Joined: Sat Mar 28, 2020 5:07 pm

Bursty UDP traffic from ESP32-C3

Postby ihabawad » Sun Aug 13, 2023 1:57 am

Greetings! I am using an ESP32-C3 with the attached short ESP32 Arduino program, which is a minimal repro of my application.

I expect that the program should send one packet every 50 ms. What I see, running Wireshark on a computer on the same Wi-Fi network, is that the traffic is "bursty".

Attached is a sample of the inter-packet delays, on a linear and a logarithmic scale.

* On the linear scale below, you can see that, on average, something happens every 200 ms to deliver a "burst" of packets.
receive-times-linear.png
receive-times-linear.png (26.1 KiB) Viewed 1913 times
* On the logarithmic scale below, you can see the actual distribution of the packets that arrive almost "simultaneously" with the previous ones.
receive-times-logarithmic.png
receive-times-logarithmic.png (28.3 KiB) Viewed 1913 times
Proper timing is important for my application. The receiving end is not an ESP32.

Is there an explanation for this? Is there something that can help?

Ihab Awad
Attachments
test_wifi_esp32.zip
(2.34 KiB) Downloaded 186 times

ihabawad
Posts: 9
Joined: Sat Mar 28, 2020 5:07 pm

Re: Bursty UDP traffic from ESP32-C3

Postby ihabawad » Wed Aug 16, 2023 2:56 am

Greetings again folks,

I have rewritten my example using ESP-IDF -- without Arduino -- and had the same results. Below is the logarithmic plot of inter-packet times. I have also attached a ZIP file of my code. The main section of code is also below.

This is a critical issue for my application. I am surprised this is the behavior.

Ihab

Code: Select all

      struct addrinfo hints = {
	.ai_flags = AI_PASSIVE,
	.ai_socktype = SOCK_DGRAM,
      };
      
      struct addrinfo *res;
      hints.ai_family = AF_INET; // For an IPv4 socket
      err = getaddrinfo(EXAMPLE_MULTICAST_IPV4_ADDR,
			NULL,
			&hints,
			&res);
      if (err < 0) {
	ESP_LOGE(TAG, "getaddrinfo() failed for IPV4 destination address. error: %d", err);
	break;
      }
      
      if (res == 0) {
	ESP_LOGE(TAG, "getaddrinfo() did not return any addresses");
	break;
      }

      ((struct sockaddr_in *)res->ai_addr)->sin_port = htons(UDP_PORT);
      inet_ntoa_r(((struct sockaddr_in *)res->ai_addr)->sin_addr, addrbuf, sizeof(addrbuf)-1);
      ESP_LOGI(TAG, "Sending to IPV4 multicast address %s:%d...",  addrbuf, UDP_PORT);

      err = sendto(sock, sendbuf, len, 0, res->ai_addr, res->ai_addrlen);
      
      freeaddrinfo(res);
      
      if (err < 0) {
	ESP_LOGE(TAG, "IPV4 sendto failed. errno: %d", errno);
	break;
      }
      
      vTaskDelay(50 / portTICK_PERIOD_MS);
log-esp-idf.png
log-esp-idf.png (40.52 KiB) Viewed 1753 times
Attachments
probe_idf.zip
(29.42 KiB) Downloaded 264 times

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

Re: Bursty UDP traffic from ESP32-C3

Postby ESP_Sprite » Wed Aug 16, 2023 7:04 am

Have you disabled wifi power saving?

Code: Select all

esp_wifi_set_ps(WIFI_PS_NONE);

ihabawad
Posts: 9
Joined: Sat Mar 28, 2020 5:07 pm

Re: Bursty UDP traffic from ESP32-C3

Postby ihabawad » Thu Aug 17, 2023 1:45 am

I just tried it --

Code: Select all

  ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
  ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
  ESP_ERROR_CHECK(esp_wifi_start());

  ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
The result is as below. No difference.

Ihab
without-powersave-log.png
without-powersave-log.png (29.58 KiB) Viewed 1698 times

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

Re: Bursty UDP traffic from ESP32-C3

Postby ESP_Sprite » Thu Aug 17, 2023 2:11 am

Any chance that other traffic on the channel is interfering? WiFi is a shared medium, and when the airwaves are occupied transmitters tend to back off and resend later.

ihabawad
Posts: 9
Joined: Sat Mar 28, 2020 5:07 pm

Re: Bursty UDP traffic from ESP32-C3

Postby ihabawad » Thu Aug 17, 2023 2:15 am

Well, I'm at home with my home Wi-Fi and perhaps other people's as well. Huh. Ok, let me see if I can get some time in the RF chamber at work and I'll report back.

Ihab

ihabawad
Posts: 9
Joined: Sat Mar 28, 2020 5:07 pm

Re: Bursty UDP traffic from ESP32-C3

Postby ihabawad » Thu Aug 17, 2023 4:48 pm

I tried some more experiments and found that the behavior is to some extent dependent on the receiving Wi-Fi adapter. I tried receiving the UDP packets on my laptop using the built-in adapter versus a USB Wi-Fi dongle, and in some cases (though the results were inconsistent), I received properly spaced UDP packets.

I then returned to basics. I added

Code: Select all

esp_wifi_set_ps(WIFI_PS_NONE)
to my actual Arduino code, and tried it out along with my Raspberry Pi CM4 receiving unit, for my actual application. This seemed to provide adequate response times.

As a result, I'm going to consider this issue solved for now, and see if I can address it systematically later. If it recurs, I will re-post here with what I have learned.

Thank you,

Ihab Awad

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

Re: Bursty UDP traffic from ESP32-C3

Postby ESP_Sprite » Fri Aug 18, 2023 4:49 am

Good to hear you put this to bed for now; thanks for keeping us updated!

Who is online

Users browsing this forum: No registered users and 52 guests