-
Notifications
You must be signed in to change notification settings - Fork 3k
Extend and rework WiFi interface #2627
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
customer wanted the method to scan_ssid to find available networks. I would make it simple, return a list of found networks, which can be empty if error happened. this method should be added at same time as this rss and state methods |
OK, will add it now then. |
de2c44d
to
7b4d948
Compare
scan added. I would say we are still missing some basic functionality like using static IP (not DHCP), but that would require changing underlying NetworkInterface (we really should have it for Ethernet as well) which may not fit the current time scales. Something to remember about. |
09e0f10
to
984424e
Compare
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error | ||
* see @a nsapi_error | ||
*/ | ||
virtual int scan(wifi_ap_t *res, unsigned count) = 0; |
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.
this might be problematic api for application. Only way is to estimate how many networks there might be available, but still you might get just partial list of ssid's. It would be more usefull and also memory friendly if you could get one by one result, or if this api allow to skip N results...
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.
I am +1 for this solution. It is simple and should work for most use cases.
Correct me if I am wrong, but alternatives would require implicit memory allocation for devices that return all results in a single query (I believe the ESP8266 for one).
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.
This is not yet implemented to esp8266-driver, or is it ? I just look at quickly AT command which give you list of access points, and it depend how implement will be done that is it possible to get one by one those results easily or not. At least ESP8266 give you whole list of access points so you have to reserve memory for all of them dynamically before returning back.. but it probably would be much faster if you could get results one by one as soon as you get result from wifi chip.. there is cons and prons in both ways..
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.
I'm moving ESP implementation together with this API https://github.com/bulislaw/esp8266-driver/tree/feature_wifi
There's no way of getting it one by one really, the async api call the callback between paring next entry.
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.
async api looks good alternative solution which do the trick "I wanted" 👍 . I think this sync API is good enough for now.
there is the problem of blocking call for scan and connect. If those are changed to be event based, then the scan could return SSIDs (APs) one by one as it finds them. The status method would be event values. Connect and scan can take 30secs and more Customer did raise the concern that this is blocking API |
We can't really do a 'continue' index because each scan is different, some new networks can appear, but also the order is different. We could do event based scan, or even better add extra event based function, but depending on module that may be impossible to implement properly as they may return whole list of detected networks anyway. I agree that having both sync/async API is the best solution. I'll add the event based methods. |
9f7de44
to
64b9da7
Compare
* | ||
* @return Connection strength in dBm (negative value), or 0 if measurement impossible | ||
*/ | ||
virtual int16_t get_rssi() = 0; |
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.
Why int16_t
? Just curious
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.
Mostly because I wasn't sure int8_t is large enough.
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.
i believe that 8bit is enough for rssi..
64b9da7
to
21a2f0f
Compare
* @param cb Function to be called for every discovered network | ||
* @param data A user handle that will be passed to @a cb along with the AP data | ||
*/ | ||
virtual void scan(wifi_ap_scan_cb_t cb, void *data = NULL) = 0; |
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.
Nitpick (sorry, it's Friday): I'd call this something like scan_async
(and maybe even scan_sync
for the blocking version). Even though the documentation is very clear, calling both functions sync
and having one be synchronous and the other one asynchronous can lead to some confusion for people reading the code. Makes even more sense since you already did this with connect_async
.
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.
Agreed, makes sense.
What would be the best way to test this PR? |
There's ESP8266 implementation for the new API: https://github.com/bulislaw/esp8266-driver/tree/feature_wifi |
21a2f0f
to
0a3d0cd
Compare
0a3d0cd
to
d19c0c3
Compare
This is for a wifi feature branch where we can progress with it. I would go with the new return types as @bulislaw proposing, and clean the rest meanwhile (that can happen separately), the feature wifi branch is just for wifi. Any other leftovers for this to be merged to the feature branch? |
I think that's it, if we find something else needs tweaking we can fix it in subsequent commits. |
Looks good to merge and keep taking patches pending CI results of course 👍 |
/morph test |
Result: FAILUREYour command has finished executing! Here's what you wrote!
Outputmbed Build Number: 856 Build failed! |
Failure not related but if possible I'd suggest rebasing this branch against master so development CI at least compiles. There is a include path problem when compiling on linux due to case sensitivity for the NCS platform. |
General refactoring of the API and new methods added: * get_rssi() - measures radio signal strenght * get_state() - returns current state (not connected, connecting, connected, error) * scan() - scans for available networks sync and async versions * connect_async() - connect to a network without blocking
d19c0c3
to
f9f1f44
Compare
Rebased. |
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
Outputmbed Build Number: 861 All builds and test passed! |
General refactoring of the API and two new methods added:
connecting, connected, error)
@lauri-piikivi @sg-
I changed how the get_rssi function works, comparing to what Lauri proposed. It's more in line in how other IOT SDKs work and also it's simpler. It only fetches current RSSI, if application wants to average it out over multiple measurements it can always wrap it in a loop, but I think it's probably good enough for most people.