Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development and cleanup #313

Merged
merged 94 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
83c271f
initial commit, signal meter and secure icons
tablatronix Mar 25, 2016
6708ddf
remove debug
tablatronix Mar 25, 2016
fd27cef
remove debug
tablatronix Mar 25, 2016
74bccc0
adds better retina support
tablatronix Mar 25, 2016
7360be5
Merge remote-tracking branch 'refs/remotes/origin/feature_308_configp…
tablatronix Feb 8, 2017
c8455f5
Merge remote-tracking branch 'refs/remotes/tzapu/master'
tablatronix Feb 8, 2017
9c72bf9
cleaning up source, comments
tablatronix Feb 9, 2017
45a325b
fix validippassword
tablatronix Feb 9, 2017
2edd37e
oops typo
tablatronix Feb 9, 2017
c819d46
allow for empty password
tablatronix Feb 9, 2017
bd9c3b3
refactoring some larger functions
tablatronix Feb 10, 2017
e9b36f9
fix breakafterconfig
tablatronix Feb 10, 2017
65349cb
fix WL_IDLE_STATUS return values for compatibility
tablatronix Feb 10, 2017
1a44dd5
move apcallback to proper location
tablatronix Feb 10, 2017
0b0eb61
moving blocks
tablatronix Feb 10, 2017
612e18b
oops deleted a function
tablatronix Feb 10, 2017
004f222
do not wait for conx is no ssid
tablatronix Feb 10, 2017
29b2f02
Fix broken links
camelmasa Mar 20, 2017
ada93b7
fix for #362 - Setting Content-length explicitly - https://github.com…
May 3, 2017
5e92486
Merge pull request #334 from camelmasa/fix-broken-links
tzapu Jun 6, 2017
58eb711
Spelling fixes
scop Jul 9, 2017
eb4594c
Merge pull request #383 from scop/spelling
tzapu Jul 10, 2017
0de9d12
Merge pull request #363 from suculent/fix-content-length
tzapu Jul 10, 2017
9637d94
Improve wishlist in README
denisvm Jul 13, 2017
06d75bf
Update README.md
tzapu Jul 13, 2017
f9c4c87
Merge pull request #386 from denisvm/readme-wishlist
tzapu Jul 13, 2017
cee18a7
Update WiFiManager.h
Derek123456 Aug 22, 2017
68e32a1
Update WiFiManager.cpp
Derek123456 Aug 22, 2017
89af312
Merge pull request #398 from Derek123456/Derek123456-patch-1
tzapu Aug 22, 2017
179c030
comments, autoconnect fix
tablatronix Aug 27, 2017
0aecffc
fix configportal loop flow
tablatronix Aug 27, 2017
47d9082
testing non blocking portal
tablatronix Aug 27, 2017
75f34d9
Merge remote-tracking branch 'tzapu/master'
tablatronix Aug 27, 2017
cadf6b4
Merge remote-tracking branch 'upstream/master'
tablatronix Aug 27, 2017
68e3eb5
Merge branch 'master' into development
tablatronix Aug 27, 2017
c456380
renable blocking
tablatronix Aug 27, 2017
f258046
fix const char corruptions
tablatronix Aug 27, 2017
8592647
fraking tabs
tablatronix Aug 27, 2017
8185eaa
add blocking setter
tablatronix Aug 27, 2017
b62f488
Merge remote-tracking branch 'origin/feature-icons' into development
tablatronix Aug 29, 2017
d1ab6ec
left in debug
tablatronix Aug 29, 2017
04a9dda
testing mode and persistent presrvation
tablatronix Aug 29, 2017
9160b5b
maxlength null string fix
tablatronix Aug 30, 2017
63dd714
oops missed one pr#244
tablatronix Aug 30, 2017
606a1c3
removed escaped quotes
tablatronix Aug 30, 2017
66c653f
convert to post
tablatronix Aug 30, 2017
6e43c1e
change all forms to POST
tablatronix Aug 30, 2017
5f28843
Cleaned some html csss
tablatronix Aug 30, 2017
2c357d7
changing non form back to GET
tablatronix Aug 31, 2017
6525a0b
fixed comment wording
tablatronix Aug 31, 2017
a93b601
again
tablatronix Aug 31, 2017
81b37df
adds some style, clean up css, adds new tokens
tablatronix Sep 8, 2017
14ce250
Merge remote-tracking branch 'remotes/tzapu/development' into tzapu/d…
tablatronix Sep 8, 2017
69ddda0
Merge remote-tracking branch 'remotes/tzapu/development' into tzapu/d…
tablatronix Sep 8, 2017
985f811
style lists /info
tablatronix Sep 9, 2017
64798eb
pimped out info pagee
tablatronix Sep 11, 2017
c6f7ac0
added uptime to info
tablatronix Sep 14, 2017
e43a7d0
modify templates, remove placeholders
tablatronix Sep 14, 2017
37dbd66
add staticfield setter
tablatronix Sep 14, 2017
4d18bfb
abstracted outputters
tablatronix Sep 14, 2017
31ab2b6
ability to disable captiveportal
tablatronix Sep 14, 2017
80470fb
addd token precheck flags
tablatronix Sep 16, 2017
12de391
comments
tablatronix Sep 16, 2017
eee3fb7
#418 even more info
tablatronix Sep 16, 2017
8e710b9
disable ios safari tel links
tablatronix Sep 16, 2017
4592914
test ondemand webportal
tablatronix Sep 18, 2017
2aef134
use ip as title if not in captiveportal
tablatronix Sep 18, 2017
b151c19
add ondemandwebportal example
tablatronix Sep 18, 2017
db2a133
adds exit functionality to shutdown configportal/webportal
tablatronix Sep 25, 2017
cf51018
uninitialized abort caused immediate exit
mrbig Oct 16, 2017
342eacf
autoConnect did not return true on successfull connection
mrbig Oct 16, 2017
3d2453a
html for exit
tablatronix Oct 18, 2017
d7e3c8d
Merge pull request #5 from mrbig/development
tablatronix Oct 18, 2017
eb434a0
clean up handlexit feature
tablatronix Oct 18, 2017
df58574
adds verbose connection status enum strings
tablatronix Oct 18, 2017
d09aff2
fixing some reliability issues, testing
tablatronix Oct 27, 2017
ad6b8bd
add local enableSTA for toggling
tablatronix Oct 28, 2017
4763783
rename some functions
tablatronix Oct 28, 2017
e8c0b52
added ease, stabilize persistent modes, rename some functions
tablatronix Oct 29, 2017
52d5427
testing erase config polyfill
tablatronix Nov 1, 2017
a1050d0
fix some returns
tablatronix Nov 3, 2017
3fdf53b
adding debug for configportalhastimeout
tablatronix Nov 15, 2017
d6aec20
add debug 2 argument function
tablatronix Nov 15, 2017
0ae9ca3
adds _debugport stream ref
tablatronix Nov 16, 2017
fa05d2c
fix for configportal on wifisave fail
tablatronix Nov 16, 2017
9a57122
Added some info panel changes
tablatronix Nov 16, 2017
a702fa6
html validation fizes
tablatronix Nov 21, 2017
2f4015e
fix token replace invalid html
tablatronix Nov 21, 2017
648274a
oops left wrap test in
tablatronix Nov 21, 2017
0897c58
update examples w setConfigPortalTimeout
tablatronix Nov 28, 2017
d797638
fix setCaptivePortalEnable
tablatronix Jan 10, 2018
7625680
adds test of setCaptivePortalEnable to example
tablatronix Jan 10, 2018
1a61362
typo
tablatronix Jan 10, 2018
b266cd5
fix open tag on info
tablatronix Jan 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 98 additions & 50 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "WiFiManager.h"

// PARAMETERS

WiFiManagerParameter::WiFiManagerParameter(const char *custom) {
_id = NULL;
_placeholder = NULL;
Expand Down Expand Up @@ -64,9 +66,6 @@ const char* WiFiManagerParameter::getCustomHTML() {
return _customHTML;
}

WiFiManager::WiFiManager() {
}

void WiFiManager::addParameter(WiFiManagerParameter *p) {
if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS)
{
Expand All @@ -82,7 +81,11 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) {
DEBUG_WM(p->getID());
}

WiFiManager::WiFiManager() {
}

void WiFiManager::setupConfigPortal() {
// setup dns and web servers
dnsServer.reset(new DNSServer());
server.reset(new ESP8266WebServer(80));

Expand All @@ -91,36 +94,29 @@ void WiFiManager::setupConfigPortal() {

DEBUG_WM(F("Configuring access point... "));
DEBUG_WM(_apName);
if (_apPassword != NULL) {
if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) {
// fail passphrase to short or long!
DEBUG_WM(F("Invalid AccessPoint password. Ignoring"));
_apPassword = NULL;
}
DEBUG_WM(_apPassword);
}

//optional soft ip config
// setup optional soft AP static ip config
if (_ap_static_ip) {
DEBUG_WM(F("Custom AP IP/GW/Subnet"));
WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn);
}

// start soft AP with pass or anonymous
if (_apPassword != NULL) {
WiFi.softAP(_apName, _apPassword);//password option
} else {
WiFi.softAP(_apName);
}

delay(500); // Without delay I've seen the IP address blank
delay(500); // slight delay to make sure we have a password
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant ip address doh

DEBUG_WM(F("AP IP address: "));
DEBUG_WM(WiFi.softAPIP());

/* Setup the DNS server redirecting all the domains to the apIP */
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());

/* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */
/* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */
server->on("/", std::bind(&WiFiManager::handleRoot, this));
server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true));
server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false));
Expand All @@ -129,9 +125,9 @@ void WiFiManager::setupConfigPortal() {
server->on("/r", std::bind(&WiFiManager::handleReset, this));
//server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));

server->begin(); // Web server start
DEBUG_WM(F("HTTP server started"));

}

boolean WiFiManager::autoConnect() {
Expand All @@ -143,17 +139,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
DEBUG_WM(F(""));
DEBUG_WM(F("AutoConnect"));

// read eeprom for ssid and pass
// read eeprom for ssid and pass, deprecated
//String ssid = getSSID();
//String pass = getPassword();

// attempt to connect; should it fail, fall back to AP
// attempt to connect using saved settings, on fail fallback to AP config portal
WiFi.mode(WIFI_STA);

if (connectWifi("", "") == WL_CONNECTED) {
//connected
DEBUG_WM(F("IP Address:"));
DEBUG_WM(WiFi.localIP());
//connected
return true;
}

Expand All @@ -178,34 +174,38 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
WiFi.mode(WIFI_AP_STA);
DEBUG_WM("SET AP STA");

_apName = apName;
_apName = apName;
_apPassword = apPassword;
if(!validApPassword) return;

//notify we entered AP mode
// do AP callback if set
if ( _apcallback != NULL) {
_apcallback(this);
}

connect = false;

// init configportal
setupConfigPortal();

// blocking loop waiting for config
while(1){

// check if timeout
// check if timed out
if(configPortalHasTimeout()) break;

//DNS
//DNS handler
dnsServer->processNextRequest();
//HTTP
//HTTP handler
server->handleClient();


// Waiting for save...
if (connect) {
connect = false;
delay(2000);
DEBUG_WM(F("Connecting to new AP"));

// using user-provided _ssid, _pass in place of system-stored ssid and pass
// attempt sta connection to submitted _ssid, _pass
if (connectWifi(_ssid, _pass) != WL_CONNECTED) {
DEBUG_WM(F("Failed to connect."));
} else {
Expand Down Expand Up @@ -238,28 +238,32 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
return WiFi.status() == WL_CONNECTED;
}


int WiFiManager::connectWifi(String ssid, String pass) {
DEBUG_WM(F("Connecting as wifi client..."));

// check if we've got static_ip settings, if we do, use those.
// Setup static IP config if provided
if (_sta_static_ip) {
DEBUG_WM(F("Custom STA IP/GW/Subnet"));
WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
DEBUG_WM(WiFi.localIP());
}
//fix for auto connect racing issue

// fix for auto connect racing issue
// @todo why is this here, what issue?, should be making sure its actually ssid == ssid should it not?
if (WiFi.status() == WL_CONNECTED) {
DEBUG_WM("Already connected. Bailing out.");
DEBUG_WM("Already connected. Exiting");
return WL_CONNECTED;
}
//check if we have ssid and pass and force those, if not, try with last saved values

// if ssid argument provided connect to that
if (ssid != "") {
DEBUG_WM("Connecting to new AP");
WiFi.begin(ssid.c_str(), pass.c_str());
} else {
// connect using saved ssid if there is one
if (WiFi.SSID()) {
DEBUG_WM("Using last saved values, should be faster");
//trying to fix connection in progress hanging
DEBUG_WM("Connecting to saved AP");
// trying to fix connection in progress hanging, explain why ??
ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();
Expand All @@ -273,12 +277,15 @@ int WiFiManager::connectWifi(String ssid, String pass) {
int connRes = waitForConnectResult();
DEBUG_WM ("Connection result: ");
DEBUG_WM ( connRes );
//not connected, WPS enabled, no pass - first attempt

// do WPS, if WPS options enabled and not connected and no password was supplied
// @todo this seems like wrong place for this, is it a fallback or option?
if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
startWPS();
//should be connected at the end of WPS
// should be connected at the end of WPS
connRes = waitForConnectResult();
}

return connRes;
}

Expand Down Expand Up @@ -331,16 +338,20 @@ void WiFiManager::startWPS() {
return _pass;
}
*/

// GETTERS
String WiFiManager::getConfigPortalSSID() {
return _apName;
}

// SETTERS
void WiFiManager::resetSettings() {
DEBUG_WM(F("settings invalidated"));
DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA."));
DEBUG_WM(F("SETTINGS ERASED"));
DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.")); // @todo WHUT?
WiFi.disconnect(true);
//delay(200);
}

void WiFiManager::setTimeout(unsigned long seconds) {
setConfigPortalTimeout(seconds);
}
Expand Down Expand Up @@ -377,10 +388,14 @@ void WiFiManager::setBreakAfterConfig(boolean shouldBreak) {
_shouldBreakAfterConfig = shouldBreak;
}

/** Handle root or redirect to captive portal */


/**
* HTTPD CALLBACK root or redirect to captive portal
*/
void WiFiManager::handleRoot() {
DEBUG_WM(F("Handle root"));
if (captivePortal()) { // If caprive portal redirect instead of displaying the page.
if (captivePortal()) { // If captive portal redirect instead of displaying the page.
return;
}

Expand All @@ -401,7 +416,9 @@ void WiFiManager::handleRoot() {

}

/** Wifi config page handler */
/**
* HTTPD CALLBACK Wifi config page handler
*/
void WiFiManager::handleWifi(boolean scan) {

String page = FPSTR(HTTP_HEAD);
Expand Down Expand Up @@ -571,7 +588,9 @@ void WiFiManager::handleWifi(boolean scan) {
DEBUG_WM(F("Sent config page"));
}

/** Handle the WLAN save form and redirect to WLAN config page again */
/**
* HTTPD CALLBACK save form and redirect to WLAN config page again
*/
void WiFiManager::handleWifiSave() {
DEBUG_WM(F("WiFi save"));

Expand Down Expand Up @@ -629,7 +648,9 @@ void WiFiManager::handleWifiSave() {
connect = true; //signal ready to connect/reset
}

/** Handle the info page */
/**
* HTTPD CALLBACK info page
*/
void WiFiManager::handleInfo() {
DEBUG_WM(F("Info"));

Expand Down Expand Up @@ -669,7 +690,9 @@ void WiFiManager::handleInfo() {
DEBUG_WM(F("Sent info page"));
}

/** Handle the reset page */
/**
* HTTPD CALLBACK reset page
*/
void WiFiManager::handleReset() {
DEBUG_WM(F("Reset"));

Expand All @@ -689,17 +712,23 @@ void WiFiManager::handleReset() {
delay(2000);
}



//removed as mentioned here https://github.com/tzapu/WiFiManager/issues/114
/*void WiFiManager::handle204() {
/**
* HTTPD CALLBACK 204
* @note removed as mentioned here https://github.com/tzapu/WiFiManager/issues/114
*/
/*
void WiFiManager::handle204() {
DEBUG_WM(F("204 No Response"));
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
server->sendHeader("Pragma", "no-cache");
server->sendHeader("Expires", "-1");
server->send ( 204, "text/plain", "");
}*/
}
*/

/**
* HTTPD CALLBACK 404
*/
void WiFiManager::handleNotFound() {
if (captivePortal()) { // If captive portal redirect instead of displaying the error page.
return;
Expand All @@ -722,8 +751,11 @@ void WiFiManager::handleNotFound() {
server->send ( 404, "text/plain", message );
}


/** Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
/**
* HTTPD redirector
* Redirect to captive portal if we got a request for another domain.
* Return true in that case so the page handler do not try to handle the request again.
*/
boolean WiFiManager::captivePortal() {
if (!isIp(server->hostHeader()) ) {
DEBUG_WM(F("Request redirected to captive portal"));
Expand All @@ -735,6 +767,8 @@ boolean WiFiManager::captivePortal() {
return false;
}

// MORE SETTERS

//start up config portal callback
void WiFiManager::setAPCallback( void (*func)(WiFiManager* myWiFiManager) ) {
_apcallback = func;
Expand All @@ -755,7 +789,7 @@ void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) {
_removeDuplicateAPs = removeDuplicates;
}


// HELPERS

template <typename Generic>
void WiFiManager::DEBUG_WM(Generic text) {
Expand Down Expand Up @@ -798,3 +832,17 @@ String WiFiManager::toStringIp(IPAddress ip) {
res += String(((ip >> 8 * 3)) & 0xFF);
return res;
}

bool WiFiManager::validApPassword(){
// check that ap password is valid, return false
if (_apPassword != NULL) {
if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) {
DEBUG_WM(F("AccessPoint password is INVALID"));
_apPassword = NULL;
return false; // @todo FATAL or fallback to NULL ?
}
DEBUG_WM(F("AccessPoint Password is VALID"));
DEBUG_WM(_apPassword);
}
return true;
}
3 changes: 2 additions & 1 deletion WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ class WiFiManager
void handle204();
boolean captivePortal();
boolean configPortalHasTimeout();

boolean validApPassword();

// DNS server
const byte DNS_PORT = 53;

Expand Down