Open FrigoEU opened 2 hours ago
A quick googling reveals this C ESP IDF example which should be your starting point, and seems to do exactly what you want: https://github.com/espressif/esp-idf/tree/release/v5.2/examples/network/bridge
Informally speaking, how it operates is as follows:
EspNetif
in Rust-speak) and "assigns" to this bridge all N ethernet netifs + the optional Wifi AP netif. Apparently, this is something new in ESP IDF 5. ESP IDF 4.4 did not support layer-2 bridging, only layer3 IP packet forwarding (which is still supported in the esp-idf-*
crates btw)
How to do it in Rust?
EspEth
instances (these are a combination of phy (EthDriver
) + netif (EspNetif
). For their netifs, use a custom NetworkConfiguration
, so that you can assign a different netif key and different distance to each ethernet netif. In each ethernet EspEth
instance, you need to set the same Ethernet Mac address, as per the example. There is a public API for that, I think, otherwise unsafely call into esp_idf_svc::sys::esp_eth_ioctl
as per the exampleEspWifi
(a combination of phy WifiDriver
+ netif EspNetif
), and set it in AP mode, as usualNow the non-trivial part:
Once the above laborious excercise is done, you need to create - as per the C example - an extra netif, and configure it as a bridge. The configuration currently cannot be 100% done with safe Rust calls, because the ESP IDF bridge APIs are not yet exposed in a safe manner in esp-idf-svc
(as in the esp_netif_br_*
structs and glue functions). Until this is available in Rust, you can just do it with unsafe calls into esp_idf_svc::sys::*
.
Once you have this, I would appreciate if you publish it as I can use it as a template to expose the bridge APIs in a safe way in esp-idf-svc
.
The bridge configuration stuff in the example starts from here. All above (ethernet and wifi conf) can be done with safe Rust.
Hope that helps.
Hi,
This isn't an issue but rather a request for a nudge in the right direction. I've made a fairly large application in Rust running on the ESP32. So far it's been fairly smooth sailing. But the next feature I'd like to build is to me quite difficult to get started on.
The situation: my ESP32 will be plugged into Ethernet. When connection is successful (and it's configured as such) it should start a WiFi access point (with pre-configured ssid/password) and allow another device to connect to the WiFi and connect to the internet via the ESP32's Ethernet connection. I feel in theory this should be possible but I've found only very limited information/examples online (especially in the Rust language).
I'd greatly appreciate it if somebody could point me in the right direction to get started on this.
Simon