0

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);
asked Mar 15, 2019 at 1:21
3
  • removing comments now, as they are not necessary :p Commented Mar 15, 2019 at 5:46
  • 1
    Possible duplicate of String compare when using Serial Commented Mar 15, 2019 at 7:53
  • As you can see, I don't do string compare. So what do you think how I could've found the question you mentioned? Yes, it's the same reason. No, it's not the same issue. Commented Mar 15, 2019 at 16:01

1 Answer 1

1

The answer was quite simple but of the kind you need some time get find out. The issue was a hiding carriage return.

passw.trim();

Did the trick. String.trim() removes the \r and thus the password gets accepted.

answered Mar 15, 2019 at 4:26
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.