Added AutoConnectConfig::attachMenu

pull/197/head
Hieromon Ikasamo 5 years ago
parent 6559273991
commit da02d16f43
  1. 13
      src/AutoConnect.cpp
  2. 25
      src/AutoConnect.h
  3. 5
      src/AutoConnectLabels.h
  4. 47
      src/AutoConnectPage.cpp

@ -2,8 +2,8 @@
* AutoConnect class implementation.
* @file AutoConnect.cpp
* @author hieromon@gmail.com
* @version 1.1.1
* @date 2019-10-17
* @version 1.1.4
* @date 2020-03-30
* @copyright MIT license.
*/
@ -311,8 +311,13 @@ bool AutoConnect::_configSTA(const IPAddress& ip, const IPAddress& gateway, cons
return rc;
}
String AutoConnect::_getBootUri()
{
/**
* Get URI to redirect at boot. It uses the URI according to the
* AutoConnectConfig::bootUti setting with the AutoConnectConfig::homeUri
* as the boot path.
* @return the boot uri.
*/
String AutoConnect::_getBootUri(void) {
if (_apConfig.bootUri == AC_ONBOOTURI_ROOT)
return String(AUTOCONNECT_URI);
else if (_apConfig.bootUri == AC_ONBOOTURI_HOME)

@ -2,8 +2,8 @@
* Declaration of AutoConnect class and accompanying AutoConnectConfig class.
* @file AutoConnect.h
* @author hieromon@gmail.com
* @version 1.1.1
* @date 2019-10-17
* @version 1.1.4
* @date 2020-03-30
* @copyright MIT license.
*/
@ -45,11 +45,23 @@ typedef enum AC_SAVECREDENTIAL {
AC_SAVECREDENTIAL_AUTO
} AC_SAVECREDENTIAL_t;
/**< URI that can be specified to AutoConnectConfig::bootUri. */
typedef enum AC_ONBOOTURI {
AC_ONBOOTURI_ROOT,
AC_ONBOOTURI_HOME
} AC_ONBOOTURI_t;
/**< An enumerated type of the designated menu items. */
typedef enum AC_MENUITEM {
AC_MENUITEM_CONFIGNEW = 0x0001,
AC_MENUITEM_OPENSSIDS = 0x0002,
AC_MENUITEM_DISCONNECT = 0x0004,
AC_MENUITEM_RESET = 0x0008,
AC_MENUITEM_HOME = 0x0010,
AC_MENUITEM_UPDATE = 0x0020,
AC_MENUITEM_DEVINFO = 0x0040
} AC_MENUITEM_t;
class AutoConnectConfig {
public:
/**
@ -75,6 +87,7 @@ class AutoConnectConfig {
immediateStart(false),
retainPortal(false),
portalTimeout(AUTOCONNECT_CAPTIVEPORTAL_TIMEOUT),
attachMenu(AC_MENUITEM_CONFIGNEW + AC_MENUITEM_OPENSSIDS + AC_MENUITEM_DISCONNECT + AC_MENUITEM_RESET + AC_MENUITEM_HOME),
ticker(false),
tickerPort(AUTOCONNECT_TICKER_PORT),
tickerOn(LOW),
@ -107,6 +120,7 @@ class AutoConnectConfig {
immediateStart(false),
retainPortal(false),
portalTimeout(portalTimeout),
attachMenu(AC_MENUITEM_CONFIGNEW + AC_MENUITEM_OPENSSIDS + AC_MENUITEM_DISCONNECT + AC_MENUITEM_RESET + AC_MENUITEM_HOME),
ticker(false),
tickerPort(AUTOCONNECT_TICKER_PORT),
tickerOn(LOW),
@ -139,6 +153,7 @@ class AutoConnectConfig {
immediateStart = o.immediateStart;
retainPortal = o.retainPortal;
portalTimeout = o.portalTimeout;
attachMenu = o.attachMenu;
ticker = o.ticker;
tickerPort = o.tickerPort;
tickerOn = o.tickerOn;
@ -170,6 +185,7 @@ class AutoConnectConfig {
bool immediateStart; /**< Skips WiFi.begin(), start portal immediately */
bool retainPortal; /**< Even if the captive portal times out, it maintains the portal state. */
unsigned long portalTimeout; /**< Timeout value for stay in the captive portal */
uint16_t attachMenu; /**< A compound value of the menu items to be attached */
bool ticker; /**< Drives LED flicker according to WiFi connection status. */
uint8_t tickerPort; /**< GPIO for flicker */
uint8_t tickerOn; /**< A signal for flicker turn on */
@ -224,7 +240,7 @@ class AutoConnect {
} AC_STARECONNECT_t;
bool _config(void);
bool _configSTA(const IPAddress& ip, const IPAddress& gateway, const IPAddress& netmask, const IPAddress& dns1, const IPAddress& dns2);
String _getBootUri();
String _getBootUri(void);
bool _getConfigSTA(station_config_t* config);
void _startWebServer(void);
void _startDNSServer(void);
@ -234,7 +250,7 @@ class AutoConnect {
bool _classifyHandle(HTTPMethod mothod, String uri);
void _handleUpload(const String& requestUri, const HTTPUpload& upload);
void _purgePages(void);
virtual PageElement* _setupPage(String uri);
virtual PageElement* _setupPage(String& uri);
#ifdef AUTOCONNECT_USE_JSON
template<typename T>
bool _parseJson(T in);
@ -257,6 +273,7 @@ class AutoConnect {
void _setReconnect(const AC_STARECONNECT_t order);
/** Utilities */
String _attachMenuItem(const AC_MENUITEM_t item);
static uint32_t _getChipId(void);
static uint32_t _getFlashChipRealSize(void);
static String _toMACAddressString(const uint8_t mac[]);

@ -61,6 +61,11 @@
#define AUTOCONNECT_MENULABEL_UPDATE "Update"
#endif // !AUTOCONNECT_MENULABEL_UPDATE
// Menu item: Device Info
#ifndef AUTOCONNECT_MENULABEL_DEVICEINFO
#define AUTOCONNECT_MENULABEL_DEVICEINFO "Device info"
#endif // !AUTOCONNECT_MENULABEL_DEVICEINFO
// Button label: RESET
#ifndef AUTOCONNECT_BUTTONLABEL_RESET
#define AUTOCONNECT_BUTTONLABEL_RESET "RESET"

@ -553,10 +553,10 @@ const char AutoConnect::_ELM_MENU_PRE[] PROGMEM = {
"<a href=\"BOOT_URI\" class=\"lb-brand\">MENU_TITLE</a>"
"<label class=\"lb-burger lb-burger-dblspin\" id=\"lb-burger\" for=\"lb-cb\"><span></span></label>"
"</li>"
"<li class=\"lb-item\"><a href=\"" AUTOCONNECT_URI_CONFIG "\">" AUTOCONNECT_MENULABEL_CONFIGNEW "</a></li>"
"<li class=\"lb-item\"><a href=\"" AUTOCONNECT_URI_OPEN "\">" AUTOCONNECT_MENULABEL_OPENSSIDS "</a></li>"
"<li class=\"lb-item\"><a href=\"" AUTOCONNECT_URI_DISCON "\">" AUTOCONNECT_MENULABEL_DISCONNECT "</a></li>"
"<li class=\"lb-item\" id=\"reset\"><a href=\"#rdlg\">" AUTOCONNECT_MENULABEL_RESET "</a></li>"
"MENU_CONFIGNEW"
"MENU_OPENSSIDS"
"MENU_DISCONNECT"
"MENU_RESET"
};
const char AutoConnect::_ELM_MENU_AUX[] PROGMEM = {
@ -564,7 +564,8 @@ const char AutoConnect::_ELM_MENU_AUX[] PROGMEM = {
};
const char AutoConnect::_ELM_MENU_POST[] PROGMEM = {
"<li class=\"lb-item\"><a href=\"HOME_URI\">" AUTOCONNECT_MENULABEL_HOME "</a></li>"
"MENU_HOME"
"MENU_DEVINFO"
"</ul>"
"</div>"
"<div class=\"lap\" id=\"rdlg\"><a href=\"#reset\" class=\"overlap\"></a>"
@ -972,6 +973,10 @@ String AutoConnect::_token_HEAD(PageArgument& args) {
String AutoConnect::_token_MENU_PRE(PageArgument& args) {
String currentMenu = FPSTR(_ELM_MENU_PRE);
currentMenu.replace(String(F("MENU_CONFIGNEW")), _attachMenuItem(AC_MENUITEM_CONFIGNEW));
currentMenu.replace(String(F("MENU_OPENSSIDS")), _attachMenuItem(AC_MENUITEM_OPENSSIDS));
currentMenu.replace(String(F("MENU_DISCONNECT")), _attachMenuItem(AC_MENUITEM_DISCONNECT));
currentMenu.replace(String(F("MENU_RESET")), _attachMenuItem(AC_MENUITEM_RESET));
currentMenu.replace(String(F("BOOT_URI")), _getBootUri());
currentMenu.replace(String(F("MENU_TITLE")), _menuTitle);
currentMenu.replace(String(F("{{CUR_SSID}}")), _token_ESTAB_SSID(args));
@ -988,7 +993,9 @@ String AutoConnect::_token_MENU_AUX(PageArgument& args) {
String AutoConnect::_token_MENU_POST(PageArgument& args) {
AC_UNUSED(args);
String postMenu = FPSTR(_ELM_MENU_POST);
postMenu.replace(String(F("MENU_HOME")), _attachMenuItem(AC_MENUITEM_HOME));
postMenu.replace(String(F("HOME_URI")), _apConfig.homeUri);
postMenu.replace(String(F("MENU_DEVINFO")), _attachMenuItem(AC_MENUITEM_DEVINFO));
return postMenu;
}
@ -1353,6 +1360,24 @@ String AutoConnect::_token_CURRENT_SSID(PageArgument& args) {
return ssid;
}
String AutoConnect::_attachMenuItem(const AC_MENUITEM_t item) {
String liItem = String(F("<li class=\"lb-item\""));
if (_apConfig.attachMenu & AC_MENUITEM_CONFIGNEW)
liItem += String(F("><a href=\"" AUTOCONNECT_URI_CONFIG "\">" AUTOCONNECT_MENULABEL_CONFIGNEW));
else if (_apConfig.attachMenu & AC_MENUITEM_OPENSSIDS)
liItem += String(F("><a href=\"" AUTOCONNECT_URI_OPEN "\">" AUTOCONNECT_MENULABEL_OPENSSIDS));
else if (_apConfig.attachMenu & AC_MENUITEM_DISCONNECT)
liItem += String(F("><a href=\"" AUTOCONNECT_URI_DISCON "\">" AUTOCONNECT_MENULABEL_DISCONNECT));
else if (_apConfig.attachMenu & AC_MENUITEM_RESET)
liItem += String(F(" id=\"reset\"><a href=\"#rdlg\">" AUTOCONNECT_MENULABEL_RESET));
else if (_apConfig.attachMenu & AC_MENUITEM_HOME)
liItem += String(F("><a href=\"HOME_URI\">" AUTOCONNECT_MENULABEL_HOME));
else if (_apConfig.attachMenu & AC_MENUITEM_DEVINFO)
liItem += String(F("><a href=\"" AUTOCONNECT_URI "\">" AUTOCONNECT_MENULABEL_DEVICEINFO));
liItem += String(F("</a></li>"));
return liItem;
}
/**
* This function dynamically build up the response pages that conform to
* the requested URI. A PageBuilder instance is stored in _responsePage
@ -1361,7 +1386,7 @@ String AutoConnect::_token_CURRENT_SSID(PageArgument& args) {
* @retval true A response page generated.
* @retval false Requested uri is not defined.
*/
PageElement* AutoConnect::_setupPage(String uri) {
PageElement* AutoConnect::_setupPage(String& uri) {
PageElement *elm = new PageElement();
// Restore menu title
@ -1396,7 +1421,7 @@ PageElement* AutoConnect::_setupPage(String uri) {
elm->addToken(String(FPSTR("CHIP_ID")), std::bind(&AutoConnect::_token_CHIP_ID, this, std::placeholders::_1));
elm->addToken(String(FPSTR("FREE_HEAP")), std::bind(&AutoConnect::_token_FREE_HEAP, this, std::placeholders::_1));
}
else if (uri == String(AUTOCONNECT_URI_CONFIG)) {
else if (uri == String(AUTOCONNECT_URI_CONFIG) && (_apConfig.attachMenu & AC_MENUITEM_CONFIGNEW)) {
// Setup /auto/config
elm->setMold(_PAGE_CONFIGNEW);
@ -1415,7 +1440,7 @@ PageElement* AutoConnect::_setupPage(String uri) {
elm->addToken(String(FPSTR("HIDDEN_COUNT")), std::bind(&AutoConnect::_token_HIDDEN_COUNT, this, std::placeholders::_1));
elm->addToken(String(FPSTR("CONFIG_IP")), std::bind(&AutoConnect::_token_CONFIG_STAIP, this, std::placeholders::_1));
}
else if (uri == String(AUTOCONNECT_URI_CONNECT)) {
else if (uri == String(AUTOCONNECT_URI_CONNECT) && (_apConfig.attachMenu & AC_MENUITEM_CONFIGNEW || _apConfig.attachMenu & AC_MENUITEM_OPENSSIDS)) {
// Setup /auto/connect
_menuTitle = FPSTR(AUTOCONNECT_MENUTEXT_CONNECTING);
@ -1429,7 +1454,7 @@ PageElement* AutoConnect::_setupPage(String uri) {
elm->addToken(String(FPSTR("MENU_POST")), std::bind(&AutoConnect::_token_MENU_POST, this, std::placeholders::_1));
elm->addToken(String(FPSTR("CUR_SSID")), std::bind(&AutoConnect::_token_CURRENT_SSID, this, std::placeholders::_1));
}
else if (uri == String(AUTOCONNECT_URI_OPEN)) {
else if (uri == String(AUTOCONNECT_URI_OPEN) && (_apConfig.attachMenu & AC_MENUITEM_OPENSSIDS)) {
// Setup /auto/open
elm->setMold(_PAGE_OPENCREDT);
@ -1443,7 +1468,7 @@ PageElement* AutoConnect::_setupPage(String uri) {
elm->addToken(String(FPSTR("MENU_POST")), std::bind(&AutoConnect::_token_MENU_POST, this, std::placeholders::_1));
elm->addToken(String(FPSTR("OPEN_SSID")), std::bind(&AutoConnect::_token_OPEN_SSID, this, std::placeholders::_1));
}
else if (uri == String(AUTOCONNECT_URI_DISCON)) {
else if (uri == String(AUTOCONNECT_URI_DISCON) && (_apConfig.attachMenu & AC_MENUITEM_DISCONNECT)) {
// Setup /auto/disc
_menuTitle = FPSTR(AUTOCONNECT_MENUTEXT_DISCONNECT);
@ -1455,7 +1480,7 @@ PageElement* AutoConnect::_setupPage(String uri) {
elm->addToken(String(FPSTR("MENU_PRE")), std::bind(&AutoConnect::_token_MENU_PRE, this, std::placeholders::_1));
elm->addToken(String(FPSTR("MENU_POST")), std::bind(&AutoConnect::_token_MENU_POST, this, std::placeholders::_1));
}
else if (uri == String(AUTOCONNECT_URI_RESET)) {
else if (uri == String(AUTOCONNECT_URI_RESET) && (_apConfig.attachMenu & AC_MENUITEM_RESET)) {
// Setup /auto/reset
elm->setMold(_PAGE_RESETTING);

Loading…
Cancel
Save