Code Monkey home page Code Monkey logo

Comments (3)

BauerPh avatar BauerPh commented on August 22, 2024

I've used it in this project: click

Quick untested example:

#include <JSONtoSPIFFS.h>

#define CONFIGFILE "config.json"

JSONtoSPIFFS Config;

// Define some variables
bool setting1;
int setting2;
String setting3;

void setup() {
  Serial.begin(115200);

  // init library
  SPIFFS.begin();
  Config.begin(&SPIFFS);

  // set variables
  setting1 = false;
  setting2 = 343;
  setting3 = "hello world";

  // save config
  if (Config.loadConfigFile(CONFIGFILE)) {   // this will also create the configfile if it doesn't exists
    Config.setValue("mySetting1", setting1); // returns true on success
    Config.setValue("mySetting2", setting2);
    Config.setValue("mySetting3", setting3);
    Config.saveConfigFile(); // Commit changes
  }
  
  // change variables
  setting1 = true;
  setting2 = 100;
  setting3 = "no hello world";

  // load config
  if (Config.loadConfigFile(CONFIGFILE)) {
    Config.getValue("mySetting1", setting1);
    Config.getValue("mySetting2", setting2);
    Config.getValue("mySetting3", setting3);
    Config.closeConfigFile(); // dont forget to close the file!
  }

  // check variables
   Serial.println(setting1);
   Serial.println(setting2);
   Serial.println(setting3);

  // Remove "mySetting1"
  if (Config.loadConfigFile(CONFIGFILE)) {
    Config.removeKey("mySetting1");
    Config.saveConfigFile(); // Commit changes
  }

  // Delete configfile
  Config.deleteConfigFile(CONFIGFILE); // file has to be closed!
}

Not that ALL methods return true on success and false when failed!

Also have a look at JSONtoSPIFFS.h to enable Debug-Logging.

from jsontospiffs.

renerlemes avatar renerlemes commented on August 22, 2024

If I have the following json:

{ "Debug": true, "Device": [ { "Serial": "AUT010001" } ], }

How to update the Serial field?

from jsontospiffs.

BauerPh avatar BauerPh commented on August 22, 2024

afaik nested json data is not supported. Can you modify this to:

{ "Debug": true, "Device": "", "Serial": "AUT010001"}

from jsontospiffs.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.