Connecting to WiFi on ESP32 using credentials from SD card I'd like to use an SD card to provide the login credentials to an ESP32. I've already got the ESP32 reading the relative data from the SD card and storing it as a char array on the ESP, but when I use those arrays in the WiFi.begin function it never connects.

Is this something to do with the way arrays work or am I doing something else wrong?

Respective code:


if (dataFile) {
Serial.println("File is available");
while (dataFile.available()) {
  byte currbyte = dataFile.read();
  if (currbyte == 58) {
    reading = 1;    //Begin reading data
    i = 0;
  }
  while (reading == 1 and s == 0) {
    byte currbyte = dataFile.read();
    //Serial.print(currbyte);
    //Serial.println(char(currbyte));
    if (currbyte == 13) {
      s = 1;
      reading = 0 ;
    }
    ssid[i] = char(currbyte);
    i++;
    //Serial.println(ssid);
  }
  while (reading == 1 and s == 1) {
    byte currbyte = dataFile.read();
    //Serial.print(currbyte);
    //Serial.println(char(currbyte));
    if (currbyte == 13) {
      s = 2;
      reading = 0 ;
    }
    password[i] = char(currbyte);
    i++;
    //Serial.println(password);
  }
}
dataFile.close();
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED and count &lt; 20) {
Serial.println("Connecting to WiFi..");
delay(1000);
count++;}
you add the '\13' to the SSID and password string instead of the terminating zero, because ssid[i] = char(currbyte); runs for 13 too

use readBytesUntil()

  char ssid[33];
  int l = file.readBytesUntil('\n', ssid, sizeof(ssid));
  if (l &gt; 0 &amp;&amp; ssid[l-1] == '\r') {
    l--;
  }
  ssid[l] = 0;