After realising the need for faster data transfer, we started looking at the ESP32 and the various protocols it supports. Although using layer 4 protocols like TCP or UDP is possible, the overheads of handling connections to an ad-hoc network could be problematic. We thus examined ESP-NOW, a protocol defined by Espressif which sends data over raw 802.11 packets directly without the need for devices to be on the same WLAN network.
Code was written to test the effects of the following parameters on the throughput of ESP-NOW:
- Wi-Fi Data Rate
- Broadcast or Unicast:
- Sending packets directly to a peer identified by their MAC address results in the peer sending an Acknowledgement packet back
- Broadcasting packets (send to MAC FF:FF:FF:FF:FF:FF) will not cause Acknowledgement packets to be sent, potentially speeding up transfer.
The test code transmits 250 byte (maximum supported packet length) ESP-NOW packets as fast as possible from a device (henceforth the master) to another device (henceforth the slave) for 3 seconds, sleeps for 10 seconds, then repeats.
The slave device then transmits the number of packets received at 1 second intervals back to the master device, which then prints out this number.
The following data rates have been observed between two ESP32-DevKitC’s approximately 1m apart in a standard household environment (ie with Wi-Fi interference):
Transmission Type | Wi-Fi Data Rate | Max Throughput Observed (bytes) in 1s |
---|---|---|
Unicast | WIFI_PHY_RATE_1M_L |
89250 |
Broadcast | WIFI_PHY_RATE_1M_L |
101000 |
Unicast | WIFI_PHY_RATE_11M_L |
349250 |
Broadcast | WIFI_PHY_RATE_11M_L |
497000 |
Unicast | WIFI_PHY_RATE_54M |
778500 |
Broadcast | WIFI_PHY_RATE_54M |
963000 |
Unicast | WIFI_PHY_RATE_MCS0_LGI |
442000 |
Broadcast | WIFI_PHY_RATE_MCS0_LGI |
502250 |
Unicast | WIFI_PHY_RATE_MCS4_LGI |
756750 |
Broadcast | WIFI_PHY_RATE_MCS4_LGI |
930750 |
Unicast | WIFI_PHY_RATE_MCS7_LGI |
224750 |
Broadcast | WIFI_PHY_RATE_MCS7_LGI |
706250 |
Unicast | WIFI_PHY_RATE_MCS0_SGI |
464750 |
Broadcast | WIFI_PHY_RATE_MCS0_SGI |
535000 |
Unicast | WIFI_PHY_RATE_MCS4_SGI |
771750 |
Broadcast | WIFI_PHY_RATE_MCS4_SGI |
945250 |
Unicast | WIFI_PHY_RATE_MCS7_SGI |
734250 |
Broadcast | WIFI_PHY_RATE_MCS7_SGI |
833500 |
We can observe that sending broadcast instead of unicast packets speeds up data transmissions slightly. Increasing the Wi-Fi bit rate also has a significant impact on data rates, but comes at the cost of significantly more packet loss (packets not acknowledged by peer).
Quick testing in outdoor conditions (ESP32-DevKitC placed at a distance of 20m with line-of-sight visibility) shows similar (or slight better) data rates at WIFI_PHY_RATE_1M_L
and WIFI_PHY_RATE_11M_L
when compared to the results above. Data rates of up to 549250 bytes/s were observed at WIFI_PHY_RATE_24M
. Almost all packets were lost at WIFI_PHY_RATE_54M
.
12 bit data sampled at 80Hz results in 553Mbit or 70875 kbyte of data, which would take approximate 145s to transmit at 500000 bytes/s.
These data rates were also observed using the on-board PCB antenna. An alternative option is to connect an external antenna to ESP32-WROOM-32U modules, which is likely to improve the data rate.