0.9 fixed encoding problems

This commit is contained in:
Alex Tudorache
2016-02-04 14:38:48 +02:00
parent ba1aa5496d
commit 0f75d745fe
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
#### 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
- 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->begin(); // Web server start
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) {
//setup AP
WiFi.mode(WIFI_AP);
DEBUG_WM("SET AP");
_apName = apName;
_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
if (ssid != "" && pass != "") {
if (ssid != "") {
WiFi.begin(ssid.c_str(), pass.c_str());
} else {
DEBUG_WM("Using last saved values, should be faster");
@@ -213,10 +210,21 @@ int WiFiManager::connectWifi(String ssid, String pass) {
int connRes = WiFi.waitForConnectResult();
DEBUG_WM ("Connection result: ");
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;
}
void WiFiManager::startWPS() {
DEBUG_WM("START WPS");
WiFi.beginWPSConfig();
DEBUG_WM("END WPS");
}
/*
String WiFiManager::getSSID() {
if (_ssid == "") {
DEBUG_WM(F("Reading SSID"));
@@ -236,47 +244,11 @@ String WiFiManager::getPassword() {
}
return _pass;
}
*/
String WiFiManager::getConfigPortalSSID() {
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() {
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."));
@@ -455,8 +427,8 @@ void WiFiManager::handleWifiSave() {
DEBUG_WM(F("WiFi save"));
//SAVE/connect here
_ssid = urldecode(server->arg("s").c_str());
_pass = urldecode(server->arg("p").c_str());
_ssid = server->arg("s").c_str();
_pass = server->arg("p").c_str();
//parameters
for (int i = 0; i < _paramsCount; i++) {
@@ -464,7 +436,7 @@ void WiFiManager::handleWifiSave() {
break;
}
//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
value.toCharArray(_params[i]->_value, _params[i]->_length);
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
boolean startConfigPortal(char const *apName, char const *apPassword = NULL);
String getSSID();
String getPassword();
//String getSSID();
//String getPassword();
// get the AP name of the config portal, so it can be used in the callback
String getConfigPortalSSID();
void resetSettings();
//for convenience
String urldecode(const char*);
//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
@@ -95,34 +93,38 @@ class WiFiManager
void addParameter(WiFiManagerParameter *p);
//if this is set, it will exit after config, even if connection is unsucessful.
void setBreakAfterConfig(boolean shouldBreak);
//if this is set, try WPS setup when starting (this will delay config portal for up to 2 mins)
private:
std::unique_ptr<DNSServer> dnsServer;
std::unique_ptr<ESP8266WebServer> server;
const int WM_DONE = 0;
const int WM_WAIT = 10;
//const int WM_DONE = 0;
//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>";
void setupConfigPortal();
void startWPS();
int _eepromStart;
const char* _apName = "no-net";
const char* _apPassword = NULL;
String _ssid = "";
String _pass = "";
unsigned long timeout = 0;
unsigned long start = 0;
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_gw;
IPAddress _ap_static_sn;
IPAddress _sta_static_ip;
IPAddress _sta_static_gw;
IPAddress _sta_static_sn;
int _paramsCount = 0;
int _minimumQuality = -1;
int _paramsCount = 0;
int _minimumQuality = -1;
boolean _shouldBreakAfterConfig = false;
boolean _tryWPS = false;
//String getEEPROMString(int start, int len);
//void setEEPROMString(int start, int len, String string);
+1 -1
View File
@@ -9,5 +9,5 @@
},
"frameworks": "arduino",
"platforms": "espressif",
"version": "0.8"
"version": "0.9"
}
+1 -1
View File
@@ -1,5 +1,5 @@
name=WiFiManager
version=0.8
version=0.9
author=tzapu
maintainer=tzapu
sentence=ESP8266 WiFi Connection manager with fallback web configuration portal