Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loadConfiguration() {
- if (LittleFS.exists("/config.json")) {
- //file exists, reading and loading
- Serial.println("reading config file");
- File configFile = LittleFS.open("/config.json", "r");
- if (configFile) {
- Serial.println("opened config file");
- size_t size = configFile.size();
- // Allocate a buffer to store contents of the file.
- std::unique_ptr<char[]> buf(new char[size]);
- configFile.readBytes(buf.get(), size);
- DynamicJsonDocument doc(512);
- DeserializationError error = deserializeJson(doc, (buf.get()));
- if (error)
- Usermax0 = doc["Usermax0"];
- Usermin0 = doc["Usermax0"];
- }
- else{
- Serial.println("Failed to open config file");
- }
- configFile.close();
- Serial.print("Usermax0 :");Serial.println(Usermax0);
- Serial.print("Usermax0 :");Serial.println(Usermax0);
- }
- else{ Serial.println("The JSON file doesn't exist "); }
- }
- void saveConfiguration() {
- if (LittleFS.exists("/config.json")) {
- //file exists, Saving configuration
- Serial.println("saving config");
- StaticJsonDocument<512> doc;
- doc["Usermax0"] = Usermax0;
- doc["Usermin0"] = Usermin0;
- doc["Usermax1"] = Usermax1;
- doc["Usermin1"] = Usermin1;
- doc["Usermax2"] = Usermax2;
- serializeJson(doc, Serial);
- File configFile = LittleFS.open("/config.json", "w");
- if (!configFile) { Serial.println("failed to open config file for writing"); }
- }
- else{
- Serial.println("The JSON file doesn't exist ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement