Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethink WiFi API #3027

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Rethink WiFi API #3027

wants to merge 1 commit into from

Conversation

bjoernQ
Copy link
Contributor

@bjoernQ bjoernQ commented Jan 24, 2025

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

This is a POC to address #2224

The idea is

  • network devices / interfaces are independent of the controller - they exist before creating the controller and still exist when the controller is dropped
  • no type-state for the enabled wifi mode - a user can switch the wifi mode at any time

This might or might not end up being merged. For now, it's here to illustrate how the API can or should be changed

Testing

Run the examples

pub async fn start_async(&mut self) -> Result<(), WifiError> {
let mode = WifiMode::try_from(&self.config)?;
if !TAKEN
.compare_exchange(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be swap or fetch_or, which only need a single Ordering and end up in general simpler. In general I don't know if I'm happy with the interface being a completely separate singleton (or singleton pair) - but at the very least, we need an unsafe way to grab them in case they need to be re-created for some reasn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking if the network interfaces (and maybe esp-now, we also might want to add a NAN interface later) should be virtual peripherals but for this first commit in this PoC I didn't want to touch that (and I thought it would be weird but after thinking about it I don't think it's that weird).

Generally, I wanted to illustrate the idea of having the network interfaces/device separated from the controller (and it's life cycle)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it's not clear what these network interfaces are meant to represent. I can create them, then create embassy-net runners, without ever configuring esp-wifi. This is pretty different from any other part of the HAL. The example changes in this PR just make me think the general UX of esp-wifi gets worse. I don't know if you demonstrate switching wifi modes anywhere. Given that is one of the motivators, I would probably appreciate seeing them.

I am fine with keeping the interfaces separate from the controller (as in, the controller returned by wifi::new*), but perhaps we should tie them to esp_wifi::init.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's certainly different - it's a very different thing IMHO and I don't think we really need to make different things look the same

Connecting / disconnecting is pretty much like plugging in / removing an ethernet cable.

A disconnected network interface is really just that - it won't send or receive anything but otherwise doesn't cause any harm

The examples are just changed to compile / work for now - no new examples are added for now - can be done if we can align on the general direction here before (but ofc needed to validate the design)

I am fine with keeping the interfaces separate from the controller (as in, the controller returned by wifi::new*), but perhaps we should tie them to esp_wifi::init.

Sounds reasonable - but would require the network interfaces to get teared down to stop esp-wifi completely? It might be desirable to stop esp-wifi (including the scheduler) for some time and periodically connect to some network to e.g. check for OTA updates or push some MQTT packets (without the whole re-create the network interfaces dance)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable - but would require the network interfaces to get teared down to stop esp-wifi completely? It might be desirable to stop esp-wifi (including the scheduler) for some time and periodically connect to some network to e.g. check for OTA updates or push some MQTT packets (without the whole re-create the network interfaces dance)

Interesting, why would one want to tear down esp_wifi even after turning of WiFi and BL? Maybe there should some ref counting on these resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants