Hi,
I am currently struggling with setting wiFi credentials from serial.
Here is my serial routine:
case '~': //Redio Report / WiFi and enter wiFi credentials if not connected
if (WiFi.status() == WL_CONNECTED)
{
Console2.printf ("\nWiFi Status\n");
serialPage = '~';
} else {
// unconnected, need credentials
Console2.printf ("\nEnter SSID,Password");
while (Console0.available() == 0) {}
ssid = Console0.readStringUntil(','); // store SSID
pass = Console0.readStringUntil('\n'); // store password
Console2.printf("\nTry conn' to %s (%u) , %s (%u) \n", ssid.c_str(), ssid.length(), pass.c_str(), pass.length());
#ifdef TELNET
TelnetStream.println("bye bye");
TelnetStream.flush();
TelnetStream.stop();
#endif
WiFi.disconnect();
delay(1000);
Console0.flush();
getWiFi();
}
break;
It prints the correct ssid and password,however the length is given with one byte more (the null character, I assume).
The getWiFi() routine is not successful:
void getWiFi()
{
if ((WiFi.status() != WL_CONNECTED))
{
WiFi.mode(WIFI_STA);
if (ssid.length() && pass.length())
{
WiFi.begin(ssid.c_str(), pass.c_str());
}else{
WiFi.begin();
}
// WiFi.begin(WIFI_SSID, WIFI_PASS);
// WiFi.begin();
wifiConnectCounter = 1;
while (WiFi.status() != WL_CONNECTED)
{
delay(wifiRepeatInterval);
Console4.print(".");
wifiConnectCounter++;
if (wifiConnectCounter > wifiMaxTries)
{
Console4.printf("\nIs %s , %s OK? -> Menu, enter ""~""", ssid.c_str(), pass.c_str());
WiFi.disconnect();
Console4.printf("\nRunning offline\n");
WiFi.softAP("SoftPower", WIFI_PASS);
ip = WiFi.softAPIP();
break;
}
}
delay(50);
WiFi.setHostname(DEVICE_NAME);
}
if (WiFi.status() == WL_CONNECTED)
{
ip = WiFi.localIP();
} else {
Console4.printf("\nStarting Access point\n");
WiFi.softAP("SoftPower", WIFI_PASS);
ip = WiFi.softAPIP();
}
Console4.print("\nDone: RRSI= "); Console4.print(WiFi.RSSI());
myIP(); Console4.printf(charbuff);
}
I assume that it takes over the null character into the
WiFi.begin(ssid.c_str(), pass.c_str());
and it fails due to that null character.
How could I formulate the WiFi.begin() call to get it right?
Thank you for your help.
Laszlo