Hi there,
I am building a relatively simple solution to save variables/values to spiffs via arduinojson.
In nutshell:
The default variables/values are saved to config.json file while the esp8266 in function, though web interface. The next reboot the new variables, like ssid/password are loaded, and connection estabilished. Still i have pleanty of other variables as well, the explanations yet is just for simplicity with ssid/pass.
The default configuration-save/load are working good, but the save for only one variable to conf.json are overwriting the file, so i get the file just with the variable=value which has been saved lastly.
Can someone point me, or hint or help..how to get this part of the code working as expected:
If variable exists, then update the new value, if not, then create and save.
At the moment the code has been built with arduinojson 5, i dont mind if we need to update to 6.
Thank in advance,
void ConfigFile_Save_Variable(String text, String value) {
Serial.print("Save_VariableToConfigFile: ");
Serial.print(text); Serial.print("="); Serial.print(value);
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
Serial.println("- failed to open config file for writing");
return;
}
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
//
json[text] = value;
//
//json.printTo(Serial); //print to - serial - debug
json.printTo(configFile); //print to - file
configFile.close();
Serial.println("");
Serial.println(" - config.json saved - OK.");
}