diff --git a/README.md b/README.md
index a052fdf..f65dae2 100644
--- a/README.md
+++ b/README.md
@@ -289,6 +289,7 @@ works with the staging release ver. 1.6.5-1044-g170995a, built on Aug 10, 2015 o
The support and help I got from the community has been nothing short of phenomenal. I can't thank you guys enough. This is my first real attept in developing open source stuff and I must say, now I understand why people are so dedicated to it, it is because of all the wonderful people involved.
__THANK YOU__
+
[Shawn A](https://github.com/tablatronix)
[Maximiliano Duarte](https://github.com/domonetic)
diff --git a/WiFiManager.cpp b/WiFiManager.cpp
index 44cb18d..8014f66 100644
--- a/WiFiManager.cpp
+++ b/WiFiManager.cpp
@@ -12,8 +12,24 @@
#include "WiFiManager.h"
-
-WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, int rofield) {
+WiFiManagerParameter::WiFiManagerParameter(const char *custom) {
+ _id = NULL;
+ _placeholder = NULL;
+ _length = 0;
+ _value = NULL;
+
+ _customHTML = custom;
+}
+
+WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) {
+ init(id, placeholder, defaultValue, length, "");
+}
+
+WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) {
+ init(id, placeholder, defaultValue, length, custom);
+}
+
+void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) {
_id = id;
_placeholder = placeholder;
_length = length;
@@ -24,25 +40,8 @@ WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placehold
if (defaultValue != NULL) {
strncpy(_value, defaultValue, length);
}
- if (rofield == 0) {
- _rofield = " readonly";
- } else {
- _rofield = "";
- }
-}
-WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) {
- _id = id;
- _placeholder = placeholder;
- _length = length;
- _value = new char[length + 1];
- for (int i = 0; i < length; i++) {
- _value[i] = 0;
- }
- if (defaultValue != NULL) {
- strncpy(_value, defaultValue, length);
- }
- _rofield = "";
+ _customHTML = custom;
}
const char* WiFiManagerParameter::getValue() {
@@ -57,8 +56,8 @@ const char* WiFiManagerParameter::getPlaceholder() {
int WiFiManagerParameter::getValueLength() {
return _length;
}
-const char* WiFiManagerParameter::getRofield() {
- return _rofield;
+const char* WiFiManagerParameter::getCustomHTML() {
+ return _customHTML;
}
WiFiManager::WiFiManager() {
@@ -348,6 +347,7 @@ void WiFiManager::handleRoot() {
page.replace("{v}", "Options");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
+ page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += "
";
page += _apName;
@@ -367,6 +367,7 @@ void WiFiManager::handleWifi(boolean scan) {
page.replace("{v}", "Config ESP");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
+ page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
if (scan) {
@@ -379,11 +380,11 @@ void WiFiManager::handleWifi(boolean scan) {
//sort networks
/*int indices[n];
- for (int i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
indices[i] = i;
- }
+ }
- for (int i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
//int temp = indices[j];
@@ -392,19 +393,19 @@ void WiFiManager::handleWifi(boolean scan) {
std::swap(indices[i], indices[j]);
}
}
- }
+ }
*/
int indices[n];
for (int i = 0; i < n; i++) {
indices[i] = i;
}
- std::sort(indices, indices+n, [](const int & a, const int & b) -> bool
- {
- return WiFi.RSSI(a) > WiFi.RSSI(b);
+ std::sort(indices, indices + n, [](const int & a, const int & b) -> bool
+ {
+ return WiFi.RSSI(a) > WiFi.RSSI(b);
});
-
-
+
+
//display networks in page
for (int i = 0; i < n; i++) {
DEBUG_WM(WiFi.SSID(indices[i]));
@@ -443,13 +444,17 @@ void WiFiManager::handleWifi(boolean scan) {
}
String pitem = FPSTR(HTTP_FORM_PARAM);
- pitem.replace("{i}", _params[i]->getID());
- pitem.replace("{n}", _params[i]->getID());
- pitem.replace("{p}", _params[i]->getPlaceholder());
- snprintf(parLength, 2, "%d", _params[i]->getValueLength());
- pitem.replace("{l}", parLength);
- pitem.replace("{v}", _params[i]->getValue());
- pitem.replace("{r}", _params[i]->getRofield());
+ if (_params[i]->getID() != NULL) {
+ pitem.replace("{i}", _params[i]->getID());
+ pitem.replace("{n}", _params[i]->getID());
+ pitem.replace("{p}", _params[i]->getPlaceholder());
+ snprintf(parLength, 2, "%d", _params[i]->getValueLength());
+ pitem.replace("{l}", parLength);
+ pitem.replace("{v}", _params[i]->getValue());
+ pitem.replace("{c}", _params[i]->getCustomHTML());
+ } else {
+ pitem = _params[i]->getCustomHTML();
+ }
page += pitem;
}
@@ -546,6 +551,7 @@ void WiFiManager::handleWifiSave() {
page.replace("{v}", "Credentials Saved");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
+ page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += FPSTR(HTTP_SAVED);
page += FPSTR(HTTP_END);
@@ -565,6 +571,7 @@ void WiFiManager::handleInfo() {
page.replace("{v}", "Info");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
+ page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += F("");
page += F("- Chip ID
- ");
@@ -604,6 +611,7 @@ void WiFiManager::handleReset() {
page.replace("{v}", "Info");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
+ page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += F("Module will reset in a few seconds.");
page += FPSTR(HTTP_END);
@@ -671,6 +679,12 @@ void WiFiManager::setSaveConfigCallback( void (*func)(void) ) {
_savecallback = func;
}
+//sets a custom element to add to head, like a new style tag
+void WiFiManager::setCustomHeadElement(const char* element) {
+ _customHeadElement = element;
+}
+
+
template
diff --git a/WiFiManager.h b/WiFiManager.h
index a2fbba8..c9f1746 100644
--- a/WiFiManager.h
+++ b/WiFiManager.h
@@ -22,40 +22,42 @@
#include
-const char HTTP_200[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
-const char HTTP_HEAD[] PROGMEM = "{v}";
-const char HTTP_STYLE[] PROGMEM = "";
-const char HTTP_SCRIPT[] PROGMEM = "";
-const char HTTP_HEAD_END[] PROGMEM = "
";
-const char HTTP_PORTAL_OPTIONS[] PROGMEM = "
";
-const char HTTP_ITEM[] PROGMEM = "
";
+const char HTTP_200[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
+const char HTTP_HEAD[] PROGMEM = "
{v}";
+const char HTTP_STYLE[] PROGMEM = "";
+const char HTTP_SCRIPT[] PROGMEM = "";
+const char HTTP_HEAD_END[] PROGMEM = "
";
+const char HTTP_PORTAL_OPTIONS[] PROGMEM = "
";
+const char HTTP_ITEM[] PROGMEM = "
";
//const char HTTP_ITEM_PADLOCK[] PROGMEM = "

";
-const char HTTP_FORM_START[] PROGMEM = "
";
-const char HTTP_SCAN_LINK[] PROGMEM = "
";
-
-const char HTTP_SAVED[] PROGMEM = "
Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
";
-const char HTTP_END[] PROGMEM = "
";
+const char HTTP_FORM_START[] PROGMEM = "
";
+const char HTTP_SCAN_LINK[] PROGMEM = "
";
+const char HTTP_SAVED[] PROGMEM = "
Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
";
+const char HTTP_END[] PROGMEM = "
";
#define WIFI_MANAGER_MAX_PARAMS 10
class WiFiManagerParameter {
public:
+ WiFiManagerParameter(const char *custom);
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length);
- WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, int rofield);
+ WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
const char *getID();
const char *getValue();
const char *getPlaceholder();
int getValueLength();
- const char *getRofield();
+ const char *getCustomHTML();
private:
const char *_id;
const char *_placeholder;
char *_value;
int _length;
- const char *_rofield;
+ const char *_customHTML;
+
+ void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
friend class WiFiManager;
};
@@ -103,6 +105,10 @@ class WiFiManager
//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)
+ //TODO
+ //if this is set, customise style
+ void setCustomHeadElement(const char* element);
+
private:
std::unique_ptr dnsServer;
@@ -136,6 +142,8 @@ class WiFiManager
boolean _shouldBreakAfterConfig = false;
boolean _tryWPS = false;
+ const char* _customHeadElement = "";
+
//String getEEPROMString(int start, int len);
//void setEEPROMString(int start, int len, String string);
@@ -173,11 +181,11 @@ class WiFiManager
template
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
- return obj->fromString(s);
+ return obj->fromString(s);
}
auto optionalIPFromString(...) -> bool {
- DEBUG_WM("NO fromString METHOD ON IPAddress, you need ESP8266 core 2.1.0 or newer for Custom IP configuration to work.");
- return false;
+ DEBUG_WM("NO fromString METHOD ON IPAddress, you need ESP8266 core 2.1.0 or newer for Custom IP configuration to work.");
+ return false;
}
};