From ff43e69bc0df926eaae2bb1855d03fabc94f373d Mon Sep 17 00:00:00 2001 From: "rjwats@gmail.com" Date: Sat, 3 Mar 2018 11:45:02 +0000 Subject: [PATCH] add example --- README.md | 36 +++++++++++++++++++++++++++++++++++- src/WiFiStatus.h | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6ea5d19..891b05f 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,41 @@ The default settings configure the device to bring up an access point on start u ## Software Overview -TODO... +### Back End + +The back end is a set of REST endpoints hosted by a ([ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer)) instance. The source is split up by feature, for example ([WiFiScanner.h](src/WiFiScanner.h)) implements the end points for scanning for available networks. + +There is an abstract class ([SettingsService.h](src/SettingsService.h)) that provides an easy means of adding configurable services/features to the device. It takes care of writing the settings as JSON to the SPIFFS filesystem. All you need to do is extend the class with your required configuration and implement the functions which serialize the settings to/from JSON. JSON serialization utilizes the excellent [ArduinoJson](https://github.com/bblanchon/ArduinoJson) library. Here is a example is a service with username and password settings: + +```cpp +#include + +class ExampleSettingsService : public SettingsService { + + public: + + ExampleSettingsService(AsyncWebServer* server, FS* fs) : SettingsService(server, fs, "/apSettings", "/config/apSettings.json") {} + ~ExampleSettingsService(){} + + protected: + + void readFromJsonObject(JsonObject& root) { + _username = root["username"] | ""; + _password = root["password"] | ""; + } + + void writeToJsonObject(JsonObject& root) { + root["username"] = _username; + root["password"] = _password; + } + + private: + + String _username; + String _password; + +}; +``` ## Future Extensions diff --git a/src/WiFiStatus.h b/src/WiFiStatus.h index bce0b57..916214a 100644 --- a/src/WiFiStatus.h +++ b/src/WiFiStatus.h @@ -23,7 +23,7 @@ class WiFiStatus { WiFiEventHandler _onStationModeDisconnectedHandler; WiFiEventHandler _onStationModeGotIPHandler; - // static functions for logging wifi events to the UART + // static functions for logging WiFi events to the UART static void onStationModeConnected(const WiFiEventStationModeConnected& event); static void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event); static void onStationModeGotIP(const WiFiEventStationModeGotIP& event);