// Read File from SPIFFS String readFile(fs::FS &fs, const char * path){ Serial.printf("Reading file: %s\r\n", path); File file = fs.open(path); if(!file || file.isDirectory()){ Serial.println("- failed to open file for reading"); return String(); } String fileContent; while(file.available()){ fileContent = file.readStringUntil('\n'); break; } return fileContent; } // Write file to SPIFFS void writeFile(fs::FS &fs, const char * path, const char * message){ Serial.printf("Writing file: %s\r\n", path); File file = fs.open(path, FILE_WRITE); if(!file){ Serial.println("- failed to open file for writing"); return; } if(file.print(message)){ Serial.println("- file written"); } else { Serial.println("- frite failed"); } } //returns all key/value pairs with the parameter "all" or just the value of the parameter key. String getCurrentSavedData(const char* data, String key){ File file = SPIFFS.open(data, "r"); if (!file) { throw std::runtime_error("File not found"); } String json = file.readString(); file.close(); StaticJsonDocument<200> jsonDoc; // create a JSON document with a capacity of 200 bytes deserializeJson(jsonDoc, json); // parse the JSON data and store it in the JsonDocument if(key == "all"){ return json; } else{ if(jsonDoc[key] == nullptr){ return ""; } else return jsonDoc[key]; } }