Skip to content
/ ConfigDB Public

A fast way to store configurations in the "EEPROM" memory (NodeMCU / esp8266 12e)

License

Notifications You must be signed in to change notification settings

Eitol/ConfigDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConfigDB

A fast way to store configurations data in the "EEPROM" memory (NodeMCU / esp8266 12e)


Problem

Saving data structures in the EEPROM can be complicated. This library was created with the purpose of facilitating the saving of configurations in the EEPROM memory

Steps to use:

To use this library should jump define your own configuration class (in the example i made MyConfiguration class)

Simple example

This code shows examples of saving and obtaining the configuration data.

#include <math.h>
#include <configdb.h>

/** The custom MyConfiguration class  **/
class MyConfiguration
{
  public:
    int intValue;
    float floatValue;
};

ConfigDB<MyConfiguration> configDB;

bool printCfg(MyConfiguration cfg)
{
    Serial.printf("cfg.intValue:%d\n", cfg.intValue);
    Serial.printf("cfg.floatValue:%f\n", cfg.floatValue);
}

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

    //                         intValue | floatValue
    MyConfiguration defaultCfg = {0, 9876.543};

    // If the MyConfiguration is not saved then save it with a default value
    bool isPreviusConfigStored = configDB.storeDefaultIfNotLoad(defaultCfg);

    Serial.printf("\nisPreviusConfigStored=%d\n", isPreviusConfigStored); // False

    // Get the Configuration from the eeprom
    MyConfiguration newCfg = configDB.load();
    printCfg(newCfg);

    // Make new config and save
    newCfg.intValue = 1234;
    newCfg.floatValue = EULER;
    configDB.save(newCfg);

    // Get the new MyConfiguration recently saved in the eeprom
    newCfg = configDB.load();
    printCfg(newCfg);

    configDB.clear();    
}

void loop()
{
    // put your main code here, to run repeatedly:
}



Out of the program:

About

A fast way to store configurations in the "EEPROM" memory (NodeMCU / esp8266 12e)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages