Compare commits

...
1 Commits
Author SHA1 Message Date
Alex Tudorache 0f75d745fe 0.9 fixed encoding problems 2016-02-04 14:38:48 +02:00
5 changed files with 41 additions and 64 deletions
+4 -1
View File
@@ -238,7 +238,10 @@ If you connect to the created configuration Access Point but the configuration p
## Releases ## Releases
#### 0.8 #### 0.9
- fixed support for encoded characters in ssid/pass
##### 0.8
- made it compile on older versions of ESP8266 core as well, tested down to 2.0.0 - made it compile on older versions of ESP8266 core as well, tested down to 2.0.0
- added simple example for Custom IP - added simple example for Custom IP
+18 -46
View File
@@ -98,10 +98,6 @@ void WiFiManager::setupConfigPortal() {
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
server->begin(); // Web server start server->begin(); // Web server start
DEBUG_WM(F("HTTP server started")); DEBUG_WM(F("HTTP server started"));
/*
String ip = "10.1.2.3";
optionalIPFromString(&_sta_static_ip, ip.c_str());
DEBUG_WM(_sta_static_ip);*/
} }
@@ -134,6 +130,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) {
//setup AP //setup AP
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
DEBUG_WM("SET AP");
_apName = apName; _apName = apName;
_apPassword = apPassword; _apPassword = apPassword;
@@ -203,7 +200,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
} }
//check if we have ssid and pass and force those, if not, try with last saved values //check if we have ssid and pass and force those, if not, try with last saved values
if (ssid != "" && pass != "") { if (ssid != "") {
WiFi.begin(ssid.c_str(), pass.c_str()); WiFi.begin(ssid.c_str(), pass.c_str());
} else { } else {
DEBUG_WM("Using last saved values, should be faster"); DEBUG_WM("Using last saved values, should be faster");
@@ -213,10 +210,21 @@ int WiFiManager::connectWifi(String ssid, String pass) {
int connRes = WiFi.waitForConnectResult(); int connRes = WiFi.waitForConnectResult();
DEBUG_WM ("Connection result: "); DEBUG_WM ("Connection result: ");
DEBUG_WM ( connRes ); DEBUG_WM ( connRes );
//not connected, WPS enabled, no pass - first attempt
if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
startWPS();
//should be connected at the end of WPS
connRes = WiFi.waitForConnectResult();
}
return connRes; return connRes;
} }
void WiFiManager::startWPS() {
DEBUG_WM("START WPS");
WiFi.beginWPSConfig();
DEBUG_WM("END WPS");
}
/*
String WiFiManager::getSSID() { String WiFiManager::getSSID() {
if (_ssid == "") { if (_ssid == "") {
DEBUG_WM(F("Reading SSID")); DEBUG_WM(F("Reading SSID"));
@@ -236,47 +244,11 @@ String WiFiManager::getPassword() {
} }
return _pass; return _pass;
} }
*/
String WiFiManager::getConfigPortalSSID() { String WiFiManager::getConfigPortalSSID() {
return _apName; return _apName;
} }
String WiFiManager::urldecode(const char *src)
{
String decoded = "";
char a, b;
while (*src) {
if ((*src == '%') &&
((a = src[1]) && (b = src[2])) &&
(isxdigit(a) && isxdigit(b))) {
if (a >= 'a')
a -= 'a' - 'A';
if (a >= 'A')
a -= ('A' - 10);
else
a -= '0';
if (b >= 'a')
b -= 'a' - 'A';
if (b >= 'A')
b -= ('A' - 10);
else
b -= '0';
decoded += char(16 * a + b);
src += 3;
} else if (*src == '+') {
decoded += ' ';
*src++;
} else {
decoded += *src;
*src++;
}
}
decoded += '\0';
return decoded;
}
void WiFiManager::resetSettings() { void WiFiManager::resetSettings() {
DEBUG_WM(F("settings invalidated")); 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("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA."));
@@ -455,8 +427,8 @@ void WiFiManager::handleWifiSave() {
DEBUG_WM(F("WiFi save")); DEBUG_WM(F("WiFi save"));
//SAVE/connect here //SAVE/connect here
_ssid = urldecode(server->arg("s").c_str()); _ssid = server->arg("s").c_str();
_pass = urldecode(server->arg("p").c_str()); _pass = server->arg("p").c_str();
//parameters //parameters
for (int i = 0; i < _paramsCount; i++) { for (int i = 0; i < _paramsCount; i++) {
@@ -464,7 +436,7 @@ void WiFiManager::handleWifiSave() {
break; break;
} }
//read parameter //read parameter
String value = urldecode(server->arg(_params[i]->getID()).c_str()); String value = server->arg(_params[i]->getID()).c_str();
//store it in array //store it in array
value.toCharArray(_params[i]->_value, _params[i]->_length); value.toCharArray(_params[i]->_value, _params[i]->_length);
DEBUG_WM(F("Parameter")); DEBUG_WM(F("Parameter"));
+17 -15
View File
@@ -66,15 +66,13 @@ class WiFiManager
//if you want to always start the config portal, without trying to connect first //if you want to always start the config portal, without trying to connect first
boolean startConfigPortal(char const *apName, char const *apPassword = NULL); boolean startConfigPortal(char const *apName, char const *apPassword = NULL);
String getSSID(); //String getSSID();
String getPassword(); //String getPassword();
// get the AP name of the config portal, so it can be used in the callback // get the AP name of the config portal, so it can be used in the callback
String getConfigPortalSSID(); String getConfigPortalSSID();
void resetSettings(); void resetSettings();
//for convenience
String urldecode(const char*);
//sets timeout before webserver loop ends and exits even if there has been no setup. //sets timeout before webserver loop ends and exits even if there has been no setup.
//usefully for devices that failed to connect at some point and got stuck in a webserver loop //usefully for devices that failed to connect at some point and got stuck in a webserver loop
@@ -95,34 +93,38 @@ class WiFiManager
void addParameter(WiFiManagerParameter *p); void addParameter(WiFiManagerParameter *p);
//if this is set, it will exit after config, even if connection is unsucessful. //if this is set, it will exit after config, even if connection is unsucessful.
void setBreakAfterConfig(boolean shouldBreak); void setBreakAfterConfig(boolean shouldBreak);
//if this is set, try WPS setup when starting (this will delay config portal for up to 2 mins)
private: private:
std::unique_ptr<DNSServer> dnsServer; std::unique_ptr<DNSServer> dnsServer;
std::unique_ptr<ESP8266WebServer> server; std::unique_ptr<ESP8266WebServer> server;
const int WM_DONE = 0; //const int WM_DONE = 0;
const int WM_WAIT = 10; //const int WM_WAIT = 10;
//const String HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>"; //const String HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>";
void setupConfigPortal(); void setupConfigPortal();
void startWPS();
const char* _apName = "no-net";
const char* _apPassword = NULL;
String _ssid = "";
String _pass = "";
unsigned long timeout = 0;
unsigned long start = 0;
int _eepromStart;
const char* _apName = "no-net";
const char* _apPassword = NULL;
String _ssid = "";
String _pass = "";
unsigned long timeout = 0;
unsigned long start = 0;
IPAddress _ap_static_ip; IPAddress _ap_static_ip;
IPAddress _ap_static_gw; IPAddress _ap_static_gw;
IPAddress _ap_static_sn; IPAddress _ap_static_sn;
IPAddress _sta_static_ip; IPAddress _sta_static_ip;
IPAddress _sta_static_gw; IPAddress _sta_static_gw;
IPAddress _sta_static_sn; IPAddress _sta_static_sn;
int _paramsCount = 0;
int _minimumQuality = -1; int _paramsCount = 0;
int _minimumQuality = -1;
boolean _shouldBreakAfterConfig = false; boolean _shouldBreakAfterConfig = false;
boolean _tryWPS = false;
//String getEEPROMString(int start, int len); //String getEEPROMString(int start, int len);
//void setEEPROMString(int start, int len, String string); //void setEEPROMString(int start, int len, String string);
+1 -1
View File
@@ -9,5 +9,5 @@
}, },
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "espressif", "platforms": "espressif",
"version": "0.8" "version": "0.9"
} }
+1 -1
View File
@@ -1,5 +1,5 @@
name=WiFiManager name=WiFiManager
version=0.8 version=0.9
author=tzapu author=tzapu
maintainer=tzapu maintainer=tzapu
sentence=ESP8266 WiFi Connection manager with fallback web configuration portal sentence=ESP8266 WiFi Connection manager with fallback web configuration portal