Usualy i use the module ESP8266 sketch data upload to upload my file but i would like to know if it's possible to create an empty file from sketch in case it doesn't exist.
I tried this :
#define CONFIG_FILE "/data/config.json"
// create file config.json if not exist
if (!SPIFFS.exists(CONFIG_FILE)){
Serial.print("Creating "); Serial.println(CONFIG_FILE);
File configFile = SPIFFS.open(CONFIG_FILE, "w");
StaticJsonBuffer<200> jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["serverName"] = "";
json["accessToken"] = "";
json.printTo(configFile);
configFile.close();
}
// now should exit anyway
File configFile = SPIFFS.open("/config.json", "r");
if (!configFile) {
Serial.println("Failed to open config file");
return false;
}
But not working.