From d281bb33e7f85bdf35410048fdd0668408a938aa Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Thu, 22 Nov 2018 18:58:20 +0900 Subject: [PATCH] Supports AutoConnectAux --- README.md | 10 +- src/AutoConnect.cpp | 2 +- src/AutoConnect.h | 79 +------ src/AutoConnectAux.cpp | 375 +++++++++++++++++++----------- src/AutoConnectAux.h | 168 ++----------- src/AutoConnectDefs.h | 103 ++++++++ src/AutoConnectElement.h | 49 ++++ src/AutoConnectElementBasis.h | 170 ++++++++++++++ src/AutoConnectElementBasisImpl.h | 107 +++++++++ src/AutoConnectElementJson.h | 173 ++++++++++++++ src/AutoConnectElementJsonImpl.h | 140 +++++++++++ 11 files changed, 1012 insertions(+), 364 deletions(-) create mode 100644 src/AutoConnectDefs.h create mode 100644 src/AutoConnectElement.h create mode 100644 src/AutoConnectElementBasis.h create mode 100644 src/AutoConnectElementBasisImpl.h create mode 100644 src/AutoConnectElementJson.h create mode 100644 src/AutoConnectElementJsonImpl.h diff --git a/README.md b/README.md index 1487d20..fa27055 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,14 @@ AutoConnect can be embedded easily into your sketch, just "**begin**" and "**han The sketches which provide the web page using ESP8266WebServer/WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object(ESP8266) or WebServer object(ESP32), or itself can assign it. -### Adding the user-owned web screen can easily +### Adding the user-owned web screen can easily ENHANCED w/ v0.9.7 You can easily add your own web screen with sketch. It can be called from the AutoConnect menu and parameters can be passed. +### Adding the extended menu with a simple code can easily ENHANCED w/ v0.9.7 + +Just loading the elements of portal screen extension written with JSON allows you to incorporate your owned portal screen into the AutoConnect menu. + ## Supported hardware Apply the [Arduino core](https://github.com/esp8266/Arduino) of the ESP8266 Community. @@ -86,8 +90,10 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some ## Change log ### [0.9.7] Nov. 11, 2018 -- Supports addition of AutoConnect menu with user sketch by AutoConnectAux implementation. +- Supports AutoConnect menu extention by user sketch with **AutoConnectAux** implementation that attached **AutoConnectElement**. +- Supports loading and saving of user-defined parameters with JSON format. - Supports AutoConnectConfig::immediateStart option, to start the portal immediately without first trying WiFi.begin. +- Improved source code placement of predefined macros. Defined macros have been moved to ```AutoConnectDefs.h```. ### [0.9.6] Sept. 27, 2018 - Improvement of RSSI detection for saved SSIDs. diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 64a6372..8210fa2 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -700,4 +700,4 @@ void AutoConnect::_disconnectWiFi(bool wifiOff) { #endif while (WiFi.status() == WL_CONNECTED) delay(100); -} \ No newline at end of file +} diff --git a/src/AutoConnect.h b/src/AutoConnect.h index 605ad1e..bea3726 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -28,85 +28,11 @@ using WebServerClass = WebServer; #endif #include #include +#include "AutoConnectDefs.h" #include "AutoConnectPage.h" #include "AutoConnectCredential.h" #include "AutoConnectAux.h" -// Uncomment the following AC_DEBUG to enable debug output. -#define AC_DEBUG - -// Debug output destination can be defined externally with AC_DEBUG_PORT -#ifndef AC_DEBUG_PORT -#define AC_DEBUG_PORT Serial -#endif -#ifdef AC_DEBUG -#define AC_DBG(...) do {AC_DEBUG_PORT.print("[AC] "); AC_DEBUG_PORT.printf( __VA_ARGS__ );} while (0) -#else -#define AC_DBG(...) -#endif - -#ifndef AUTOCONNECT_APID -#if defined(ARDUINO_ARCH_ESP8266) -#define AUTOCONNECT_APID "esp8266ap" -#elif defined(ARDUINO_ARCH_ESP32) -#define AUTOCONNECT_APID "esp32ap" -#endif -#endif - -#ifndef AUTOCONNECT_PSK -#define AUTOCONNECT_PSK "12345678" -#endif - -#ifndef AUTOCONNECT_AP_IP -#define AUTOCONNECT_AP_IP 0x01F4A8C0 //*< 192.168.244.1 */ -#endif // !AUTOCONNECT_AP_IP -#ifndef AUTOCONNECT_AP_GW -#define AUTOCONNECT_AP_GW 0x01F4A8C0 //*< 192.168.244.1 */ -#endif // !AUTOCONNECT_AP_GW -#ifndef AUTOCONNECT_AP_NM -#define AUTOCONNECT_AP_NM 0x00FFFFFF //*< 255.255.255.0 */ -#endif // !AUTOCONNECT_AP_NM - -#ifndef AUTOCONNECT_URI -#define AUTOCONNECT_URI "/_ac" -#endif - -#ifndef AUTOCONNECT_HOMEURI -#define AUTOCONNECT_HOMEURI "/" -#endif - -#ifndef AUTOCONNECT_MENU_TITLE -#define AUTOCONNECT_MENU_TITLE "AutoConnect" -#endif -#define AUTOCONNECT_MENU_TITLE_CONNETED "Connected" - -#define AUTOCONNECT_URI_CONFIG AUTOCONNECT_URI "/config" -#define AUTOCONNECT_URI_CONNECT AUTOCONNECT_URI "/connect" -#define AUTOCONNECT_URI_RESULT AUTOCONNECT_URI "/result" -#define AUTOCONNECT_URI_OPEN AUTOCONNECT_URI "/open" -#define AUTOCONNECT_URI_DISCON AUTOCONNECT_URI "/disc" -#define AUTOCONNECT_URI_RESET AUTOCONNECT_URI "/reset" -#define AUTOCONNECT_URI_SUCCESS AUTOCONNECT_URI "/success" -#define AUTOCONNECT_URI_FAIL AUTOCONNECT_URI "/fail" - -#ifndef AUTOCONNECT_TIMEOUT -#define AUTOCONNECT_TIMEOUT 30000 -#endif - -#ifndef AUTOCONNECT_STARTUPTIME -#define AUTOCONNECT_STARTUPTIME 10 -#endif - -#ifndef AUTOCONNECT_HTTPPORT -#define AUTOCONNECT_HTTPPORT 80 -#endif - -#ifndef AUTOCONNECT_DNSPORT -#define AUTOCONNECT_DNSPORT 53 -#endif - -#define AC_UNUSED(expr) do { (void)(expr); } while (0) - /**< A type to save established credential at WiFi.begin automatically. */ typedef enum AC_SAVECREDENTIAL { AC_SAVECREDENTIAL_NEVER, @@ -286,7 +212,7 @@ class AutoConnect { /** Extended pages made up with AutoConnectAux */ std::unique_ptr _aux; - + /** Saved configurations */ AutoConnectConfig _apConfig; struct station_config _credential; @@ -363,6 +289,7 @@ class AutoConnect { #elif defined(ARDUINO_ARCH_ESP32) friend class WebServer; #endif + friend class AutoConnectAux; }; diff --git a/src/AutoConnectAux.cpp b/src/AutoConnectAux.cpp index fffa880..aa19702 100644 --- a/src/AutoConnectAux.cpp +++ b/src/AutoConnectAux.cpp @@ -1,18 +1,22 @@ /** - * Implementation of AutoConnectAux class and subordinated AutoConnectElement class. - * @file AutoConnectAux.cpp - * @author hieromon@gmail.com - * @version 0.9.7 - * @date 2018-11-17 - * @copyright MIT license. + * Implementation of AutoConnectAux class. + * @file AutoConnectAuxBasisImpl.h + * @author hieromon@gmail.com + * @version 0.9.7 + * @date 2018-11-17 + * @copyright MIT license. */ #include "AutoConnect.h" #include "AutoConnectAux.h" +#include "AutoConnectElement.h" +#include "AutoConnectElementBasisImpl.h" +#ifdef AUTOCONNECT_USE_JSON +#include "AutoConnectElementJsonImpl.h" +#endif /** * Template for auxiliary page composed with AutoConnectAux of user sketch. - * * The structure of the auxiliary page depends on this template for * the purpose to be incorporated into the AutoConnect Menu. * The page element implemented by AutoConnectElement is placed at the @@ -57,100 +61,8 @@ const char AutoConnectAux::_PAGE_AUX[] PROGMEM = { }; /** - * Generate an HTML ")); -} - -/** - * Generate an HTML element. - * A "value" is associated with the input tag and sent by the form - * action as the value of "name". If the label member is contained, it - * is placed to the right side of the checkbox to be labeled. - * If the label member is empty, only the checkbox is placed. - * @return String an HTML string. - */ -const String AutoConnectCheckbox::toHTML(void) const { - String html; - - html = String(FPSTR("