Changed name of addMenuItem to append

enhance/v120
Hieromon Ikasamo 5 years ago
parent 6d0e30d382
commit abac1d0198
  1. 329
      src/AutoConnect.cpp
  2. 65
      src/AutoConnect.h
  3. 406
      src/AutoConnectPage.cpp

@ -367,16 +367,6 @@ bool AutoConnect::_getConfigSTA(station_config_t* config) {
return rc;
}
/**
* Put a user site's home URI.
* The URI specified by home is linked from "HOME" in the AutoConnect
* portal menu.
* @param uri A URI string of user site's home.
*/
void AutoConnect::home(const String& uri) {
_apConfig.homeUri = uri;
}
/**
* Stops AutoConnect captive portal service.
*/
@ -393,150 +383,18 @@ void AutoConnect::end(void) {
}
/**
* Returns the current hosted ESP8266WebServer.
*/
WebServerClass& AutoConnect::host(void) {
return *_webServer;
}
/**
* Returns AutoConnectAux instance of specified.
* @param uri An uri string.
* @return A pointer of AutoConnectAux instance.
*/
AutoConnectAux* AutoConnect::aux(const String& uri) const {
AutoConnectAux* aux_p = _aux;
while (aux_p) {
if (!strcmp(aux_p->uri(), uri.c_str()))
break;
aux_p = aux_p->_next;
}
return aux_p;
}
/**
* Append auxiliary pages made up with AutoConnectAux.
* @param aux A reference to AutoConnectAux that made up
* the auxiliary page to be added.
*/
void AutoConnect::join(AutoConnectAux& aux) {
if (_aux)
_aux->_concat(aux);
else
_aux = &aux;
aux._join(*this);
AC_DBG("%s on hands\n", aux.uri());
}
/**
* Append auxiliary pages made up with AutoConnectAux.
* @param aux A vector of reference to AutoConnectAux that made up
* the auxiliary page to be added.
*/
void AutoConnect::join(AutoConnectAuxVT auxVector) {
for (std::reference_wrapper<AutoConnectAux> aux : auxVector)
join(aux.get());
}
/**
* Creates an AutoConnectAux dynamically with the specified URI and
* integrates it into the menu. Returns false if a menu item with
* the same URI already exists.
* @param uri An uri of a new item to add
* @param title Title of the menu item
* @return true Added
* @return false The same item has existed.
*/
bool AutoConnect::addMenuItem(const String& uri, const String& title) {
AutoConnectAux* reg = aux(uri);
if (!reg) {
reg = new AutoConnectAux(uri, title);
join(*reg);
return true;
}
return false;
}
/**
* Creates an AutoConnectAux dynamically with the specified URI and
* integrates it into the menu. It will register the request handler
* for the WebServer after the addMenuItem works. It has similar
* efficacy to calling addMenuItem and WebSever::on at once.
* @param uri An uri of a new item to add
* @param title Title of the menu item
* @param handler Function of the request handler for WebServer class
* @return true Added
* @return false The same item has existed.
*/
bool AutoConnect::addMenuItem(const String& uri, const String& title, WebServerClass::THandlerFunction handler) {
if (_webServer) {
if (addMenuItem(uri, title)) {
_webServer->on(uri, handler);
return true;
}
}
return false;
}
/**
* Release a AutoConnectAux from the portal.
* @param uri An uri of the AutoConnectAux should be released
* @return true Specified AUX has released
* @return false Specified AUX not registered
*/
AutoConnectAux* AutoConnect::release(const String &uri) {
AutoConnectAux** self = &_aux;
while (*self) {
if (!strcmp((*self)->uri(), uri.c_str())) {
AC_DBG("%s released\n", (*self)->uri());
AutoConnectAux* ref = *self;
*self = (*self)->_next;
return ref;
}
self = &((*self)->_next);
}
return nullptr;
}
/**
* Starts Web server for AutoConnect service.
*/
void AutoConnect::_startWebServer(void) {
// Boot Web server
if (!_webServer) {
// Only when hosting WebServer internally
_webServer = WebserverUP(new WebServerClass(AUTOCONNECT_HTTPPORT), std::default_delete<WebServerClass>() );
AC_DBG("WebServer allocated\n");
}
// Discard the original the not found handler to redirect captive portal detection.
// It is supposed to evacuate but ESP8266WebServer::_notFoundHandler is not accessible.
_webServer->onNotFound(std::bind(&AutoConnect::_handleNotFound, this));
// here, Prepare PageBuilders for captive portal
if (!_responsePage) {
_responsePage.reset( new PageBuilder() );
_responsePage->exitCanHandle(std::bind(&AutoConnect::_classifyHandle, this, std::placeholders::_1, std::placeholders::_2));
_responsePage->onUpload(std::bind(&AutoConnect::_handleUpload, this, std::placeholders::_1, std::placeholders::_2));
_responsePage->insert(*_webServer);
_webServer->begin();
AC_DBG("http server started\n");
}
else {
AC_DBG("http server readied\n");
}
}
/**
* Starts DNS server for Captive portal.
* Get the total amount of memory required to hold the AutoConnect credentials
* and any custom configuration settings stored in EEPROM.
* This function is available only for ESP8266 use.
* @return Combined size of AutoConnect credentials and custom settings.
*/
void AutoConnect::_startDNSServer(void) {
// Boot DNS server, set up for captive portal redirection.
if (!_dnsServer) {
_dnsServer.reset(new DNSServer());
_dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
_dnsServer->start(AUTOCONNECT_DNSPORT, "*", WiFi.softAPIP());
AC_DBG("DNS server started\n");
}
uint16_t AutoConnect::getEEPROMUsedSize(void) {
#if defined(ARDUINO_ARCH_ESP8266)
AutoConnectCredential credentials(_apConfig.boundaryOffset);
return _apConfig.boundaryOffset + credentials.dataSize();
#elif defined(ARDUINO_ARCH_ESP32)
return 0;
#endif
}
/**
@ -684,6 +542,123 @@ void AutoConnect::handleRequest(void) {
}
}
/**
* Put a user site's home URI.
* The URI specified by home is linked from "HOME" in the AutoConnect
* portal menu.
* @param uri A URI string of user site's home.
*/
void AutoConnect::home(const String& uri) {
_apConfig.homeUri = uri;
}
/**
* Returns the current hosted ESP8266WebServer.
*/
WebServerClass& AutoConnect::host(void) {
return *_webServer;
}
/**
* Returns AutoConnectAux instance of specified.
* @param uri An uri string.
* @return A pointer of AutoConnectAux instance.
*/
AutoConnectAux* AutoConnect::aux(const String& uri) const {
AutoConnectAux* aux_p = _aux;
while (aux_p) {
if (!strcmp(aux_p->uri(), uri.c_str()))
break;
aux_p = aux_p->_next;
}
return aux_p;
}
/**
* Creates an AutoConnectAux dynamically with the specified URI and
* integrates it into the menu. Returns false if a menu item with
* the same URI already exists.
* @param uri An uri of a new item to add
* @param title Title of the menu item
* @return A pointer to an added AutoConnectAux
*/
AutoConnectAux* AutoConnect::append(const String& uri, const String& title) {
AutoConnectAux* reg = aux(uri);
if (!reg) {
reg = new AutoConnectAux(uri, title);
join(*reg);
return reg;
}
AC_DBG("%s has already listed\n", uri.c_str());
return nullptr;
}
/**
* Creates an AutoConnectAux dynamically with the specified URI and
* integrates it into the menu. It will register the request handler
* for the WebServer after the addMenuItem works. It has similar
* efficacy to calling addMenuItem and WebSever::on at once.
* @param uri An uri of a new item to add
* @param title Title of the menu item
* @param handler Function of the request handler for WebServer class
* @return true Added
* @return A pointer to an added AutoConnectAux
*/
AutoConnectAux* AutoConnect::append(const String& uri, const String& title, WebServerClass::THandlerFunction handler) {
if (_webServer) {
AutoConnectAux* reg = append(uri, title);
if (reg)
_webServer->on(uri, handler);
return reg;
}
return nullptr;
}
/**
* Detach a AutoConnectAux from the portal.
* @param uri An uri of the AutoConnectAux should be released
* @return true Specified AUX has released
* @return false Specified AUX not registered
*/
AutoConnectAux* AutoConnect::detach(const String &uri) {
AutoConnectAux** self = &_aux;
while (*self) {
if (!strcmp((*self)->uri(), uri.c_str())) {
AC_DBG("%s released\n", (*self)->uri());
AutoConnectAux* ref = *self;
*self = (*self)->_next;
return ref;
}
self = &((*self)->_next);
}
AC_DBG("%s not listed\n", uri.c_str());
return nullptr;
}
/**
* Append auxiliary pages made up with AutoConnectAux.
* @param aux A reference to AutoConnectAux that made up
* the auxiliary page to be added.
*/
void AutoConnect::join(AutoConnectAux& aux) {
if (_aux)
_aux->_concat(aux);
else
_aux = &aux;
aux._join(*this);
AC_DBG("%s on hands\n", aux.uri());
}
/**
* Append auxiliary pages made up with AutoConnectAux.
* @param aux A vector of reference to AutoConnectAux that made up
* the auxiliary page to be added.
*/
void AutoConnect::join(AutoConnectAuxVT auxVector) {
for (std::reference_wrapper<AutoConnectAux> aux : auxVector)
join(aux.get());
}
/**
* Register the exit routine for AutoConnectAux.
* @param uri Specify the URI of the AutoConnectAux page that
@ -832,18 +807,44 @@ bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_PRINCIPLE_t pr
}
/**
* Get the total amount of memory required to hold the AutoConnect credentials
* and any custom configuration settings stored in EEPROM.
* This function is available only for ESP8266 use.
* @return Combined size of AutoConnect credentials and custom settings.
* Starts Web server for AutoConnect service.
*/
uint16_t AutoConnect::getEEPROMUsedSize(void) {
#if defined(ARDUINO_ARCH_ESP8266)
AutoConnectCredential credentials(_apConfig.boundaryOffset);
return _apConfig.boundaryOffset + credentials.dataSize();
#elif defined(ARDUINO_ARCH_ESP32)
return 0;
#endif
void AutoConnect::_startWebServer(void) {
// Boot Web server
if (!_webServer) {
// Only when hosting WebServer internally
_webServer = WebserverUP(new WebServerClass(AUTOCONNECT_HTTPPORT), std::default_delete<WebServerClass>() );
AC_DBG("WebServer allocated\n");
}
// Discard the original the not found handler to redirect captive portal detection.
// It is supposed to evacuate but ESP8266WebServer::_notFoundHandler is not accessible.
_webServer->onNotFound(std::bind(&AutoConnect::_handleNotFound, this));
// here, Prepare PageBuilders for captive portal
if (!_responsePage) {
_responsePage.reset( new PageBuilder() );
_responsePage->exitCanHandle(std::bind(&AutoConnect::_classifyHandle, this, std::placeholders::_1, std::placeholders::_2));
_responsePage->onUpload(std::bind(&AutoConnect::_handleUpload, this, std::placeholders::_1, std::placeholders::_2));
_responsePage->insert(*_webServer);
_webServer->begin();
AC_DBG("http server started\n");
}
else {
AC_DBG("http server readied\n");
}
}
/**
* Starts DNS server for Captive portal.
*/
void AutoConnect::_startDNSServer(void) {
// Boot DNS server, set up for captive portal redirection.
if (!_dnsServer) {
_dnsServer.reset(new DNSServer());
_dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
_dnsServer->start(AUTOCONNECT_DNSPORT, "*", WiFi.softAPIP());
AC_DBG("DNS server started\n");
}
}
/**

@ -217,8 +217,6 @@ class AutoConnect {
AutoConnect();
AutoConnect(WebServerClass& webServer);
~AutoConnect();
AutoConnectAux* aux(const String& uri) const;
AutoConnectAux* release(const String& uri);
bool begin(void);
bool begin(const char* ssid, const char* passphrase = nullptr, unsigned long timeout = AUTOCONNECT_TIMEOUT);
bool config(AutoConnectConfig& Config);
@ -229,14 +227,17 @@ class AutoConnect {
void handleRequest(void);
void home(const String& uri);
WebServerClass& host(void);
String where(void) const { return _auxUri; }
AutoConnectAux* aux(const String& uri) const;
AutoConnectAux* append(const String& uri, const String& title);
AutoConnectAux* append(const String& uri, const String& title, WebServerClass::THandlerFunction handler);
AutoConnectAux* detach(const String& uri);
inline void disableMenu(const uint16_t items) { _apConfig.menuItems &= (0xffff ^ items); }
inline void enableMenu(const uint16_t items) { _apConfig.menuItems |= items; }
void join(AutoConnectAux& aux);
void join(AutoConnectAuxVT auxVector);
bool on(const String& uri, const AuxHandlerFunctionT handler, AutoConnectExitOrder_t order = AC_EXIT_AHEAD);
String where(void) const { return _auxUri; }
bool addMenuItem(const String& uri, const String& title);
bool addMenuItem(const String& uri, const String& title, WebServerClass::THandlerFunction handler);
inline void enableMenu(const uint16_t items) { _apConfig.menuItems |= items; }
inline void disableMenu(const uint16_t items) { _apConfig.menuItems &= (0xffff ^ items); }
/** For AutoConnectAux described in JSON */
#ifdef AUTOCONNECT_USE_JSON
@ -261,14 +262,14 @@ class AutoConnect {
bool _configSTA(const IPAddress& ip, const IPAddress& gateway, const IPAddress& netmask, const IPAddress& dns1, const IPAddress& dns2);
String _getBootUri(void);
bool _getConfigSTA(station_config_t* config);
void _startWebServer(void);
void _startDNSServer(void);
void _handleNotFound(void);
bool _loadAvailCredential(const char* ssid, const AC_PRINCIPLE_t principle = AC_PRINCIPLE_RECENT, const bool excludeCurrent = false);
bool _loadCurrentCredential(char* ssid, char* password, const AC_PRINCIPLE_t principle, const bool excludeCurrent);
void _startWebServer(void);
void _startDNSServer(void);
void _stopPortal(void);
bool _classifyHandle(HTTPMethod mothod, String uri);
void _handleUpload(const String& requestUri, const HTTPUpload& upload);
void _handleNotFound(void);
void _purgePages(void);
virtual PageElement* _setupPage(String& uri);
#ifdef AUTOCONNECT_USE_JSON
@ -352,13 +353,13 @@ class AutoConnect {
/** PageElements of AutoConnect site. */
static const char _CSS_BASE[] PROGMEM;
static const char _CSS_LUXBAR[] PROGMEM;
static const char _CSS_UL[] PROGMEM;
static const char _CSS_ICON_LOCK[] PROGMEM;
static const char _CSS_INPUT_BUTTON[] PROGMEM;
static const char _CSS_INPUT_TEXT[] PROGMEM;
static const char _CSS_TABLE[] PROGMEM;
static const char _CSS_SPINNER[] PROGMEM;
static const char _CSS_LUXBAR[] PROGMEM;
static const char _ELM_HTML_HEAD[] PROGMEM;
static const char _ELM_MENU_PRE[] PROGMEM;
static const char _ELM_MENU_AUX[] PROGMEM;
@ -381,41 +382,41 @@ class AutoConnect {
/** Token handlers for PageBuilder */
String _token_CSS_BASE(PageArgument& args);
String _token_CSS_UL(PageArgument& args);
String _token_CSS_ICON_LOCK(PageArgument& args);
String _token_CSS_INPUT_BUTTON(PageArgument& args);
String _token_CSS_INPUT_TEXT(PageArgument& args);
String _token_CSS_TABLE(PageArgument& args);
String _token_CSS_SPINNER(PageArgument& args);
String _token_CSS_LUXBAR(PageArgument& args);
String _token_HEAD(PageArgument& args);
String _token_MENU_PRE(PageArgument& args);
String _token_CSS_SPINNER(PageArgument& args);
String _token_CSS_TABLE(PageArgument& args);
String _token_CSS_UL(PageArgument& args);
String _token_MENU_AUX(PageArgument& args);
String _token_MENU_POST(PageArgument& args);
String _token_ESTAB_SSID(PageArgument& args);
String _token_WIFI_MODE(PageArgument& args);
String _token_WIFI_STATUS(PageArgument& args);
String _token_STATION_STATUS(PageArgument& args);
String _token_LOCAL_IP(PageArgument& args);
String _token_SOFTAP_IP(PageArgument& args);
String _token_GATEWAY(PageArgument& args);
String _token_NETMASK(PageArgument& args);
String _token_MENU_PRE(PageArgument& args);
String _token_AP_MAC(PageArgument& args);
String _token_STA_MAC(PageArgument& args);
String _token_BOOTURI(PageArgument& args);
String _token_CHANNEL(PageArgument& args);
String _token_DBM(PageArgument& args);
String _token_CHIP_ID(PageArgument& args);
String _token_CONFIG_STAIP(PageArgument& args);
String _token_CPU_FREQ(PageArgument& args);
String _token_CURRENT_SSID(PageArgument& args);
String _token_DBM(PageArgument& args);
String _token_ESTAB_SSID(PageArgument& args);
String _token_FLASH_SIZE(PageArgument& args);
String _token_CHIP_ID(PageArgument& args);
String _token_FREE_HEAP(PageArgument& args);
String _token_LIST_SSID(PageArgument& args);
String _token_SSID_COUNT(PageArgument& args);
String _token_GATEWAY(PageArgument& args);
String _token_HEAD(PageArgument& args);
String _token_HIDDEN_COUNT(PageArgument& args);
String _token_CONFIG_STAIP(PageArgument& args);
String _token_LIST_SSID(PageArgument& args);
String _token_LOCAL_IP(PageArgument& args);
String _token_NETMASK(PageArgument& args);
String _token_OPEN_SSID(PageArgument& args);
String _token_SOFTAP_IP(PageArgument& args);
String _token_SSID_COUNT(PageArgument& args);
String _token_STA_MAC(PageArgument& args);
String _token_STATION_STATUS(PageArgument& args);
String _token_UPTIME(PageArgument& args);
String _token_BOOTURI(PageArgument& args);
String _token_CURRENT_SSID(PageArgument& args);
String _token_WIFI_MODE(PageArgument& args);
String _token_WIFI_STATUS(PageArgument& args);
private:
static const String _emptyString; /**< An empty string allocation **/

@ -912,11 +912,6 @@ String AutoConnect::_token_CSS_BASE(PageArgument& args) {
return String(FPSTR(_CSS_BASE));
}
String AutoConnect::_token_CSS_UL(PageArgument& args) {
AC_UNUSED(args);
return String(FPSTR(_CSS_UL));
}
String AutoConnect::_token_CSS_ICON_LOCK(PageArgument& args) {
AC_UNUSED(args);
return String(FPSTR(_CSS_ICON_LOCK));
@ -932,9 +927,9 @@ String AutoConnect::_token_CSS_INPUT_TEXT(PageArgument& args) {
return String(FPSTR(_CSS_INPUT_TEXT));
}
String AutoConnect::_token_CSS_TABLE(PageArgument& args) {
String AutoConnect::_token_CSS_LUXBAR(PageArgument& args) {
AC_UNUSED(args);
return String(FPSTR(_CSS_TABLE));
return String(FPSTR(_CSS_LUXBAR));
}
String AutoConnect::_token_CSS_SPINNER(PageArgument& args) {
@ -942,9 +937,21 @@ String AutoConnect::_token_CSS_SPINNER(PageArgument& args) {
return String(FPSTR(_CSS_SPINNER));
}
String AutoConnect::_token_HEAD(PageArgument& args) {
String AutoConnect::_token_CSS_TABLE(PageArgument& args) {
AC_UNUSED(args);
return String(FPSTR(_ELM_HTML_HEAD));
return String(FPSTR(_CSS_TABLE));
}
String AutoConnect::_token_CSS_UL(PageArgument& args) {
AC_UNUSED(args);
return String(FPSTR(_CSS_UL));
}
String AutoConnect::_token_MENU_AUX(PageArgument& args) {
String menuItem = String("");
if (_aux)
menuItem = _aux->_injectMenu(args);
return menuItem;
}
String AutoConnect::_token_MENU_PRE(PageArgument& args) {
@ -960,13 +967,6 @@ String AutoConnect::_token_MENU_PRE(PageArgument& args) {
return currentMenu;
}
String AutoConnect::_token_MENU_AUX(PageArgument& args) {
String menuItem = String("");
if (_aux)
menuItem = _aux->_injectMenu(args);
return menuItem;
}
String AutoConnect::_token_MENU_POST(PageArgument& args) {
AC_UNUSED(args);
String postMenu = FPSTR(_ELM_MENU_POST);
@ -976,184 +976,115 @@ String AutoConnect::_token_MENU_POST(PageArgument& args) {
return postMenu;
}
String AutoConnect::_token_CSS_LUXBAR(PageArgument& args) {
String AutoConnect::_token_AP_MAC(PageArgument& args) {
AC_UNUSED(args);
return String(FPSTR(_CSS_LUXBAR));
uint8_t macAddress[6];
WiFi.softAPmacAddress(macAddress);
return AutoConnect::_toMACAddressString(macAddress);
}
String AutoConnect::_token_ESTAB_SSID(PageArgument& args) {
String AutoConnect::_token_BOOTURI(PageArgument& args) {
AC_UNUSED(args);
return (WiFi.status() == WL_CONNECTED ? WiFi.SSID() : String(F("N/A")));
return _getBootUri();
}
String AutoConnect::_token_WIFI_MODE(PageArgument& args) {
String AutoConnect::_token_CHANNEL(PageArgument& args) {
AC_UNUSED(args);
PGM_P wifiMode;
switch (WiFi.getMode()) {
case WIFI_OFF:
wifiMode = PSTR("OFF");
break;
case WIFI_STA:
wifiMode = PSTR("STA");
break;
case WIFI_AP:
wifiMode = PSTR("AP");
break;
case WIFI_AP_STA:
wifiMode = PSTR("AP_STA");
break;
#ifdef ARDUINO_ARCH_ESP32
case WIFI_MODE_MAX:
wifiMode = PSTR("MAX");
break;
#endif
default:
wifiMode = PSTR("experimental");
}
return String(FPSTR(wifiMode));
return String(WiFi.channel());
}
String AutoConnect::_token_WIFI_STATUS(PageArgument& args) {
String AutoConnect::_token_CHIP_ID(PageArgument& args) {
AC_UNUSED(args);
return String(WiFi.status());
return String(_getChipId());
}
String AutoConnect::_token_STATION_STATUS(PageArgument& args) {
String AutoConnect::_token_CONFIG_STAIP(PageArgument& args) {
AC_UNUSED(args);
PGM_P wlStatusSymbol = PSTR("");
// const char* wlStatusSymbol ="";
PGM_P wlStatusSymbols[] = {
// static const char* wlStatusSymbols[] = {
#if defined(ARDUINO_ARCH_ESP8266)
PSTR("IDLE"),
PSTR("CONNECTING"),
PSTR("WRONG_PASSWORD"),
PSTR("NO_AP_FOUND"),
PSTR("CONNECT_FAIL"),
PSTR("GOT_IP")
};
switch (wifi_station_get_connect_status()) {
case STATION_IDLE:
wlStatusSymbol = wlStatusSymbols[0];
break;
case STATION_CONNECTING:
wlStatusSymbol = wlStatusSymbols[1];
break;
case STATION_WRONG_PASSWORD:
wlStatusSymbol = wlStatusSymbols[2];
break;
case STATION_NO_AP_FOUND:
wlStatusSymbol = wlStatusSymbols[3];
break;
case STATION_CONNECT_FAIL:
wlStatusSymbol = wlStatusSymbols[4];
break;
case STATION_GOT_IP:
wlStatusSymbol = wlStatusSymbols[5];
break;
#elif defined(ARDUINO_ARCH_ESP32)
PSTR("IDLE"),
PSTR("NO_SSID_AVAIL"),
PSTR("SCAN_COMPLETED"),
PSTR("CONNECTED"),
PSTR("CONNECT_FAILED"),
PSTR("CONNECTION_LOST"),
PSTR("DISCONNECTED"),
PSTR("NO_SHIELD")
static const char _configIPList[] PROGMEM =
"<li class=\"exp\">"
"<label for=\"%s\">%s</label>"
"<input id=\"%s\" type=\"text\" name=\"%s\" value=\"%s\">"
"</li>";
struct _reps {
PGM_P lid;
PGM_P lbl;
} static const reps[] = {
{ PSTR(AUTOCONNECT_PARAMID_STAIP), PSTR("IP Address") },
{ PSTR(AUTOCONNECT_PARAMID_GTWAY), PSTR("Gateway") },
{ PSTR(AUTOCONNECT_PARAMID_NTMSK), PSTR("Netmask") },
{ PSTR(AUTOCONNECT_PARAMID_DNS1), PSTR("DNS1") },
{ PSTR(AUTOCONNECT_PARAMID_DNS2), PSTR("DNS2") }
};
switch (_rsConnect) {
case WL_IDLE_STATUS:
wlStatusSymbol = wlStatusSymbols[0];
break;
case WL_NO_SSID_AVAIL:
wlStatusSymbol = wlStatusSymbols[1];
break;
case WL_SCAN_COMPLETED:
wlStatusSymbol = wlStatusSymbols[2];
break;
case WL_CONNECTED:
wlStatusSymbol = wlStatusSymbols[3];
break;
case WL_CONNECT_FAILED:
wlStatusSymbol = wlStatusSymbols[4];
break;
case WL_CONNECTION_LOST:
wlStatusSymbol = wlStatusSymbols[5];
break;
case WL_DISCONNECTED:
wlStatusSymbol = wlStatusSymbols[6];
break;
case WL_NO_SHIELD:
wlStatusSymbol = wlStatusSymbols[7];
break;
#endif
}
return String("(") + String(_rsConnect) + String(") ") + String(FPSTR(wlStatusSymbol));
}
String AutoConnect::_token_LOCAL_IP(PageArgument& args) {
AC_UNUSED(args);
return WiFi.localIP().toString();
}
String AutoConnect::_token_SOFTAP_IP(PageArgument& args) {
AC_UNUSED(args);
return WiFi.softAPIP().toString();
}
char liCont[600];
char* liBuf = liCont;
String AutoConnect::_token_GATEWAY(PageArgument& args) {
AC_UNUSED(args);
return WiFi.gatewayIP().toString();
for (uint8_t i = 0; i < 5; i++) {
IPAddress* ip = nullptr;
if (i == 0)
ip = &_apConfig.staip;
else if (i == 1)
ip = &_apConfig.staGateway;
else if (i == 2)
ip = &_apConfig.staNetmask;
else if (i == 3)
ip = &_apConfig.dns1;
else if (i == 4)
ip = &_apConfig.dns2;
String ipStr = ip != nullptr ? ip->toString() : String(F("0.0.0.0"));
snprintf_P(liBuf, sizeof(liCont) - (liBuf - liCont), (PGM_P)_configIPList, reps[i].lid, reps[i].lbl, reps[i].lid, reps[i].lid, ipStr.c_str());
liBuf += strlen(liBuf);
}
return String(liCont);
}
String AutoConnect::_token_NETMASK(PageArgument& args) {
String AutoConnect::_token_CPU_FREQ(PageArgument& args) {
AC_UNUSED(args);
return WiFi.subnetMask().toString();
return String(ESP.getCpuFreqMHz());
}
String AutoConnect::_token_AP_MAC(PageArgument& args) {
String AutoConnect::_token_CURRENT_SSID(PageArgument& args) {
AC_UNUSED(args);
uint8_t macAddress[6];
WiFi.softAPmacAddress(macAddress);
return AutoConnect::_toMACAddressString(macAddress);
char ssid_c[sizeof(station_config_t::ssid) + 1];
*ssid_c = '\0';
strncat(ssid_c, reinterpret_cast<char*>(_credential.ssid), sizeof(ssid_c) - 1);
String ssid = String(ssid_c);
return ssid;
}
String AutoConnect::_token_STA_MAC(PageArgument& args) {
String AutoConnect::_token_DBM(PageArgument& args) {
AC_UNUSED(args);
uint8_t macAddress[6];
WiFi.macAddress(macAddress);
return AutoConnect::_toMACAddressString(macAddress);
int32_t dBm = WiFi.RSSI();
return (dBm == 31 ? String(F("N/A")) : String(dBm));
}
String AutoConnect::_token_CHANNEL(PageArgument& args) {
String AutoConnect::_token_ESTAB_SSID(PageArgument& args) {
AC_UNUSED(args);
return String(WiFi.channel());
return (WiFi.status() == WL_CONNECTED ? WiFi.SSID() : String(F("N/A")));
}
String AutoConnect::_token_DBM(PageArgument& args) {
String AutoConnect::_token_FLASH_SIZE(PageArgument& args) {
AC_UNUSED(args);
int32_t dBm = WiFi.RSSI();
return (dBm == 31 ? String(F("N/A")) : String(dBm));
return String(_getFlashChipRealSize());
}
String AutoConnect::_token_CPU_FREQ(PageArgument& args) {
String AutoConnect::_token_FREE_HEAP(PageArgument& args) {
AC_UNUSED(args);
return String(ESP.getCpuFreqMHz());
return String(_freeHeapSize);
}
String AutoConnect::_token_FLASH_SIZE(PageArgument& args) {
String AutoConnect::_token_GATEWAY(PageArgument& args) {
AC_UNUSED(args);
return String(_getFlashChipRealSize());
return WiFi.gatewayIP().toString();
}
String AutoConnect::_token_CHIP_ID(PageArgument& args) {
String AutoConnect::_token_HEAD(PageArgument& args) {
AC_UNUSED(args);
return String(_getChipId());
return String(FPSTR(_ELM_HTML_HEAD));
}
String AutoConnect::_token_FREE_HEAP(PageArgument& args) {
String AutoConnect::_token_HIDDEN_COUNT(PageArgument& args) {
AC_UNUSED(args);
return String(_freeHeapSize);
return String(_hiddenSSIDCount);
}
String AutoConnect::_token_LIST_SSID(PageArgument& args) {
@ -1226,53 +1157,14 @@ String AutoConnect::_token_LIST_SSID(PageArgument& args) {
return ssidListStr;
}
String AutoConnect::_token_SSID_COUNT(PageArgument& args) {
AC_UNUSED(args);
return String(_scanCount);
}
String AutoConnect::_token_HIDDEN_COUNT(PageArgument& args) {
String AutoConnect::_token_LOCAL_IP(PageArgument& args) {
AC_UNUSED(args);
return String(_hiddenSSIDCount);
return WiFi.localIP().toString();
}
String AutoConnect::_token_CONFIG_STAIP(PageArgument& args) {
String AutoConnect::_token_NETMASK(PageArgument& args) {
AC_UNUSED(args);
static const char _configIPList[] PROGMEM =
"<li class=\"exp\">"
"<label for=\"%s\">%s</label>"
"<input id=\"%s\" type=\"text\" name=\"%s\" value=\"%s\">"
"</li>";
struct _reps {
PGM_P lid;
PGM_P lbl;
} static const reps[] = {
{ PSTR(AUTOCONNECT_PARAMID_STAIP), PSTR("IP Address") },
{ PSTR(AUTOCONNECT_PARAMID_GTWAY), PSTR("Gateway") },
{ PSTR(AUTOCONNECT_PARAMID_NTMSK), PSTR("Netmask") },
{ PSTR(AUTOCONNECT_PARAMID_DNS1), PSTR("DNS1") },
{ PSTR(AUTOCONNECT_PARAMID_DNS2), PSTR("DNS2") }
};
char liCont[600];
char* liBuf = liCont;
for (uint8_t i = 0; i < 5; i++) {
IPAddress* ip = nullptr;
if (i == 0)
ip = &_apConfig.staip;
else if (i == 1)
ip = &_apConfig.staGateway;
else if (i == 2)
ip = &_apConfig.staNetmask;
else if (i == 3)
ip = &_apConfig.dns1;
else if (i == 4)
ip = &_apConfig.dns2;
String ipStr = ip != nullptr ? ip->toString() : String(F("0.0.0.0"));
snprintf_P(liBuf, sizeof(liCont) - (liBuf - liCont), (PGM_P)_configIPList, reps[i].lid, reps[i].lbl, reps[i].lid, reps[i].lid, ipStr.c_str());
liBuf += strlen(liBuf);
}
return String(liCont);
return WiFi.subnetMask().toString();
}
String AutoConnect::_token_OPEN_SSID(PageArgument& args) {
@ -1318,23 +1210,131 @@ String AutoConnect::_token_OPEN_SSID(PageArgument& args) {
return ssidList;
}
String AutoConnect::_token_SOFTAP_IP(PageArgument& args) {
AC_UNUSED(args);
return WiFi.softAPIP().toString();
}
String AutoConnect::_token_SSID_COUNT(PageArgument& args) {
AC_UNUSED(args);
return String(_scanCount);
}
String AutoConnect::_token_STA_MAC(PageArgument& args) {
AC_UNUSED(args);
uint8_t macAddress[6];
WiFi.macAddress(macAddress);
return AutoConnect::_toMACAddressString(macAddress);
}
String AutoConnect::_token_STATION_STATUS(PageArgument& args) {
AC_UNUSED(args);
PGM_P wlStatusSymbol = PSTR("");
// const char* wlStatusSymbol ="";
PGM_P wlStatusSymbols[] = {
// static const char* wlStatusSymbols[] = {
#if defined(ARDUINO_ARCH_ESP8266)
PSTR("IDLE"),
PSTR("CONNECTING"),
PSTR("WRONG_PASSWORD"),
PSTR("NO_AP_FOUND"),
PSTR("CONNECT_FAIL"),
PSTR("GOT_IP")
};
switch (wifi_station_get_connect_status()) {
case STATION_IDLE:
wlStatusSymbol = wlStatusSymbols[0];
break;
case STATION_CONNECTING:
wlStatusSymbol = wlStatusSymbols[1];
break;
case STATION_WRONG_PASSWORD:
wlStatusSymbol = wlStatusSymbols[2];
break;
case STATION_NO_AP_FOUND:
wlStatusSymbol = wlStatusSymbols[3];
break;
case STATION_CONNECT_FAIL:
wlStatusSymbol = wlStatusSymbols[4];
break;
case STATION_GOT_IP:
wlStatusSymbol = wlStatusSymbols[5];
break;
#elif defined(ARDUINO_ARCH_ESP32)
PSTR("IDLE"),
PSTR("NO_SSID_AVAIL"),
PSTR("SCAN_COMPLETED"),
PSTR("CONNECTED"),
PSTR("CONNECT_FAILED"),
PSTR("CONNECTION_LOST"),
PSTR("DISCONNECTED"),
PSTR("NO_SHIELD")
};
switch (_rsConnect) {
case WL_IDLE_STATUS:
wlStatusSymbol = wlStatusSymbols[0];
break;
case WL_NO_SSID_AVAIL:
wlStatusSymbol = wlStatusSymbols[1];
break;
case WL_SCAN_COMPLETED:
wlStatusSymbol = wlStatusSymbols[2];
break;
case WL_CONNECTED:
wlStatusSymbol = wlStatusSymbols[3];
break;
case WL_CONNECT_FAILED:
wlStatusSymbol = wlStatusSymbols[4];
break;
case WL_CONNECTION_LOST:
wlStatusSymbol = wlStatusSymbols[5];
break;
case WL_DISCONNECTED:
wlStatusSymbol = wlStatusSymbols[6];
break;
case WL_NO_SHIELD:
wlStatusSymbol = wlStatusSymbols[7];
break;
#endif
}
return String("(") + String(_rsConnect) + String(") ") + String(FPSTR(wlStatusSymbol));
}
String AutoConnect::_token_UPTIME(PageArgument& args) {
AC_UNUSED(args);
return String(_apConfig.uptime);
}
String AutoConnect::_token_BOOTURI(PageArgument& args) {
String AutoConnect::_token_WIFI_MODE(PageArgument& args) {
AC_UNUSED(args);
return _getBootUri();
PGM_P wifiMode;
switch (WiFi.getMode()) {
case WIFI_OFF:
wifiMode = PSTR("OFF");
break;
case WIFI_STA:
wifiMode = PSTR("STA");
break;
case WIFI_AP:
wifiMode = PSTR("AP");
break;
case WIFI_AP_STA:
wifiMode = PSTR("AP_STA");
break;
#ifdef ARDUINO_ARCH_ESP32
case WIFI_MODE_MAX:
wifiMode = PSTR("MAX");
break;
#endif
default:
wifiMode = PSTR("experimental");
}
return String(FPSTR(wifiMode));
}
String AutoConnect::_token_CURRENT_SSID(PageArgument& args) {
String AutoConnect::_token_WIFI_STATUS(PageArgument& args) {
AC_UNUSED(args);
char ssid_c[sizeof(station_config_t::ssid) + 1];
*ssid_c = '\0';
strncat(ssid_c, reinterpret_cast<char*>(_credential.ssid), sizeof(ssid_c) - 1);
String ssid = String(ssid_c);
return ssid;
return String(WiFi.status());
}
/**

Loading…
Cancel
Save