Skip to content

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

Merged
merged 1 commit into from
Sep 15, 2016
Merged

Conversation

bulislaw
Copy link
Member

@bulislaw bulislaw commented Sep 6, 2016

General refactoring of the API and two new methods added:

  • get_rssi() - measures radio signal strenght
  • get_state() - which returns current state (not connected,
    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.

@lauri-piikivi
Copy link

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

@bulislaw
Copy link
Member Author

bulislaw commented Sep 6, 2016

OK, will add it now then.

@bulislaw
Copy link
Member Author

bulislaw commented Sep 6, 2016

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.

@bulislaw bulislaw force-pushed the feature_wifi branch 2 times, most recently from 09e0f10 to 984424e Compare September 6, 2016 13:49
* @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;
Copy link
Contributor

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...

Copy link
Contributor

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).

Copy link
Contributor

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..

Copy link
Member Author

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.

Copy link
Contributor

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.

@lauri-piikivi
Copy link

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

@bulislaw
Copy link
Member Author

bulislaw commented Sep 7, 2016

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.

@bulislaw bulislaw force-pushed the feature_wifi branch 4 times, most recently from 9f7de44 to 64b9da7 Compare September 8, 2016 09:32
*
* @return Connection strength in dBm (negative value), or 0 if measurement impossible
*/
virtual int16_t get_rssi() = 0;
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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..

* @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;
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, makes sense.

@bogdanm
Copy link
Contributor

bogdanm commented Sep 9, 2016

What would be the best way to test this PR?

@bulislaw
Copy link
Member Author

bulislaw commented Sep 9, 2016

There's ESP8266 implementation for the new API: https://github.com/bulislaw/esp8266-driver/tree/feature_wifi

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 13, 2016

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?

@bulislaw
Copy link
Member Author

I think that's it, if we find something else needs tweaking we can fix it in subsequent commits.

@sg-
Copy link
Contributor

sg- commented Sep 14, 2016

  • I'd suggest not modifying the return types for now. This can be done later given it needs to apply to the whole API, not just Wi-Fi
  • async needs work. attach member is the precident for this with an enum of what the event is to be fired on. More docs on this coming soon.

Looks good to merge and keep taking patches pending CI results of course 👍

@sg- sg- removed the needs: review label Sep 14, 2016
@sg-
Copy link
Contributor

sg- commented Sep 14, 2016

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 856

Build failed!

@sg-
Copy link
Contributor

sg- commented Sep 14, 2016

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.

a929bbb

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
@bulislaw
Copy link
Member Author

Rebased.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 14, 2016

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 861

All builds and test passed!

@bridadan
Copy link
Contributor

bridadan commented Sep 14, 2016

Just for complete clarity, the build failure was due to the fact that PR #2678 was not present on the branch this PR was being merged into. When @bulislaw rebased he brought in that change, hence the build passed.

@0xc0170 0xc0170 removed the needs: CI label Sep 15, 2016
@0xc0170 0xc0170 merged commit 4fde794 into ARMmbed:feature_wifi Sep 15, 2016
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.

9 participants