Closed
Description
Hardware:
Board: ESP32 Dev Module
Core Installation/update date: 30/jul/2018
IDE name: Arduino IDE
Flash Frequency: 40Mhz
Upload Speed: 92600
Description:
As far as i know that if esp32 connected to a wifi it store the configuration in the flash but calling WiFi.SSID() return null after restarting esp32, what i notice is that the SSID is called from esp_wifi_sta_get_ap_info while the psk is called esp_wifi_get_config in WiFiSTA.cpp
the way i solved this problem is i copied the code in WiFi.psk() and added to WiFi.SSID() like this :
String WiFiSTAClass::SSID() const
{
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));
}
else{
wifi_config_t conf;
esp_wifi_get_config(WIFI_IF_STA, &conf);
return String(reinterpret_cast<char*>(conf.sta.ssid));
}
return String();
}
and everything went good for me , is this consider a good solution for this problem ? as i was looking for others solutions but couldn`t find
Sketch:
#include <WiFi.h>
/*commented after 1st time connection*/
//const char* ssid = "your-ssid";
//const char* password = "your-password";
void setup()
{
Serial.begin(115200);
delay(10);
WiFi.mode(WIFI_STA);
WiFi.persistent (true);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
}