uEspConfigLib
https://github.com/Naguissa/uEspConfigLib
Public Member Functions | List of all members
uEspConfigLib Class Reference

The deffinitive ESP32 and ESP8266 configuration Arduino library, uEspConfigLib. More...

#include <uEspConfigLib.h>

Public Member Functions

 uEspConfigLib (uEspConfigLibFSInterface *)
 Constructor. More...
 
void addOption (const char *, const char *, const char *)
 Defines a configuration option. More...
 
bool set (const char *, const char *)
 Changes a configuration option current value. More...
 
char * getPointer (const char *)
 Gets a char pointer to the current value of a configuration option. More...
 
bool clear (const char *)
 Changes a configuration option to its default value. More...
 
void handleConfigRequestHtml (uEspConfigLib_WebServer *, const char *="/uConfigLib/saveConfig")
 Handles a configuration HTML form request. More...
 
void handleConfigRequestJson (uEspConfigLib_WebServer *)
 Handles a configuration JSON request. More...
 
void handleSaveConfig (uEspConfigLib_WebServer *)
 Handles a save configuration request. More...
 
bool loadConfigFile ()
 Loads config file from FileSystem and processes it. More...
 
bool saveConfigFile ()
 Recreates and overwrites config file to FileSystem with current configurations. More...
 

Detailed Description

The deffinitive ESP32 and ESP8266 configuration Arduino library, uEspConfigLib.

This library consist in 2 parts:

One main library, uEspConfigLib, that manages configuration options, defaults, configuration site (HTML and JSON), configuration processing (from a POST of previous site) and configuration storage.

One interface to manage different configuration storages.

Currently storage classes are: SD-card, LittleFS, SPIFFS and none (values are lost after restart).

Constructor & Destructor Documentation

◆ uEspConfigLib()

uEspConfigLib::uEspConfigLib ( uEspConfigLibFSInterface fs)

Constructor.

Parameters
fsSelected uEspConfigLibFSInterface to be used

Member Function Documentation

◆ addOption()

void uEspConfigLib::addOption ( const char *  name,
const char *  description,
const char *  defaultValue 
)

Defines a configuration option.

Parameters
nameName of configuration option
descriptionDescription of the configuration option
defaultValueDefault value of the configuration option

◆ clear()

bool uEspConfigLib::clear ( const char *  name)

Changes a configuration option to its default value.

Parameters
nameName of configuration option
Returns
False on error (name not defined previously)

◆ getPointer()

char * uEspConfigLib::getPointer ( const char *  name)

Gets a char pointer to the current value of a configuration option.

Parameters
nameName of configuration option
Returns
Char pointer. Null if not found.

◆ handleConfigRequestHtml()

void uEspConfigLib::handleConfigRequestHtml ( uEspConfigLib_WebServer *  server,
const char *  path = "/uConfigLib/saveConfig" 
)

Handles a configuration HTML form request.

This will handle the request and serve an HTML page with a form with all configurations.

Parameters
serverWebServer or ESP8266WebServer variable, depending on architecture
pathPath where the form will be sent

◆ handleConfigRequestJson()

void uEspConfigLib::handleConfigRequestJson ( uEspConfigLib_WebServer *  server)

Handles a configuration JSON request.

This will handle the request and serve a JSON document with all configurations:

{ "data": [ { "name": "variable_name", "description": "variable_description", "defaultValue": "variable_default_value", "value": "variable_current_value" }, { "name": "variable_name", "description": "variable_description", "defaultValue": "variable_default_value", "value": "variable_current_value" }, { "name": "variable_name", "description": "variable_description", "defaultValue": "variable_default_value", "value": "variable_current_value" } ] }

Parameters
serverWebServer or ESP8266WebServer variable, depending on architecture

◆ handleSaveConfig()

void uEspConfigLib::handleSaveConfig ( uEspConfigLib_WebServer *  server)

Handles a save configuration request.

This will handle the request and parameters, change any existing one and save the config file. If a config option is not set as parameter will be ignored. If a config option is empty it will be stored as empty. It usually will respond with a 302 redirect to /?saved=1, but if "format" paramer is passed with "json" value it will respond as JSON: { "data": { "result": 1 } }

Parameters
serverWebServer or ESP8266WebServer variable, depending on architecture

◆ loadConfigFile()

bool uEspConfigLib::loadConfigFile ( )

Loads config file from FileSystem and processes it.

Returns
False on error

◆ saveConfigFile()

bool uEspConfigLib::saveConfigFile ( )

Recreates and overwrites config file to FileSystem with current configurations.

Returns
False on error

◆ set()

bool uEspConfigLib::set ( const char *  name,
const char *  value 
)

Changes a configuration option current value.

Parameters
nameName of configuration option
valueDefault value of the configuration option
Returns
False on error (name not defined previously)

The documentation for this class was generated from the following files: