Latency between data frames in wifi communication

Thread Starter

Fripr

Joined Jul 22, 2023
7
I record a timestamp everytime I receive a data frame in udp between an ESP8266ex and an ESP32 such that :

C:
if (packetSize) {
   frame_size = UDP.read(buffer_t, 30);
   if (frame_size > 0) {
      timestamp_receive = micros();
      data_adc_serial[10] = timestamp_receive;
      for (int i = 0; i < 10; i++) {
         data_adc_serial[i] = (buffer_t[i*2+1] << 8) | buffer_t[i*2];
      }
      for(int i = 0; i <= 10; i++) {
         Serial.print(data_adc_serial[i]);
         Serial.print(",");
      }
      Serial.print('\n');
   }
}
Frames are supposed to arrive every 5ms, but the difference in consecutive timestamp_receive values (i.e. the delay between the reception of 2 frames) is such that : 0.5 ms,10.5 ms,0.5 ms,10.5ms and so on throughout the recording.

Here are the first points obtained:

Capture d'écran 2024-03-20 091323.png


Antennas are located close together (<1m).

In the end, over a long period of time, the loss of data due to delay is about 1-2%, but I'm not sure about this behavior.
 

BobTPH

Joined Jun 5, 2013
9,182
There is no guarantee of the latency of any packet transmission. If you are trying to use that for synchronization, it is a fool’s errand.

I would love to see a solution for synchronization via a WIFI network, because I need that for one of my projects and have not come up with a solution.
 

nsaspook

Joined Aug 27, 2009
13,443
There are possibilities for improvement in general. Most of the problems can be reduced by making the entire process more 'realtime' on both ends.
https://medium.com/@deryugin.denis/reducing-udp-latency-ce60d98c7bff

The Esp32 series doesn't have a good reputation for excellence in most areas other than cost.

A quick search of possible solutions.
https://github.com/espressif/arduino-esp32/issues/1317
https://forum.arduino.cc/t/esp32-wifi-udp-bunching-packets/1162055
https://esp32.com/viewtopic.php?t=27665
 

ApacheKid

Joined Jan 12, 2015
1,660
I record a timestamp everytime I receive a data frame in udp between an ESP8266ex and an ESP32 such that :

C:
if (packetSize) {
   frame_size = UDP.read(buffer_t, 30);
   if (frame_size > 0) {
      timestamp_receive = micros();
      data_adc_serial[10] = timestamp_receive;
      for (int i = 0; i < 10; i++) {
         data_adc_serial[i] = (buffer_t[i*2+1] << 8) | buffer_t[i*2];
      }
      for(int i = 0; i <= 10; i++) {
         Serial.print(data_adc_serial[i]);
         Serial.print(",");
      }
      Serial.print('\n');
   }
}
Frames are supposed to arrive every 5ms, but the difference in consecutive timestamp_receive values (i.e. the delay between the reception of 2 frames) is such that : 0.5 ms,10.5 ms,0.5 ms,10.5ms and so on throughout the recording.

Here are the first points obtained:

View attachment 317976


Antennas are located close together (<1m).

In the end, over a long period of time, the loss of data due to delay is about 1-2%, but I'm not sure about this behavior. Also how confident are you that the timestamp is regular, stable?
UDP is not synchronous, there's no basis for expecting anything to happen every 5ms. Also how confident are you the your timestamp is solid? If the state of the timestamp depends on CPU workload and other factors, that will skew your data findings. I learned many years ago that getting a timestamp, itself takes time (not always significant, but sometimes).
 
Last edited:

nsaspook

Joined Aug 27, 2009
13,443
UDP is not synchronous, there's no basis for expecting anything to happen every 5ms. Also how confident are you the your timestamp is solid?
Correct but that said, WiFi UDP is really horrible so the OP numbers are not too bad.

