Skip to content

Adding softAP SSID & PSK query API #4138

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 18 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,33 @@ String ESP8266WiFiAPClass::softAPmacAddress(void) {
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return String(macStr);
}

/**
* Get the configured(Not-In-Flash) softAP SSID name.
* @return String SSID.
*/
String ESP8266WiFiAPClass::softAPSSID() const {
struct softap_config config;
Copy link
Member

Choose a reason for hiding this comment

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

Indentation in this function is different from nearby functions

wifi_softap_get_config(&config);
char* name = reinterpret_cast<char*>(config.ssid);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not just

config.ssid[sizeof(config.ssid) - 1] = 0; // guard
return String((const char*)(void*)config.ssid) ?

String(char*) will anyway search for the last \0

Copy link
Contributor Author

@IMAN4K IMAN4K Jan 24, 2018

Choose a reason for hiding this comment

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

@d-a-v
Based on @devyte comment, user must be able to configure 64 byte length PSK at max, not 63

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK sorry I did not see the hidden-outdated comment.

char ssid[sizeof(config.ssid) + 1];
memcpy(ssid, name, sizeof(config.ssid));
ssid[sizeof(config.ssid)] = '\0';

return String(ssid);
}

/**
* Get the configured(Not-In-Flash) softAP PSK or PASSWORD.
* @return String psk.
*/
String ESP8266WiFiAPClass::softAPPSK() const {
struct softap_config config;
wifi_softap_get_config(&config);
char* pass = reinterpret_cast<char*>(config.password);
char psk[sizeof(config.password) + 1];
memcpy(psk, pass, sizeof(config.password));
psk[sizeof(config.password)] = '\0';

return String(psk);
}
3 changes: 3 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class ESP8266WiFiAPClass {
uint8_t* softAPmacAddress(uint8_t* mac);
String softAPmacAddress(void);

String softAPSSID() const;
Copy link
Member

Choose a reason for hiding this comment

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

Indentation on this line is different from nearby lines

String softAPPSK() const;

protected:

};
Expand Down