mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Adding softAP SSID & PSK query API (#4138)
* softAP SSID & PSK query API added. Signatures: String ESP8266WiFiAP::softAPSSID() const; String ESP8266WiFiAP::softAPPSK() const; * Fix for proper C-style string copy * add API to validate input ip as string Signatures: static bool IPAddress::isValid(const String& arg); static bool IPAddress::isValid(const char* arg, size_t len); * fix indentation * fix ip string validation to use built-in implementation. signatures: static bool isValid(const String& arg); static bool isValid(const char* arg);
This commit is contained in:
parent
29580e8166
commit
241531aa4c
@ -112,4 +112,12 @@ String IPAddress::toString() const
|
|||||||
return String(szRet);
|
return String(szRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IPAddress::isValid(const String& arg) {
|
||||||
|
return IPAddress().fromString(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPAddress::isValid(const char* arg) {
|
||||||
|
return IPAddress().fromString(arg);
|
||||||
|
}
|
||||||
|
|
||||||
const IPAddress INADDR_NONE(0, 0, 0, 0);
|
const IPAddress INADDR_NONE(0, 0, 0, 0);
|
||||||
|
@ -79,6 +79,14 @@ class IPAddress: public Printable {
|
|||||||
virtual size_t printTo(Print& p) const;
|
virtual size_t printTo(Print& p) const;
|
||||||
String toString() const;
|
String toString() const;
|
||||||
|
|
||||||
|
/*
|
||||||
|
check if input string(arg) is a valid IPV4 address or not.
|
||||||
|
return true on valid.
|
||||||
|
return false on invalid.
|
||||||
|
*/
|
||||||
|
static bool isValid(const String& arg);
|
||||||
|
static bool isValid(const char* arg);
|
||||||
|
|
||||||
friend class EthernetClass;
|
friend class EthernetClass;
|
||||||
friend class UDP;
|
friend class UDP;
|
||||||
friend class Client;
|
friend class Client;
|
||||||
|
@ -339,3 +339,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]);
|
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
return String(macStr);
|
return String(macStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the configured(Not-In-Flash) softAP SSID name.
|
||||||
|
* @return String SSID.
|
||||||
|
*/
|
||||||
|
String ESP8266WiFiAPClass::softAPSSID() const {
|
||||||
|
struct softap_config config;
|
||||||
|
wifi_softap_get_config(&config);
|
||||||
|
char* name = reinterpret_cast<char*>(config.ssid);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
@ -47,6 +47,9 @@ class ESP8266WiFiAPClass {
|
|||||||
uint8_t* softAPmacAddress(uint8_t* mac);
|
uint8_t* softAPmacAddress(uint8_t* mac);
|
||||||
String softAPmacAddress(void);
|
String softAPmacAddress(void);
|
||||||
|
|
||||||
|
String softAPSSID() const;
|
||||||
|
String softAPPSK() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user