Hey,
I'm currently working on the CaptivePortalAdvanced example provided by DNSServer. This provides a sketch named 'Credentials' where the credentials are saved in the EEPROM. But I want to save the details in a text file, so I decided to use FS.h for this. I developed a code for this, but it doesn't printout the necessary details, like it does in the original code. Any pointers to what I'm doing wrong or any advice on what I should do would be really appreciated!
This is the original code provided, where the details are saved in the EEPROM:
void loadCredentials() {
EEPROM.begin(512);
EEPROM.get(0, ssid);
EEPROM.get(0 + sizeof(ssid), password);
char ok[2 + 1];
EEPROM.get(0 + sizeof(ssid) + sizeof(password), ok);
EEPROM.end();
if (String(ok) != String("OK")) {
ssid[0] = 0;
password[0] = 0;
}
Serial.println("Recovered credentials:");
Serial.println(ssid);
Serial.println(strlen(password) > 0 ? "********" : "<no password>");
}
void saveCredentials() {
EEPROM.begin(512);
EEPROM.put(0, ssid);
EEPROM.put(0 + sizeof(ssid), password);
char ok[2 + 1] = "OK";
EEPROM.put(0 + sizeof(ssid) + sizeof(password), ok);
EEPROM.commit();
EEPROM.end();
}
This is the code that I developed to save the details in a text file:
void saveCredentials() {
bool success = SPIFFS.begin();
if (!success) {
Serial.println("Error");
return;
}
File file = SPIFFS.open("/file.txt", "w");
char ssid1 = file.print(ssid);
char password1 = file.print(password);
file.close();
}
void loadCredentials() {
File file2 = SPIFFS.open("/file.txt", "r");
Serial.write(file2.read());
Serial.println("Recovered credentials:");
Serial.println(ssid);
Serial.println(strlen(password) > 0 ? "********" : "<no password>");
file2.close();
}
Thank you
Miteshi