Closed Sycrosity closed 1 month ago
As you mentioned, this is because there isn't a DHCP server available in smoltcp. @bjoernQ wrote a simple one in an experiment last year: https://github.com/bjoernQ/esp32c3-dhcp-experiment/blob/0a9432c4a348fce9360006c8dab99b7e4d21de69/dhcp-experiment/src/main.rs#L218 which may be helpful as a starting point. Getting something like that upstreamed into smoltcp (and I already know they want it, I've seen on matrix) would be the way to solve this.
I've found a lot of utility in the C/C++ ESP implementations. But the C/C++ implementations don't follow SOLID principles which are paramount for Rust.
To decouple responsibility, there should be a rust struct that focuses on providing an access point (not a generic thing that can be both a server or a client).
As stated above, the ESP Wifi AP struct shouldn't be responsible for DHCP. Instead, the Wifi AP struct should provide an interface to service connections.
As stated above, the ESP Wifi AP struct shouldn't be responsible for DHCP. Instead, the Wifi AP struct should provide an interface to service connections.
I think you misunderstood me, I'm saying the exact same thing. This should be a socket type in smoltcp, and nothing to do with esp-wifi's AP at all.
I've made easy to use dhcp server for embassy (dhcp packet parsing based on edge-dhcp crate). Tested it on esp32-s3 (with android phone). Look at example
dir for implementation.
As you mentioned, this is because there isn't a DHCP server available in smoltcp. @bjoernQ wrote a simple one in an experiment last year: https://github.com/bjoernQ/esp32c3-dhcp-experiment/blob/0a9432c4a348fce9360006c8dab99b7e4d21de69/dhcp-experiment/src/main.rs#L218 which may be helpful as a starting point. Getting something like that upstreamed into smoltcp (and I already know they want it, I've seen on matrix) would be the way to solve this.
Having implemented one myself following @bjoernQ's example using smoltcp wire dhcp structs (mostly for fun but also to see how it would be to implement a dhcp server into smoltcp) this does seem to not really be an issue in esp-hal, but regardless would seem to be the expected outcome when running an AP server (or at least in my eyes - although others may have different uses for APs that don't require DHCP provisioning), or at least something which could be put in an example. Should there be an issue for adding an example dhcp server, at least until smoltcp upstreams a dhcp server? Not sure on this one.
this does seem to not really be an issue in esp-hal
I agree.
Should there be an issue for adding an example dhcp server, at least until smoltcp upstreams a dhcp server
Imo, no, we should at the very least file an issue under smoltcp though and referencing some external projects that use smoltcp to create one would be a good idea.
Closing this for now.
Currently, to my knowledge there is no way to automatically provision IP addresses while in AP mode, with the
wifi_(embassy_)_access_point
examples prompting the user to set their IP address to a value in the ip range. A method of provisioning these (ideally through DHCP) would be useful in making the esp-wifi AP experience a bit more natural.At the same time, this could also solve (although this should maybe be a seperate issue) the seemingly unexpected behaviour of setting
embassy-net::Config
(and the mostly equivalentesp_wifi::wifi::ipv4::ClientConfiguration
) settings for wifi when in AP mode - as the respective DHCP variants of these either do not work or cause no connections to be possible when in AP mode and don't cause any compile or runtime errors.In the meantime, what would be the best way to go around implementing a pseudo DHCP server for AP mode? Having looked into the smoltcp dhcp socket, I cannot work out how to add this into an wifi AP instance (since we do not have access to the internals of
embassy_net::StackResources
orsmoltcp::SocketStorage
).