-
Notifications
You must be signed in to change notification settings - Fork 227
Wifi scan process redesign #186
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
Conversation
|
But |
|
I think this PRs intention is that Personally, I think it would be better to expose the scanning API via async and keep the current blocking api the same, and it's actually something we want for esp-wifi. (Sorry if I've missed these traits somewhere, but I looked through embedded-svc and didn't see any). |
|
I thought this could be a first step to async/await.
Or in general, what's the idea to make the whole esp wifi async? |
But that's the point: How the async story goes so far for everything
@teamplayer3 ^^^ |
|
@zRedShift ^^^ pinging you as you also had a stake in the "async" scan, if I remember correctly. |
|
And |
|
@ivmarkov my concern of exposing the |
As long as it does not crash, I don't think this is a problem. And this memory should be free-d when the wifi driver is dropped anyway. |
|
I'm currently using a fork with some modifications and calls to |
Don't want to sound stubborn, but the sync implementation is already there - So @teamplayer3 if you can:
... we might have a great start. Truly async-ifying the above is kind of trivial and probably an optional next step, as listening to Wifi events in an async way is already implemented of course. |
|
@teamplayer3 I must say, code looks quite OK!
@MabezDev @zRedShift What do you think?
|
src/wifi.rs
Outdated
| &mut self, | ||
| scan_config: &config::ScanConfig, | ||
| ) -> Result<(heapless::Vec<AccessPointInfo, N>, usize), EspError> { | ||
| ) -> Result<heapless::Vec<AccessPointInfo, N>, EspError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usize was there for a reason: to indicate to you that you've fetched potentially less number of aps than found. I'm not sure we want to get rid of it.
Moreover, you've removed it from some signatures, but kept it in others. Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, you've removed it from some signatures, but kept it in others. Why?
I didn't removed it from the trait signatures because I agree with you to don't change the public API at this point.
Ah the returned size should be the found count. Ok, makes sense. I change it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usize was there for a reason: to indicate to you that you've fetched potentially less number of aps than found. I'm not sure we want to get rid of it.
Doesn't heapless essentially encode this information already? len() being the number of results actually found, N or capacity() being the max you could search for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't heapless essentially encode this information already? len() being the number of results actually found, N or capacity() being the max you could search for?
It isn't restricted by N how many the esp searches. It searches always all (dynamically allocated on the heap intern). The usize gives how many are found. And the heapless len() how many are fetched. If N is larger than the amount of found aps len() is the same as usize. If N is smaller than the amount of found aps usize tells the user how many could be fetched.
I will test if it's possible to fetch the remaining aps if not all are fetched at first.
src/wifi.rs
Outdated
| pub fn get_scan_result_n<const N: usize>( | ||
| &mut self, | ||
| ) -> Result<(heapless::Vec<AccessPointInfo, N>, usize), EspError> { | ||
| ) -> Result<heapless::Vec<AccessPointInfo, N>, EspError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
|
@teamplayer3 Let's proceed with my suggestion, and fold back the |
Scanning for access points is completely blocking implemented. To make it more async compatible, I think the scan process should be divided into start scan and get scan results and listen for the wifi scan done event.
To make it memory save, I wrapped the process into a
ScanProcessstruct. This mimics the style ofWifiWait.A
ScanProcesscan be used as follows:New functions
scan_start()andget_scan_result()are private and must be used throughScanProcess::scan().While implementing these changes, I added the
ScanConfigto configure the scan process.I didn't change the currently available scan function on the driver. The new implemented functions can be fused with them.
I implemented a public
set_mode()function to set the wifi mode manual. This should be automated, but for now, it's manual to configure for scanning. I thought of a state tracking by types as generics for the WifiDriver to switch from config state to started state.I'm open for discussion.