Amended reference to String

pull/41/head
Hieromon Ikasamo 6 years ago
parent fa73d4c999
commit 9b9bfc967c
  1. 26
      src/AutoConnect.cpp
  2. 3
      src/AutoConnect.h
  3. 1
      src/AutoConnectAux.cpp
  4. 4
      src/AutoConnectPage.cpp

@ -195,7 +195,7 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
} while (WiFi.softAPIP() != _apConfig.apip); } while (WiFi.softAPIP() != _apConfig.apip);
} }
_currentHostIP = WiFi.softAPIP(); _currentHostIP = WiFi.softAPIP();
AC_DBG("SoftAP %s/%s CH(%d) H(%d) IP:%s\n", _apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _apConfig.hidden, _currentHostIP.toString().c_str()); AC_DBG("SoftAP %s/%s Ch(%d) IP:%s %s\n", _apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _currentHostIP.toString().c_str(), _apConfig.hidden ? "hidden" : "");
// Fork to the exit routine that starts captive portal. // Fork to the exit routine that starts captive portal.
cs = _onDetectExit ? _onDetectExit(_currentHostIP) : true; cs = _onDetectExit ? _onDetectExit(_currentHostIP) : true;
@ -445,7 +445,7 @@ void AutoConnect::handleRequest() {
// An attempt to establish a new AP. // An attempt to establish a new AP.
int32_t ch = _connectCh == 0 ? _apConfig.channel : _connectCh; int32_t ch = _connectCh == 0 ? _apConfig.channel : _connectCh;
AC_DBG("Request(%d) for %s\n", (int)ch, reinterpret_cast<const char*>(_credential.ssid)); AC_DBG("Attempt:%s Ch(%d)\n", reinterpret_cast<const char*>(_credential.ssid), (int)ch);
WiFi.begin(reinterpret_cast<const char*>(_credential.ssid), reinterpret_cast<const char*>(_credential.password), ch); WiFi.begin(reinterpret_cast<const char*>(_credential.ssid), reinterpret_cast<const char*>(_credential.password), ch);
if (_waitForConnect(_connectTimeout) == WL_CONNECTED) { if (_waitForConnect(_connectTimeout) == WL_CONNECTED) {
if (WiFi.BSSID() != NULL) { if (WiFi.BSSID() != NULL) {
@ -677,7 +677,7 @@ String AutoConnect::_induceReset(PageArgument& args) {
*/ */
String AutoConnect::_induceDisconnect(PageArgument& args) { String AutoConnect::_induceDisconnect(PageArgument& args) {
_rfDisconnect = true; _rfDisconnect = true;
return String(""); return _emptyString;
} }
/** /**
@ -690,19 +690,20 @@ String AutoConnect::_induceDisconnect(PageArgument& args) {
*/ */
String AutoConnect::_induceConnect(PageArgument& args) { String AutoConnect::_induceConnect(PageArgument& args) {
// Retrieve credential from the post method content. // Retrieve credential from the post method content.
if (args.hasArg(AUTOCONNECT_PARAMID_CRED)) { if (args.hasArg(String(F(AUTOCONNECT_PARAMID_CRED)))) {
// Read from EEPROM // Read from EEPROM
AutoConnectCredential credential(_apConfig.boundaryOffset); AutoConnectCredential credential(_apConfig.boundaryOffset);
struct station_config entry; struct station_config entry;
credential.load(args.arg(AUTOCONNECT_PARAMID_CRED).c_str(), &entry); credential.load(args.arg(String(F(AUTOCONNECT_PARAMID_CRED))).c_str(), &entry);
strncpy(reinterpret_cast<char*>(_credential.ssid), reinterpret_cast<const char*>(entry.ssid), sizeof(_credential.ssid)); strncpy(reinterpret_cast<char*>(_credential.ssid), reinterpret_cast<const char*>(entry.ssid), sizeof(_credential.ssid));
strncpy(reinterpret_cast<char*>(_credential.password), reinterpret_cast<const char*>(entry.password), sizeof(_credential.password)); strncpy(reinterpret_cast<char*>(_credential.password), reinterpret_cast<const char*>(entry.password), sizeof(_credential.password));
AC_DBG("Credential loaded:%s\n", _credential.ssid); AC_DBG("Credential loaded:%s\n", _credential.ssid);
} }
else { else {
AC_DBG("Queried SSID:%s\n", args.arg(AUTOCONNECT_PARAMID_SSID).c_str());
// Credential had by the post parameter. // Credential had by the post parameter.
strncpy(reinterpret_cast<char*>(_credential.ssid), args.arg(AUTOCONNECT_PARAMID_SSID).c_str(), sizeof(_credential.ssid)); strncpy(reinterpret_cast<char*>(_credential.ssid), args.arg(String(F(AUTOCONNECT_PARAMID_SSID))).c_str(), sizeof(_credential.ssid));
strncpy(reinterpret_cast<char*>(_credential.password), args.arg(AUTOCONNECT_PARAMID_PASS).c_str(), sizeof(_credential.password)); strncpy(reinterpret_cast<char*>(_credential.password), args.arg(String(F(AUTOCONNECT_PARAMID_PASS))).c_str(), sizeof(_credential.password));
} }
// Determine the connection channel based on the scan result. // Determine the connection channel based on the scan result.
@ -743,7 +744,7 @@ String AutoConnect::_induceConnect(PageArgument& args) {
// _webServer->client().flush(); // _webServer->client().flush();
// _webServer->client().stop(); // _webServer->client().stop();
// _responsePage->cancel(); // _responsePage->cancel();
return String(""); return _emptyString;
} }
/** /**
@ -771,7 +772,7 @@ String AutoConnect::_invokeResult(PageArgument& args) {
_webServer->client().stop(); _webServer->client().stop();
_waitForEndTransmission(); // Wait for response transmission complete _waitForEndTransmission(); // Wait for response transmission complete
_responsePage->cancel(); _responsePage->cancel();
return String(""); return _emptyString;
} }
/** /**
@ -790,7 +791,7 @@ bool AutoConnect::_classifyHandle(HTTPMethod method, String uri) {
// If the current request argument contains AutoConnectElement, it is // If the current request argument contains AutoConnectElement, it is
// the form data of the AutoConnectAux page and with this timing save // the form data of the AutoConnectAux page and with this timing save
// the value of each element. // the value of each element.
if (_webServer->hasArg(AUTOCONNECT_AUXURI_PARAM)) { if (_webServer->hasArg(String(F(AUTOCONNECT_AUXURI_PARAM)))) {
_auxUri = _webServer->arg(AUTOCONNECT_AUXURI_PARAM); _auxUri = _webServer->arg(AUTOCONNECT_AUXURI_PARAM);
_auxUri.replace("&#47;", "/"); _auxUri.replace("&#47;", "/");
AutoConnectAux* aux = _aux.get(); AutoConnectAux* aux = _aux.get();
@ -980,3 +981,8 @@ void AutoConnect::_disconnectWiFi(bool wifiOff) {
yield(); yield();
} }
} }
/**
* Initialize an empty string to allow returning const String& with nothing.
*/
const String AutoConnect::_emptyString = String("");

@ -342,6 +342,9 @@ class AutoConnect {
String _token_BOOTURI(PageArgument& args); String _token_BOOTURI(PageArgument& args);
String _token_CURRENT_SSID(PageArgument& args); String _token_CURRENT_SSID(PageArgument& args);
private:
static const String _emptyString; /**< An empty string alloaction **/
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
friend class ESP8266WebServer; friend class ESP8266WebServer;
#elif defined(ARDUINO_ARCH_ESP32) #elif defined(ARDUINO_ARCH_ESP32)

@ -691,6 +691,7 @@ AutoConnectElement* AutoConnectAux::_createElement(const JsonObject& json) {
switch (_asElementType(type)) { switch (_asElementType(type)) {
case AC_Element: case AC_Element:
case AC_Unknown:
elm = new AutoConnectElement; elm = new AutoConnectElement;
break; break;
case AC_Button: { case AC_Button: {

@ -288,7 +288,7 @@ const char AutoConnect::_CSS_SPINNER[] PROGMEM = {
"width:100%;" "width:100%;"
"height:100%;" "height:100%;"
"border-radius:50%;" "border-radius:50%;"
"background-color:#333;" "background-color:#a2d9cd;"
"opacity:0.6;" "opacity:0.6;"
"position:absolute;" "position:absolute;"
"top:0;" "top:0;"
@ -1171,7 +1171,7 @@ String AutoConnect::_token_BOOTURI(PageArgument& args) {
else if (_apConfig.bootUri == AC_ONBOOTURI_HOME) else if (_apConfig.bootUri == AC_ONBOOTURI_HOME)
return _apConfig.homeUri.length() > 0 ? _apConfig.homeUri : String("/"); return _apConfig.homeUri.length() > 0 ? _apConfig.homeUri : String("/");
else else
return String(""); return _emptyString;
} }
String AutoConnect::_token_CURRENT_SSID(PageArgument& args) { String AutoConnect::_token_CURRENT_SSID(PageArgument& args) {

Loading…
Cancel
Save