Syntax help needed
Posted: Mon Aug 10, 2020 7:30 pm
In the following sketch I am trying to make write/read from spiffs a subroutine.
But I keep getting errors
ssidx is a string/variable I want to save in filex.txt then later read back and save to sdatax string variable
I want to save/return maybe 10 different saved different variables.
But I keep getting errors
ssidx is a string/variable I want to save in filex.txt then later read back and save to sdatax string variable
I want to save/return maybe 10 different saved different variables.
Code: Select all
#include <FS.h>
String sdatax ="";
String ssidx="192.168.0.105";
void setup(){
Serial.begin(115200);
Serial.println();
bool success = SPIFFS.begin();
if (!success){Serial.println("Error mountingthe file system"); return;}
write2_spiffs();
read2_spiffs();
}
void read2_spiffs(){
File file2 = SPIFFS.open("/filex.txt", "r");
if (!file2){ Serial.println("failed to open file for reading");return;}
sdatax = file2.readString();
file2.close();
Serial.println(sdatax);
}
void write2_spiffs(){
File file = SPIFFS.open("/filex.txt", "w");
if (!file) {Serial.println("Error opening file for writing");return;}
int bytesWritten = file.print(ssidx);
if (bytesWritten ==0){Serial.println("File write failed");return;}
file.close();
}
void loop()
{
}