My board is ESP8266.
In the smartConfig() function, get the ssid and password, print them(display the right infomation i want) and then pass the value to the external variables.
In the loop function, print the ssid, but the result is something like "??".
so what is the problem, i have spent much time on it. thank you very much if you can give me some information about it.
here is my code
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
const char* ssid;
const char* password;
bool smartConfig(){
WiFi.mode(WIFI_STA);
Serial.println("\r\nWait for Smartconfig");
WiFi.beginSmartConfig();
while (1){
delay(500);
Serial.println("waiting for smartconfig");
if (WiFi.smartConfigDone()){
delay(1000);
ssid= WiFi.SSID().c_str();
password = WiFi.psk().c_str();
Serial.println(ssid); // the right result like "mywifi"
Serial.println(password); // the right result like "mypasswd"
Serial.println("SmartConfig Success");
break;
}
}
return true;
}
void setup() {
Serial.begin(115200);
Serial.println("");
delay(1000);
smartConfig();
Serial.println(ssid);
Serial.println(password);
}
void loop() {
delay(1000);
Serial.println(ssid);// not the "mywifi",but "?????"
Serial.println(password);//not the "mypasswd",but "?????"
}