Some local ping data.
root@hpdesk:/ldrv/IH2Azzurra# ping -p 5000 10.1.1.100
PATTERN: 0x5000
PING 10.1.1.100 (10.1.1.100) 56(84) bytes of data.
64 bytes from 10.1.1.100: icmp_seq=1 ttl=64 time=0.278 ms
64 bytes from 10.1.1.100: icmp_seq=2 ttl=64 time=0.271 ms
64 bytes from 10.1.1.100: icmp_seq=3 ttl=64 time=0.239 ms
^C
--- 10.1.1.100 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2028ms
rtt min/avg/max/mdev = 0.239/0.262/0.278/0.017 ms
root@hpdesk:/ldrv/IH2Azzurra# ping -p 5000 10.1.1.69
PATTERN: 0x5000
PING 10.1.1.69 (10.1.1.69) 56(84) bytes of data.
64 bytes from 10.1.1.69: icmp_seq=1 ttl=64 time=52.6 ms
64 bytes from 10.1.1.69: icmp_seq=2 ttl=64 time=74.2 ms
64 bytes from 10.1.1.69: icmp_seq=3 ttl=64 time=199 ms
^C
--- 10.1.1.69 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 52.569/108.433/198.551/64.330 ms
root@hpdesk:/ldrv/IH2Azzurra# ping -p 5000 10.1.1.225
PATTERN: 0x5000
PING 10.1.1.225 (10.1.1.225) 56(84) bytes of data.
64 bytes from 10.1.1.225: icmp_seq=1 ttl=64 time=322 ms
64 bytes from 10.1.1.225: icmp_seq=2 ttl=64 time=105 ms
64 bytes from 10.1.1.225: icmp_seq=3 ttl=64 time=35.3 ms
^C
--- 10.1.1.225 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 35.339/154.158/322.341/122.256 ms
10.1.1.100 between 10G wired Linux servers

My home IPV6/IPV4 wireless bridge
1710944081875.png
10.1.1.69 Apple iphone
10.1.1.225 Android phone
 

Thread Starter

Fripr

Joined Jul 22, 2023
7
UDP is not synchronous, there's no basis for expecting anything to happen every 5ms. Also how confident are you the your timestamp is solid? If the state of the timestamp depends on CPU workload and other factors, that will skew your data findings.
Thank you for your responses.
I record a timestamp at the sending of the data frame, and the sending is made every 5ms by a timer. The timestamps of the sender are good, so I presume it's the receiver that's the problem.
 

Thread Starter

Fripr

Joined Jul 22, 2023
7
Correct but that said, WiFi UDP is really horrible.

Some local ping data.


10.1.1.100 between 10G wired Linux servers

My home IPV6/IPV4 wireless bridge
View attachment 317990
10.1.1.69 Apple iphone
10.1.1.225 Android phone
Do you have any idea if there are any UDP libraries for arduino IDE (ESP8266EX and ESP32) that are more efficient than others? I currently use 'Wifi' and 'WifiUdp' librairies.

Do you recommend using another protocol? TCP?
 

ApacheKid

Joined Jan 12, 2015
1,660
Correct but that said, WiFi UDP is really horrible so the OP numbers are not too bad.

Some local ping data.


10.1.1.100 between 10G wired Linux servers

My home IPV6/IPV4 wireless bridge
View attachment 317990
10.1.1.69 Apple iphone
10.1.1.225 Android phone
Not good, but pity me. I use a T-Mobile 5G service and man, sometimes its up for several days the other times it's up/down multiple times per hour.
 

nsaspook

Joined Aug 27, 2009
13,443
Do you have any idea if there are any UDP libraries for arduino IDE (ESP8266EX and ESP32) that are more efficient than others? I currently use 'Wifi' and 'WifiUdp' librairies.

Do you recommend using another protocol? TCP?
No idea about the arduino IDE as I don't use it.

Don't know exactly what your application is but TCP is usually slower with more latency under the same conditions.

root@hpdesk:/ldrv/IH2Azzurra# netperf -H 10.1.1.100 -l 30 -t TCP_STREAM
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.1.1.100 () port 0 AF_INET : demo
Recv Send Send
Socket Socket Message Elapsed
Size Size Size Time Throughput
bytes bytes bytes secs. 10^6bits/sec

131072 16384 16384 30.02 933.69
root@hpdesk:/ldrv/IH2Azzurra# netperf -H 10.1.1.100 -t TCP_RR -- -o min_latency,max_latency,mean_latency
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 10.1.1.100 () port 0 AF_INET : demo : first burst 0
Minimum Latency Microseconds,Maximum Latency Microseconds,Mean Latency Microseconds
76,1856,249.06
 

nsaspook

Joined Aug 27, 2009
13,443
Do you have any idea if there are any UDP libraries for arduino IDE (ESP8266EX and ESP32) that are more efficient than others? I currently use 'Wifi' and 'WifiUdp' librairies.

Do you recommend using another protocol? TCP?
See if you can get better actual packet arrival timing using a promiscuous mode callback for the timestamp.
https://docs.espressif.com/projects..._set_promiscuous_rx_cb21wifi_promiscuous_cb_t

https://www.techtarget.com/searchsecurity/definition/promiscuous-mode
 
Top