Skip to content

Latest commit

 

History

History
168 lines (119 loc) · 3.26 KB

README.md

File metadata and controls

168 lines (119 loc) · 3.26 KB

ConfigManager Forked

Library based on ConfigManager made by Nicholas Wiersma, main changes:

  • Implemented routine for begin AP mode only when a switch reset is pressed.
  • Fixed bug that doesn't link to landing page when SSID and PASSWORD parameters are saved.

Requires

Quick Start

Installing

You can install through the Arduino Library Manager. The package name is ConfigManager.

Usage

Include the library in your sketch

#include <ConfigManager.h>

Initialize a global instance of the library

ConfigManager configManager;

In your setup function start the manager

configManager.setAPName("Demo");
configManager.setAPFilename("/index.html");
configManager.addParameter("name", config.name, 20);
configManager.addParameter("enabled", &config.enabled);
configManager.addParameter("hour", &config.hour);
configManager.begin(config);

In your loop function, run the manager loop

configManager.loop();

Upload the index.html file found in the data directory into the SPIFFS. Instructions on how to do this vary based on your IDE. Below are links instructions on the most common IDEs:

Documentation

Methods

setAPName

void setAPName(const char *name)

Sets the name used for the access point.

setAPFilename

void setAPFilename(const char *filename)

Sets the path in SPIFFS to the webpage to be served by the access point.

setAPICallback

void setAPICallback(std::function<void(ESP8266WebServer*)> callback)

Sets a callback allowing customized http endpoints to be set when the api is setup.

addParameter

template<typename T>
void addParameter(const char *name, T *variable)

Adds a parameter to the REST interface.

addParameter (string)

void addParameter(const char *name, char *variable, size_t size)

Adds a character array parameter to the REST interface.

begin

template<typename T>
void begin(T &config)

Starts the configuration manager. The config parameter will be saved into and retrieved from the EEPROM.

save

void save()

Saves the config passed to the begin function to the EEPROM.

loop

void loop()

Handles any waiting REST requests.

Endpoints

GET /

Gets the HTML page that is used to set the Wifi SSID and password.

  • Response 200 (text/html)

POST /

Sets the Wifi SSID and password. The form example can be found in the data directory.

  • Request (application/x-www-form-urlencoded)
ssid=access point&password=some password
  • Request (application/json)
{
  "ssid": "access point",
  "password": "some password"
}

GET /settings

Gets the settings set in addParameter.

  • Response 200 (application/json)
{
  "enabled": true,
  "hour": 3
}

PUT /settings

Sets the settings set in addParameter.

  • Request (application/json)
{
  "enabled": false,
  "hour": 4
}
  • Response 400 (application/json)

  • Response 204 (application/json)