mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-15 23:51:20 +10:00
fixes #924 wifi info getters
gets ssid and psk with persistent param, needs testing
This commit is contained in:
+71
-8
@@ -2362,9 +2362,29 @@ void WiFiManager::setCountry(String cc){
|
||||
void WiFiManager::setClass(String str){
|
||||
_bodyClass = str;
|
||||
}
|
||||
|
||||
|
||||
// HELPERS
|
||||
|
||||
/**
|
||||
* getWiFiSSID
|
||||
* @since $dev
|
||||
* @param bool persistent
|
||||
* @return String
|
||||
*/
|
||||
String WiFiManager::getWiFiSSID(bool persistent){
|
||||
return WiFi_SSID(persistent);
|
||||
}
|
||||
|
||||
/**
|
||||
* getWiFiPass
|
||||
* @since $dev
|
||||
* @param bool persistent
|
||||
* @return String
|
||||
*/
|
||||
String WiFiManager::getWiFiPass(bool persistent){
|
||||
return WiFi_psk(persistent);
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
// @todo fix DEBUG_WM(0,0);
|
||||
template <typename Generic>
|
||||
@@ -2665,15 +2685,58 @@ bool WiFiManager::WiFi_hasAutoConnect(){
|
||||
return WiFi_SSID() != "";
|
||||
}
|
||||
|
||||
String WiFiManager::WiFi_SSID(){
|
||||
#ifdef ESP8266
|
||||
return WiFi.SSID();
|
||||
#elif defined(ESP32)
|
||||
//@todo , workaround only when not connected
|
||||
String WiFiManager::WiFi_SSID(bool persistent) const{
|
||||
|
||||
#ifdef ESP8266
|
||||
struct station_config conf;
|
||||
if(persistent) wifi_station_get_config_default(&conf);
|
||||
else wifi_station_get_config(&conf);
|
||||
|
||||
char tmp[33]; //ssid can be up to 32chars, => plus null term
|
||||
memcpy(tmp, conf.ssid, sizeof(conf.ssid));
|
||||
tmp[32] = 0; //nullterm in case of 32 char ssid
|
||||
return String(reinterpret_cast<char*>(tmp));
|
||||
|
||||
#elif defined(ESP32)
|
||||
if(persistent){
|
||||
wifi_config_t conf;
|
||||
esp_wifi_get_config(WIFI_IF_STA, &conf);
|
||||
return String(reinterpret_cast<const char*>(conf.sta.ssid));
|
||||
}
|
||||
else {
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return String();
|
||||
}
|
||||
wifi_ap_record_t info;
|
||||
if(!esp_wifi_sta_get_ap_info(&info)) {
|
||||
return String(reinterpret_cast<char*>(info.ssid));
|
||||
}
|
||||
return String();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
String WiFiManager::WiFi_psk(bool persistent) const {
|
||||
#ifdef ESP8266
|
||||
struct station_config conf;
|
||||
|
||||
if(persistent) wifi_station_get_config_default(&conf);
|
||||
else wifi_station_get_config(&conf);
|
||||
|
||||
char tmp[65]; //psk is 64 bytes hex => plus null term
|
||||
memcpy(tmp, conf.password, sizeof(conf.password));
|
||||
tmp[64] = 0; //null term in case of 64 byte psk
|
||||
return String(reinterpret_cast<char*>(tmp));
|
||||
|
||||
#elif defined(ESP32)
|
||||
// only if wifi is init
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return String();
|
||||
}
|
||||
wifi_config_t conf;
|
||||
esp_wifi_get_config(WIFI_IF_STA, &conf);
|
||||
return String(reinterpret_cast<const char*>(conf.sta.ssid));
|
||||
#endif
|
||||
return String(reinterpret_cast<char*>(conf.sta.password));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
+7
-1
@@ -269,6 +269,11 @@ class WiFiManager
|
||||
// check if the module has a saved ap to connect to
|
||||
bool getWiFiIsSaved();
|
||||
|
||||
// helper to get saved ssid, if persistent get stored, else get current if connected
|
||||
String getWiFiPass(bool persistent = false);
|
||||
// helper to get saved password, if persistent get stored, else get current if connected
|
||||
String getWiFiSSID(bool persistent = false);
|
||||
|
||||
// debug output the softap config
|
||||
void debugSoftAPConfig();
|
||||
// debug output platform info and versioning
|
||||
@@ -422,7 +427,8 @@ class WiFiManager
|
||||
uint8_t WiFi_softap_num_stations();
|
||||
bool WiFi_hasAutoConnect();
|
||||
void WiFi_autoReconnect();
|
||||
String WiFi_SSID();
|
||||
String WiFi_SSID(bool persistent = false) const;
|
||||
String WiFi_psk(bool persistent = false) const;
|
||||
bool WiFi_scanNetworks();
|
||||
bool WiFi_scanNetworks(bool force,bool async);
|
||||
bool WiFi_scanNetworks(unsigned int cachetime,bool async);
|
||||
|
||||
Reference in New Issue
Block a user