uEspConfigLib
https://github.com/Naguissa/uEspConfigLib
|
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... | |
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).
uEspConfigLib::uEspConfigLib | ( | uEspConfigLibFSInterface * | fs | ) |
Constructor.
fs | Selected uEspConfigLibFSInterface to be used |
void uEspConfigLib::addOption | ( | const char * | name, |
const char * | description, | ||
const char * | defaultValue | ||
) |
Defines a configuration option.
name | Name of configuration option |
description | Description of the configuration option |
defaultValue | Default value of the configuration option |
bool uEspConfigLib::clear | ( | const char * | name | ) |
Changes a configuration option to its default value.
name | Name of configuration option |
char * uEspConfigLib::getPointer | ( | const char * | name | ) |
Gets a char pointer to the current value of a configuration option.
name | Name of configuration option |
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.
server | WebServer or ESP8266WebServer variable, depending on architecture |
path | Path where the form will be sent |
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" } ] }
server | WebServer or ESP8266WebServer variable, depending on architecture |
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 } }
server | WebServer or ESP8266WebServer variable, depending on architecture |
bool uEspConfigLib::loadConfigFile | ( | ) |
Loads config file from FileSystem and processes it.
bool uEspConfigLib::saveConfigFile | ( | ) |
Recreates and overwrites config file to FileSystem with current configurations.
bool uEspConfigLib::set | ( | const char * | name, |
const char * | value | ||
) |
Changes a configuration option current value.
name | Name of configuration option |
value | Default value of the configuration option |