mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
Merge branch 'master' into esp32s2
This commit is contained in:
+89
-46
@@ -94,26 +94,26 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) {
|
||||
strncpy(_value, defaultValue, _length);
|
||||
}
|
||||
}
|
||||
const char* WiFiManagerParameter::getValue() {
|
||||
const char* WiFiManagerParameter::getValue() const {
|
||||
// Serial.println(printf("Address of _value is %p\n", (void *)_value));
|
||||
return _value;
|
||||
}
|
||||
const char* WiFiManagerParameter::getID() {
|
||||
const char* WiFiManagerParameter::getID() const {
|
||||
return _id;
|
||||
}
|
||||
const char* WiFiManagerParameter::getPlaceholder() {
|
||||
const char* WiFiManagerParameter::getPlaceholder() const {
|
||||
return _label;
|
||||
}
|
||||
const char* WiFiManagerParameter::getLabel() {
|
||||
const char* WiFiManagerParameter::getLabel() const {
|
||||
return _label;
|
||||
}
|
||||
int WiFiManagerParameter::getValueLength() {
|
||||
int WiFiManagerParameter::getValueLength() const {
|
||||
return _length;
|
||||
}
|
||||
int WiFiManagerParameter::getLabelPlacement() {
|
||||
int WiFiManagerParameter::getLabelPlacement() const {
|
||||
return _labelPlacement;
|
||||
}
|
||||
const char* WiFiManagerParameter::getCustomHTML() {
|
||||
const char* WiFiManagerParameter::getCustomHTML() const {
|
||||
return _customHTML;
|
||||
}
|
||||
|
||||
@@ -525,6 +525,7 @@ void WiFiManager::stopWebPortal() {
|
||||
}
|
||||
|
||||
boolean WiFiManager::configPortalHasTimeout(){
|
||||
if(!configPortalActive) return false;
|
||||
uint16_t logintvl = 30000; // how often to emit timeing out counter logging
|
||||
|
||||
// handle timeout portal client check
|
||||
@@ -714,7 +715,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
// if timed out or abort, break
|
||||
if(configPortalHasTimeout() || abort){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_DEV,F("configportal abort"));
|
||||
DEBUG_WM(DEBUG_DEV,F("configportal loop abort"));
|
||||
#endif
|
||||
shutdownConfigPortal();
|
||||
result = abort ? portalAbortResult : portalTimeoutResult; // false, false
|
||||
@@ -722,13 +723,16 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
}
|
||||
|
||||
state = processConfigPortal();
|
||||
|
||||
|
||||
// status change, break
|
||||
if(state != WL_IDLE_STATUS){
|
||||
result = (state == WL_CONNECTED); // true if connected
|
||||
DEBUG_WM(DEBUG_DEV,F("configportal loop break"));
|
||||
break;
|
||||
}
|
||||
|
||||
if(!configPortalActive) break;
|
||||
|
||||
yield(); // watchdog
|
||||
}
|
||||
|
||||
@@ -782,18 +786,23 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
}
|
||||
else{
|
||||
// attempt sta connection to submitted _ssid, _pass
|
||||
if (connectWifi(_ssid, _pass) == WL_CONNECTED) {
|
||||
|
||||
uint8_t res = connectWifi(_ssid, _pass, _connectonsave) == WL_CONNECTED;
|
||||
if (res || (!_connectonsave)) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(F("Connect to new AP [SUCCESS]"));
|
||||
DEBUG_WM(F("Got IP Address:"));
|
||||
DEBUG_WM(WiFi.localIP());
|
||||
if(!_connectonsave){
|
||||
DEBUG_WM(F("SAVED with no connect to new AP"));
|
||||
} else {
|
||||
DEBUG_WM(F("Connect to new AP [SUCCESS]"));
|
||||
DEBUG_WM(F("Got IP Address:"));
|
||||
DEBUG_WM(WiFi.localIP());
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( _savewificallback != NULL) {
|
||||
_savewificallback();
|
||||
}
|
||||
shutdownConfigPortal();
|
||||
if(!_connectonsave) return WL_IDLE_STATUS;
|
||||
return WL_CONNECTED; // CONNECT SUCCESS
|
||||
}
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -837,6 +846,10 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
* @return bool success (softapdisconnect)
|
||||
*/
|
||||
bool WiFiManager::shutdownConfigPortal(){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("shutdownConfigPortal"));
|
||||
#endif
|
||||
|
||||
if(webPortalActive) return false;
|
||||
|
||||
if(configPortalActive){
|
||||
@@ -863,9 +876,6 @@ bool WiFiManager::shutdownConfigPortal(){
|
||||
// https://github.com/esp8266/Arduino/issues/3793
|
||||
// [APdisconnect] set_config failed! *WM: disconnect configportal - softAPdisconnect failed
|
||||
// still no way to reproduce reliably
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("disconnect configportal"));
|
||||
#endif
|
||||
|
||||
bool ret = false;
|
||||
ret = WiFi.softAPdisconnect(false);
|
||||
@@ -887,6 +897,7 @@ bool WiFiManager::shutdownConfigPortal(){
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("wifi mode:"),getModeString(WiFi.getMode()));
|
||||
#endif
|
||||
configPortalActive = false;
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("configportal closed"));
|
||||
_end();
|
||||
return ret;
|
||||
}
|
||||
@@ -894,7 +905,7 @@ bool WiFiManager::shutdownConfigPortal(){
|
||||
// @todo refactor this up into seperate functions
|
||||
// one for connecting to flash , one for new client
|
||||
// clean up, flow is convoluted, and causes bugs
|
||||
uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client..."));
|
||||
#endif
|
||||
@@ -917,10 +928,10 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
}
|
||||
// if ssid argument provided connect to that
|
||||
if (ssid != "") {
|
||||
wifiConnectNew(ssid,pass);
|
||||
wifiConnectNew(ssid,pass,connect);
|
||||
if(_saveTimeout > 0){
|
||||
connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop
|
||||
}
|
||||
}
|
||||
else {
|
||||
connRes = waitForConnectResult(0);
|
||||
}
|
||||
@@ -968,17 +979,18 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
* @param String ssid
|
||||
* @param String pass
|
||||
* @return bool success
|
||||
* @return connect only save if false
|
||||
*/
|
||||
bool WiFiManager::wifiConnectNew(String ssid, String pass){
|
||||
bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){
|
||||
bool ret = false;
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(F("CONNECTED:"),WiFi.status() == WL_CONNECTED);
|
||||
// DEBUG_WM(DEBUG_DEV,F("CONNECTED: "),WiFi.status() == WL_CONNECTED ? "Y" : "NO");
|
||||
DEBUG_WM(F("Connecting to NEW AP:"),ssid);
|
||||
DEBUG_WM(DEBUG_DEV,F("Using Password:"),pass);
|
||||
#endif
|
||||
WiFi_enableSTA(true,storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default)
|
||||
WiFi.persistent(true);
|
||||
ret = WiFi.begin(ssid.c_str(), pass.c_str());
|
||||
ret = WiFi.begin(ssid.c_str(), pass.c_str(), 0, NULL, connect);
|
||||
WiFi.persistent(false);
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi begin failed"));
|
||||
@@ -1028,7 +1040,7 @@ bool WiFiManager::setSTAConfig(){
|
||||
#endif
|
||||
bool ret = true;
|
||||
if (_sta_static_ip) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS"));
|
||||
#endif
|
||||
if(_sta_static_dns) {
|
||||
@@ -1044,12 +1056,13 @@ bool WiFiManager::setSTAConfig(){
|
||||
ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
|
||||
}
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi config failed"));
|
||||
else DEBUG_WM(F("STA IP set:"),WiFi.localIP());
|
||||
#endif
|
||||
} else {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi config failed"));
|
||||
else DEBUG_WM(F("STA IP set:"),WiFi.localIP());
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping"));
|
||||
#endif
|
||||
}
|
||||
@@ -1172,13 +1185,16 @@ void WiFiManager::handleRequest() {
|
||||
// bool authenticateDigest(const String& username, const String& H1);
|
||||
// void requestAuthentication(HTTPAuthMethod mode = BASIC_AUTH, const char* realm = NULL, const String& authFailMsg = String("") );
|
||||
|
||||
// 2.3 NO AUTH available
|
||||
bool testauth = false;
|
||||
if(!testauth) return;
|
||||
|
||||
DEBUG_WM(DEBUG_DEV,F("DOING AUTH"));
|
||||
bool res = server->authenticate("admin","12345");
|
||||
if(!res){
|
||||
#ifndef WM_NOAUTH
|
||||
server->requestAuthentication(HTTPAuthMethod::BASIC_AUTH); // DIGEST_AUTH
|
||||
#endif
|
||||
DEBUG_WM(DEBUG_DEV,F("AUTH FAIL"));
|
||||
}
|
||||
}
|
||||
@@ -1202,7 +1218,8 @@ void WiFiManager::handleRoot() {
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->setContentLength(page.length());
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
// server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan
|
||||
if(_preloadwifiscan) WiFi_scanNetworks(_scancachetime,true); // preload wifiscan throttled, async
|
||||
@@ -1260,7 +1277,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
// server->close(); // testing reliability fix for content length mismatches during mutiple flood hits
|
||||
|
||||
@@ -1291,7 +1308,7 @@ void WiFiManager::handleParam(){
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -1635,7 +1652,7 @@ void WiFiManager::handleWiFiStatus(){
|
||||
#ifdef WM_JSTEST
|
||||
page = FPSTR(HTTP_JS);
|
||||
#endif
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
}
|
||||
|
||||
@@ -1650,7 +1667,7 @@ void WiFiManager::handleWifiSave() {
|
||||
handleRequest();
|
||||
|
||||
// @todo use new callback for before paramsaves
|
||||
if ( _presavecallback != NULL) {
|
||||
if (!_paramsInWifi && _presavecallback != NULL) {
|
||||
_presavecallback();
|
||||
}
|
||||
|
||||
@@ -1702,7 +1719,7 @@ void WiFiManager::handleWifiSave() {
|
||||
}
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
@@ -1729,7 +1746,7 @@ void WiFiManager::handleParamSave() {
|
||||
page += FPSTR(HTTP_PARAMSAVED);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -1880,7 +1897,7 @@ void WiFiManager::handleInfo() {
|
||||
page += FPSTR(HTTP_HELP);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -2022,11 +2039,13 @@ String WiFiManager::getInfoData(String id){
|
||||
}
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
#ifndef WM_NOSOFTAPSSID
|
||||
else if(id==F("apssid")){
|
||||
p = FPSTR(HTTP_INFO_apssid);
|
||||
p.replace(FPSTR(T_1),htmlEntities(WiFi.softAPSSID()));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
else if(id==F("apbssid")){
|
||||
p = FPSTR(HTTP_INFO_apbssid);
|
||||
p.replace(FPSTR(T_1),(String)WiFi.BSSIDstr());
|
||||
@@ -2103,7 +2122,7 @@ void WiFiManager::handleExit() {
|
||||
page += FPSTR(S_exiting); // @token exiting
|
||||
server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"));
|
||||
// ('Logout', 401, {'WWW-Authenticate': 'Basic realm="Login required"'})
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
delay(2000);
|
||||
abort = true;
|
||||
@@ -2121,7 +2140,7 @@ void WiFiManager::handleReset() {
|
||||
page += FPSTR(S_resetting); //@token resetting
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -2156,7 +2175,7 @@ void WiFiManager::handleErase(boolean opt) {
|
||||
}
|
||||
|
||||
page += FPSTR(HTTP_END);
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
if(ret){
|
||||
@@ -2189,7 +2208,7 @@ void WiFiManager::handleNotFound() {
|
||||
server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"));
|
||||
server->sendHeader(F("Pragma"), F("no-cache"));
|
||||
server->sendHeader(F("Expires"), F("-1"));
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(message.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(message.length()));
|
||||
server->send ( 404, FPSTR(HTTP_HEAD_CT2), message );
|
||||
}
|
||||
|
||||
@@ -2237,7 +2256,7 @@ void WiFiManager::handleClose(){
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose
|
||||
page += FPSTR(S_closing); // @token closing
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
}
|
||||
|
||||
@@ -2471,6 +2490,16 @@ void WiFiManager::setSaveConnectTimeout(unsigned long seconds) {
|
||||
_saveTimeout = seconds * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set save portal connect on save option,
|
||||
* if false, will only save credentials not connect
|
||||
* @access public
|
||||
* @param {[type]} bool connect [description]
|
||||
*/
|
||||
void WiFiManager::setSaveConnect(bool connect) {
|
||||
_connectonsave = connect;
|
||||
}
|
||||
|
||||
/**
|
||||
* [setDebugOutput description]
|
||||
* @access public
|
||||
@@ -2601,6 +2630,15 @@ void WiFiManager::setPreSaveConfigCallback( std::function<void()> func ) {
|
||||
_presavecallback = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* setPreOtaUpdateCallback, set a callback to fire before OTA update
|
||||
* @access public
|
||||
* @param {[type]} void (*func)(void)
|
||||
*/
|
||||
void WiFiManager::setPreOtaUpdateCallback( std::function<void()> func ) {
|
||||
_preotaupdatecallback = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* set custom head html
|
||||
* custom element will be added to head, eg. new style tag etc.
|
||||
@@ -3528,7 +3566,7 @@ void WiFiManager::handleUpdate() {
|
||||
page += FPSTR(HTTP_UPDATE);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
}
|
||||
@@ -3559,6 +3597,10 @@ void WiFiManager::handleUpdating(){
|
||||
if(_debug) Serial.setDebugOutput(true);
|
||||
uint32_t maxSketchSpace;
|
||||
|
||||
// Use new callback for before OTA update
|
||||
if (_preotaupdatecallback != NULL) {
|
||||
_preotaupdatecallback();
|
||||
}
|
||||
#ifdef ESP8266
|
||||
WiFiUDP::stopAll();
|
||||
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
@@ -3596,7 +3638,7 @@ void WiFiManager::handleUpdating(){
|
||||
else if (upload.status == UPLOAD_FILE_END) {
|
||||
if (Update.end(true)) { // true to set the size to the current progress
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("[OTA] OTA FILE END bytes: "), upload.totalSize);
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("\n\n[OTA] OTA FILE END bytes: "), upload.totalSize);
|
||||
// Serial.printf("Updated: %u bytes\r\nRebooting...\r\n", upload.totalSize);
|
||||
#endif
|
||||
}
|
||||
@@ -3622,6 +3664,7 @@ void WiFiManager::handleUpdateDone() {
|
||||
|
||||
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||
str.replace(FPSTR(T_t),_title);
|
||||
str.replace(FPSTR(T_v), configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading
|
||||
page += str;
|
||||
|
||||
@@ -3640,7 +3683,7 @@ void WiFiManager::handleUpdateDone() {
|
||||
}
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
delay(1000); // send page
|
||||
|
||||
Reference in New Issue
Block a user