owenthewizard

ESP32 Wi-Fi to Ethernet Bridge, Written in Rust

I've been working on a Wi-Fi to Ethernet bridge targeting the ESP32. It's basically the opposite of an Access Point; it connects an Ethernet client device to a Wi-Fi network. I already have a project that does the same* on Raspberry Pi, but I always thought a whole OS was a bit bloated for some relatively simple network bridging.

Goals

You might be wondering about that asterisk. rpi-wifi-bridge aims to provide a minimal buildroot environment to run parprouted and dhcp-relay. While it tries to function similarly to a transparent Layer 2 bridge, it's not quite. I've always thought a microcontroller would be ideal for this task. 802.3 and 802.11 frames aren't too different. Forget running a whole OS; just do some logic to translate the frames, and you should be good to go.

You can even make this Layer 2 bridge """transparent""" (at least to the rest of the network) by modifying the frame MAC addresses. No need to concern dhcp-relay, mdns-repeater, or anything else.

Implementation

With this in mind, esp32-wifi-bridge eschews Linux for FreeRTOS (via ESP-IDF) and implements the following logic:

  • Clone the client device Ethernet MAC address to the ESP32 Wi-Fi interface.
  • Set the ESP32 Ethernet to promiscuous mode.
  • Send frames received on Ethernet to Wi-Fi and vice-versa.

ESP-IDF handles the frame translation logic for us automatically. Neat!

Throughput

I've been testing using the Wireless-Tag WT32-ETH01, a standard ESP32-WROOM-based development board with LAN8720 built-in. It can hit 50 Mbps, but the limits of 520 KB of RAM become apparent as you increase the size and number of Wi-Fi and Ethernet buffers. Nevertheless, quite impressive for a <$10 board!

I suspect that boards using ESP32-WROVER like the Lilygo T-ETH-Lite could have higher throughput thanks to the PSRAM.

I didn't take any latency measurements, but I'd say it's plenty bearable for web browsing.

Future Work

Baremetal

It would be an interesting challenge to port this to a baremetal ESP32 environment instead of ESP-IDF. While there is Wi-Fi on baremetal ESP32, I'm not aware of an RMII Ethernet implementation.

Hardware

I wonder if it would be worth doing the frame translation in hardware. Another chip like the ESP32-C3 could manage the Wi-Fi connection, and simply send the frames to another IC for translation and then on to an Ethernet controller. In practice, I think you'd need something more powerful than an ESP32 to really take advantage of this.