Skip to content

Instantly share code, notes, and snippets.

@nishanc
Created May 15, 2021 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishanc/9d7293cb685ccd2869a3815310420d7b to your computer and use it in GitHub Desktop.
Save nishanc/9d7293cb685ccd2869a3815310420d7b to your computer and use it in GitHub Desktop.
//access SD card for WiFi SSID and Password
if (!SD_MMC.begin()) {
Serial.println("Failed to mount card");
return;
}
File file = SD_MMC.open("/ssid.txt", FILE_READ);
File file_pwd = SD_MMC.open("/pwd.txt", FILE_READ);
if (!file || !file_pwd) {
Serial.println("Opening file to read failed");
return;
}
Serial.println("File Content: SSID");
while (file.available()) {
int l = file.readBytesUntil('\n', ssid, sizeof(ssid));
if (l > 0 && ssid[l-1] == '\r') {
l--;
}
ssid[l] = 0;
}
Serial.println(ssid);
Serial.println("File Content: Password");
while (file_pwd.available()) {
int l = file_pwd.readBytesUntil('\n', password, sizeof(password));
if (l > 0 && password[l-1] == '\r') {
l--;
}
password[l] = 0;
}
Serial.println(password);
file.close();
file_pwd.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment