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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WiFi.getCredentials #759

Merged

Conversation

@monkbroc
Copy link
Member

commented Dec 8, 2015

  • User provides an array of WiFiAccessPoint that get filled with the APs saved on the device
  • Returns number of APs on device
  • Photon only. Returns 0 on the Core since it cannot read APs back from the CC3000 馃槥

Changes

  • Implement wlan_get_credentials in HAL
  • Implement WiFi.getCredentials with array arguments
  • Add API test

Fixes #453

Usage:

    WiFiAccessPoint ap[5];
    int found = WiFi.getCredentials(ap, 5);
    for (int i=0; i<found; i++) {
        Serial.print("ssid: ");
        Serial.println(ap[i].ssid);
        Serial.println(ap[i].security);
        Serial.println(ap[i].channel);
        Serial.println(ap[i].rssi);
    }

For discussion: my first cut of this was to return a vector<WiFiAccessPoint> (typedefed to WiFiAccessPointList) from WiFi.getCredentials. This made for very nice application code:

WiFiAccessPointList list = WiFi.getCredentials();
for(WiFiAccessPoint ap : list) {
  Serial.println(ap.ssid);
}

But I noticed that WiFi.scan is currently implemented to accept an array allocated on the stack by the caller, so I went with that solution in the end.

Any strong reasons why not create a vector that allocates a few WiFiAccessPoint on the heap whenever WiFi.scan or WiFi.getCredentials is called? It is simple to make a version of WiFi.scan that returns a WiFiAccessPointList too.

Another point of discussion:
Printing the list of available networks on one of my Photon gives me this:

Listing stored access points
Count=5
SSID=TechBreweryNew, security=3
SSID=TechBreweryNew, security=3
SSID=TechBreweryNew, security=3
SSID=TechBreweryNew, security=3
SSID=TechBreweryNew, security=3
End listing

Is it OK that there are 5 copies of the same network? Now that people will be able to read this list out it might cause confusion.

Would it be better to overwrite existing credentials if the SSID is the same rather than make multiple copies?

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Dec 18, 2015

Outstanding! 馃憤 How about we call it WiFi.getCredentials() to mirror WiFi.setCredentials()?

@monkbroc

This comment has been minimized.

Copy link
Member Author

commented Dec 18, 2015

Sure. You have write access to my fork if you want to make small changes like that before merging.

Implement WiFi.getCredentials
* User provides an array of WiFiAccessPoint that get filled with the APs
  saved on the device
* Returns number of APs on device
* Photon only. Returns 0 on the Core since it cannot read APs back from the CC3000

Changes
* Implement wlan_get_credentials in HAL
* Implement WiFi.getCredentials with array arguments
* Add API test

Fixes #453

@monkbroc monkbroc force-pushed the monkbroc:feature/wifi-list-credentials branch from 00ccdda to 06fe283 Jan 12, 2016

@monkbroc

This comment has been minimized.

Copy link
Member Author

commented Jan 12, 2016

I renamed this API to WiFi.getCredentials()

@monkbroc monkbroc changed the title Implement WiFi.listCredentials Implement WiFi.getCredentials Jan 12, 2016

monkbroc added a commit to monkbroc/particle-docs that referenced this pull request Jan 12, 2016

@m-mcgowan m-mcgowan added this to the 0.4.9 milestone Jan 12, 2016

m-mcgowan added a commit that referenced this pull request Jan 14, 2016

@m-mcgowan m-mcgowan merged commit 3af46dd into particle-iot:develop Jan 14, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
@jmaxxz

This comment has been minimized.

Copy link

commented Feb 12, 2016

I don't see how this gets the configured credentials. It appears to get the everything about the configured wifi networks besides the credentials. Am I misreading this? Or is does this api exposes the preshared keys of previously configured networks.

@monkbroc

This comment has been minimized.

Copy link
Member Author

commented Feb 12, 2016

I think what you're saying is it would be best described as "get connections" rather than "get credentials" since it doesn't actually return the passwords, but the connection information for which passwords are available, but cannot be retrieved. I can update the docs to that effect.

@jmaxxz

This comment has been minimized.

Copy link

commented Feb 14, 2016

@monkbroc yes that is exactly what I am saying. Thanks!

@technobly technobly deleted the monkbroc:feature/wifi-list-credentials branch Oct 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can鈥檛 perform that action at this time.