Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool loadConfiguration() {
- File configFile = LittleFS.open("/config.json", "r");
- if (!configFile) {
- Serial.println("Failed to open config file");
- return false;
- }
- size_t size = configFile.size();
- if (size > 1024) {
- Serial.println("Config file size is too large");
- return false;
- }
- // Allocate a buffer to store contents of the file.
- std::unique_ptr<char[]> buf(new char[size]);
- // We don't use String here because ArduinoJson library requires the input
- // buffer to be mutable. If you don't use ArduinoJson, you may as well
- // use configFile.readString instead.
- configFile.readBytes(buf.get(), size);
- StaticJsonDocument<512> doc;
- auto error = deserializeJson(doc, buf.get());
- if (error) {
- Serial.println("Failed to parse config file");
- Serial.println(error.f_str());
- return false;
- }
- Usermax0 = doc["Usermax0"];
- Usermin0 = doc["Usermin0"];
- Usermax1 = doc["Usermax1"];
- Usermin1 = doc["Usermin1"];
- Usermax2 = doc["Usermax2"];
- Usermin2 = doc["Usermin2"];
- Usermax3 = doc["Usermax3"];
- Usermin3 = doc["Usermin3"];
- Usermax4 = doc["Usermax4"];
- Usermin4 = doc["Usermin4"];
- Usermax5 = doc["Usermax5"];
- Usermin5 = doc["Usermin5"];
- Usermax6 = doc["Usermax6"];
- Usermin6 = doc["Usermin6"];
- Usermax7 = doc["Usermax7"];
- Usermin7 = doc["Usermin7"];
- Usermax8 = doc["Usermax8"];
- Usermin8 = doc["Usermin8"];
- Usermax9 = doc["Usermax9"];
- Usermin9 = doc["Usermin9"];
- Usermax10 = doc["Usermax10"];
- Usermin10 = doc["Usermin10"];
- Usermax11 = doc["Usermax11"];
- Usermin11 = doc["Usermin11"];
- Usermax12 = doc["Usermax12"];
- Usermin12 = doc["Usermin12"];
- Usermax13 = doc["Usermax13"];
- Usermin13 = doc["Usermin13"];
- Usermax14 = doc["Usermax14"];
- Usermin14 = doc["Usermin14"];
- Usermax15 = doc["Usermax15"];
- Usermin15 = doc["Usermin15"];
- Serial.print("Usermax0: "); Serial.println(Usermax0);
- Serial.print("Usermin0: "); Serial.println(Usermin0);
- Serial.print("Usermax1: "); Serial.println(Usermax1);
- Serial.print("Usermin1: "); Serial.println(Usermin1);
- Serial.print("Usermax2: "); Serial.println(Usermax2);
- Serial.print("Usermin2: "); Serial.println(Usermin2);
- Serial.print("Usermax3: "); Serial.println(Usermax3);
- Serial.print("Usermin3: "); Serial.println(Usermin3);
- Serial.print("Usermax4: "); Serial.println(Usermax4);
- Serial.print("Usermin4: "); Serial.println(Usermin4);
- Serial.print("Usermax5: "); Serial.println(Usermax5);
- Serial.print("Usermin5: "); Serial.println(Usermin5);
- Serial.print("Usermax6: "); Serial.println(Usermax6);
- Serial.print("Usermin6: "); Serial.println(Usermin6);
- Serial.print("Usermax7: "); Serial.println(Usermax7);
- Serial.print("Usermin7: "); Serial.println(Usermin7);
- Serial.print("Usermax8: "); Serial.println(Usermax8);
- Serial.print("Usermin8: "); Serial.println(Usermin8);
- Serial.print("Usermax9: "); Serial.println(Usermax9);
- Serial.print("Usermin9: "); Serial.println(Usermin9);
- Serial.print("Usermax10: "); Serial.println(Usermax10);
- Serial.print("Usermin10: "); Serial.println(Usermin10);
- Serial.print("Usermax11: "); Serial.println(Usermax11);
- Serial.print("Usermin11: "); Serial.println(Usermin11);
- Serial.print("Usermax12: "); Serial.println(Usermax12);
- Serial.print("Usermin12: "); Serial.println(Usermin12);
- Serial.print("Usermax13: "); Serial.println(Usermax13);
- Serial.print("Usermin13: "); Serial.println(Usermin13);
- Serial.print("Usermax14: "); Serial.println(Usermax14);
- Serial.print("Usermin14: "); Serial.println(Usermin14);
- Serial.print("Usermax15: "); Serial.println(Usermax15);
- Serial.print("Usermin15: "); Serial.println(Usermin15);
- //configFile.close();
- return true;
- }
- bool saveConfiguration() {
- StaticJsonDocument<512> doc;
- doc["Usermax0"] = Usermax0;
- doc["Usermin0"] = Usermin0;
- doc["Usermax1"] = Usermax1;
- doc["Usermin1"] = Usermin1;
- doc["Usermax2"] = Usermax2;
- doc["Usermin2"] = Usermin2;
- doc["Usermax3"] = Usermax3;
- doc["Usermin3"] = Usermin3;
- doc["Usermax4"] = Usermax4;
- doc["Usermin4"] = Usermin4;
- doc["Usermax5"] = Usermax5;
- doc["Usermin5"] = Usermin5;
- doc["Usermax6"] = Usermax6;
- doc["Usermin6"] = Usermin6;
- doc["Usermax7"] = Usermax7;
- doc["Usermin7"] = Usermin7;
- doc["Usermax8"] = Usermax8;
- doc["Usermin8"] = Usermin8;
- doc["Usermax9"] = Usermax9;
- doc["Usermin9"] = Usermin9;
- doc["Usermax10"] = Usermax10;
- doc["Usermin10"] = Usermin10;
- doc["Usermax11"] = Usermax11;
- doc["Usermin11"] = Usermin11;
- doc["Usermax12"] = Usermax12;
- doc["Usermin12"] = Usermin12;
- doc["Usermax13"] = Usermax13;
- doc["Usermin13"] = Usermin13;
- doc["Usermax14"] = Usermax14;
- doc["Usermin14"] = Usermin14;
- doc["Usermax15"] = Usermax15;
- doc["Usermin15"] = Usermin15;
- File configFile = LittleFS.open("/config.json", "w");
- if (!configFile) {
- Serial.println("Failed to open config file for writing");
- return false;
- }
- serializeJson(doc, configFile);
- //configFile.close();
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement