I've implemented a small WiFi connection procedure into my ESP32 project. The available networks get printed with index, then I'm entering the index and retrieve the network name from it. The password is entered via serial in clear text.
Before connecting, I'm printing the credentials and thus could confirm they are read into const char *
strings properly.
Unfortunately when using this procedure the connection to my AP times out. I've also tried to override the strings with hardcoded values and then the connection works as expected.
while (!Serial.available()) {
// (timeout is implemented here)
}
String index_s = Serial.readStringUntil('\n');
long index = index_s.toInt();
// { same while as above }
String passw = Serial.readStringUntil('\n');
const char *ssid = WiFi.SSID(index).c_str();
const char *pass = passw.c_str();
// with this it works:
// ssid = "my_network";
// pass = "my_password";
Serial.printf("connecting to %s using %s", ssid, pass);
WiFi.begin(ssid, pass);