Update wifimanager to 0.14 (#252)
This commit is contained in:
1 parent
0134f9ab0e
commit
f0c0607919
11 files changed
+265
-74
No files matched your search
+15
-10
@@ -1,3 +1,5 @@
|
|||||||
|
## Current development going on here :arrow_right: [Development Branch](https://github.com/tzapu/WiFiManager/tree/development)
|
||||||
|
|
||||||
# WiFiManager
|
# WiFiManager
|
||||||
ESP8266 WiFi Connection manager with fallback web configuration portal
|
ESP8266 WiFi Connection manager with fallback web configuration portal
|
||||||
|
|
||||||
@@ -43,16 +45,19 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
|
|||||||
 
|
 
|
||||||
|
|
||||||
## Wishlist
|
## Wishlist
|
||||||
- ~~remove dependency on EEPROM library~~
|
- [x] remove dependency on EEPROM library
|
||||||
- ~~move HTML Strings to PROGMEM~~
|
- [x] move HTML Strings to PROGMEM
|
||||||
- ~~cleanup and streamline code~~ (although this is ongoing)
|
- [x] cleanup and streamline code (although this is ongoing)
|
||||||
- if timeout is set, extend it when a page is fetched in AP mode
|
- [x] if timeout is set, extend it when a page is fetched in AP mode
|
||||||
- ~~add ability to configure more parameters than ssid/password~~
|
- [x] add ability to configure more parameters than ssid/password
|
||||||
- ~~maybe allow setting ip of ESP after reboot~~
|
- [x] maybe allow setting ip of ESP after reboot
|
||||||
- ~~add to Arduino Library Manager~~
|
- [x] add to Arduino Library Manager
|
||||||
- ~~add to PlatformIO~~
|
- [x] add to PlatformIO
|
||||||
- add multiple sets of network credentials
|
- [ ] add multiple sets of network credentials
|
||||||
- ~~allow users to customize CSS~~
|
- [x] allow users to customize CSS
|
||||||
|
- [ ] ESP32 support or instructions
|
||||||
|
- [ ] rewrite documentation for simplicity, based on scenarios/goals
|
||||||
|
- [ ] rely on the SDK's built in auto connect more than forcing a connect
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
inspired by:
|
inspired by:
|
||||||
http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||||
https://github.com/chriscook8/esp-arduino-apboot
|
https://github.com/chriscook8/esp-arduino-apboot
|
||||||
https://github.com/esp8266/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/DNSServer/examples/CaptivePortalAdvanced
|
https://github.com/esp8266/Arduino/tree/master/libraries/DNSServer/examples/CaptivePortalAdvanced
|
||||||
Built by AlexT https://github.com/tzapu
|
Built by AlexT https://github.com/tzapu
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
@@ -34,7 +34,7 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c
|
|||||||
_placeholder = placeholder;
|
_placeholder = placeholder;
|
||||||
_length = length;
|
_length = length;
|
||||||
_value = new char[length + 1];
|
_value = new char[length + 1];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length + 1; i++) {
|
||||||
_value[i] = 0;
|
_value[i] = 0;
|
||||||
}
|
}
|
||||||
if (defaultValue != NULL) {
|
if (defaultValue != NULL) {
|
||||||
@@ -44,6 +44,12 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c
|
|||||||
_customHTML = custom;
|
_customHTML = custom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WiFiManagerParameter::~WiFiManagerParameter() {
|
||||||
|
if (_value != NULL) {
|
||||||
|
delete[] _value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char* WiFiManagerParameter::getValue() {
|
const char* WiFiManagerParameter::getValue() {
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
@@ -60,14 +66,42 @@ const char* WiFiManagerParameter::getCustomHTML() {
|
|||||||
return _customHTML;
|
return _customHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WiFiManager::WiFiManager() {
|
WiFiManager::WiFiManager() {
|
||||||
|
_max_params = WIFI_MANAGER_MAX_PARAMS;
|
||||||
|
_params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*));
|
||||||
|
}
|
||||||
|
|
||||||
|
WiFiManager::~WiFiManager()
|
||||||
|
{
|
||||||
|
if (_params != NULL)
|
||||||
|
{
|
||||||
|
DEBUG_WM(F("freeing allocated params!"));
|
||||||
|
free(_params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||||
|
if(_paramsCount + 1 > _max_params)
|
||||||
|
{
|
||||||
|
// rezise the params array
|
||||||
|
_max_params += WIFI_MANAGER_MAX_PARAMS;
|
||||||
|
DEBUG_WM(F("Increasing _max_params to:"));
|
||||||
|
DEBUG_WM(_max_params);
|
||||||
|
WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*));
|
||||||
|
if (new_params != NULL) {
|
||||||
|
_params = new_params;
|
||||||
|
} else {
|
||||||
|
DEBUG_WM(F("ERROR: failed to realloc params, size not increased!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiFiManager::addParameter(WiFiManagerParameter *p) {
|
|
||||||
_params[_paramsCount] = p;
|
_params[_paramsCount] = p;
|
||||||
_paramsCount++;
|
_paramsCount++;
|
||||||
DEBUG_WM("Adding parameter");
|
DEBUG_WM(F("Adding parameter"));
|
||||||
DEBUG_WM(p->getID());
|
DEBUG_WM(p->getID());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiFiManager::setupConfigPortal() {
|
void WiFiManager::setupConfigPortal() {
|
||||||
@@ -109,14 +143,14 @@ void WiFiManager::setupConfigPortal() {
|
|||||||
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
|
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
|
||||||
|
|
||||||
/* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */
|
/* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */
|
||||||
server->on("/", std::bind(&WiFiManager::handleRoot, this));
|
server->on(String(F("/")), std::bind(&WiFiManager::handleRoot, this));
|
||||||
server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true));
|
server->on(String(F("/wifi")), std::bind(&WiFiManager::handleWifi, this, true));
|
||||||
server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false));
|
server->on(String(F("/0wifi")), std::bind(&WiFiManager::handleWifi, this, false));
|
||||||
server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this));
|
server->on(String(F("/wifisave")), std::bind(&WiFiManager::handleWifiSave, this));
|
||||||
server->on("/i", std::bind(&WiFiManager::handleInfo, this));
|
server->on(String(F("/i")), std::bind(&WiFiManager::handleInfo, this));
|
||||||
server->on("/r", std::bind(&WiFiManager::handleReset, this));
|
server->on(String(F("/r")), std::bind(&WiFiManager::handleReset, this));
|
||||||
//server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check.
|
//server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check.
|
||||||
server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
|
server->on(String(F("/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->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"));
|
||||||
@@ -149,10 +183,34 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
|||||||
return startConfigPortal(apName, apPassword);
|
return startConfigPortal(apName, apPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean WiFiManager::configPortalHasTimeout(){
|
||||||
|
if(_configPortalTimeout == 0 || wifi_softap_get_station_num() > 0){
|
||||||
|
_configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (millis() > _configPortalStart + _configPortalTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean WiFiManager::startConfigPortal() {
|
||||||
|
String ssid = "ESP" + String(ESP.getChipId());
|
||||||
|
return startConfigPortal(ssid.c_str(), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) {
|
boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) {
|
||||||
|
|
||||||
|
if(!WiFi.isConnected()){
|
||||||
|
WiFi.persistent(false);
|
||||||
|
// disconnect sta, start ap
|
||||||
|
WiFi.disconnect(); // this alone is not enough to stop the autoconnecter
|
||||||
|
WiFi.mode(WIFI_AP);
|
||||||
|
WiFi.persistent(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
//setup AP
|
//setup AP
|
||||||
WiFi.mode(WIFI_AP_STA);
|
WiFi.mode(WIFI_AP_STA);
|
||||||
DEBUG_WM("SET AP STA");
|
DEBUG_WM(F("SET AP STA"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_apName = apName;
|
_apName = apName;
|
||||||
_apPassword = apPassword;
|
_apPassword = apPassword;
|
||||||
@@ -165,7 +223,11 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
|||||||
connect = false;
|
connect = false;
|
||||||
setupConfigPortal();
|
setupConfigPortal();
|
||||||
|
|
||||||
while (_configPortalTimeout == 0 || millis() < _configPortalStart + _configPortalTimeout) {
|
while(1){
|
||||||
|
|
||||||
|
// check if timeout
|
||||||
|
if(configPortalHasTimeout()) break;
|
||||||
|
|
||||||
//DNS
|
//DNS
|
||||||
dnsServer->processNextRequest();
|
dnsServer->processNextRequest();
|
||||||
//HTTP
|
//HTTP
|
||||||
@@ -222,7 +284,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
|||||||
}
|
}
|
||||||
//fix for auto connect racing issue
|
//fix for auto connect racing issue
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
DEBUG_WM("Already connected. Bailing out.");
|
DEBUG_WM(F("Already connected. Bailing out."));
|
||||||
return WL_CONNECTED;
|
return WL_CONNECTED;
|
||||||
}
|
}
|
||||||
//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
|
||||||
@@ -230,7 +292,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
|||||||
WiFi.begin(ssid.c_str(), pass.c_str());
|
WiFi.begin(ssid.c_str(), pass.c_str());
|
||||||
} else {
|
} else {
|
||||||
if (WiFi.SSID()) {
|
if (WiFi.SSID()) {
|
||||||
DEBUG_WM("Using last saved values, should be faster");
|
DEBUG_WM(F("Using last saved values, should be faster"));
|
||||||
//trying to fix connection in progress hanging
|
//trying to fix connection in progress hanging
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
wifi_station_disconnect();
|
wifi_station_disconnect();
|
||||||
@@ -238,7 +300,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
|||||||
|
|
||||||
WiFi.begin();
|
WiFi.begin();
|
||||||
} else {
|
} else {
|
||||||
DEBUG_WM("No saved credentials");
|
DEBUG_WM(F("No saved credentials"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,11 +308,13 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
|||||||
DEBUG_WM ("Connection result: ");
|
DEBUG_WM ("Connection result: ");
|
||||||
DEBUG_WM ( connRes );
|
DEBUG_WM ( connRes );
|
||||||
//not connected, WPS enabled, no pass - first attempt
|
//not connected, WPS enabled, no pass - first attempt
|
||||||
|
#ifdef NO_EXTRA_4K_HEAP
|
||||||
if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
|
if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
|
||||||
startWPS();
|
startWPS();
|
||||||
//should be connected at the end of WPS
|
//should be connected at the end of WPS
|
||||||
connRes = waitForConnectResult();
|
connRes = waitForConnectResult();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return connRes;
|
return connRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,9 +342,9 @@ uint8_t WiFiManager::waitForConnectResult() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WiFiManager::startWPS() {
|
void WiFiManager::startWPS() {
|
||||||
DEBUG_WM("START WPS");
|
DEBUG_WM(F("START WPS"));
|
||||||
WiFi.beginWPSConfig();
|
WiFi.beginWPSConfig();
|
||||||
DEBUG_WM("END WPS");
|
DEBUG_WM(F("END WPS"));
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
String WiFiManager::getSSID() {
|
String WiFiManager::getSSID() {
|
||||||
@@ -362,13 +426,14 @@ void WiFiManager::handleRoot() {
|
|||||||
page += FPSTR(HTTP_STYLE);
|
page += FPSTR(HTTP_STYLE);
|
||||||
page += _customHeadElement;
|
page += _customHeadElement;
|
||||||
page += FPSTR(HTTP_HEAD_END);
|
page += FPSTR(HTTP_HEAD_END);
|
||||||
page += "<h1>";
|
page += String(F("<h1>"));
|
||||||
page += _apName;
|
page += _apName;
|
||||||
page += "</h1>";
|
page += String(F("</h1>"));
|
||||||
page += F("<h3>WiFiManager</h3>");
|
page += String(F("<h3>WiFiManager</h3>"));
|
||||||
page += FPSTR(HTTP_PORTAL_OPTIONS);
|
page += FPSTR(HTTP_PORTAL_OPTIONS);
|
||||||
page += FPSTR(HTTP_END);
|
page += FPSTR(HTTP_END);
|
||||||
|
|
||||||
|
server->sendHeader("Content-Length", String(page.length()));
|
||||||
server->send(200, "text/html", page);
|
server->send(200, "text/html", page);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -459,7 +524,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
page += FPSTR(HTTP_FORM_START);
|
page += FPSTR(HTTP_FORM_START);
|
||||||
char parLength[2];
|
char parLength[5];
|
||||||
// add the extra parameters to the form
|
// add the extra parameters to the form
|
||||||
for (int i = 0; i < _paramsCount; i++) {
|
for (int i = 0; i < _paramsCount; i++) {
|
||||||
if (_params[i] == NULL) {
|
if (_params[i] == NULL) {
|
||||||
@@ -471,7 +536,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
|||||||
pitem.replace("{i}", _params[i]->getID());
|
pitem.replace("{i}", _params[i]->getID());
|
||||||
pitem.replace("{n}", _params[i]->getID());
|
pitem.replace("{n}", _params[i]->getID());
|
||||||
pitem.replace("{p}", _params[i]->getPlaceholder());
|
pitem.replace("{p}", _params[i]->getPlaceholder());
|
||||||
snprintf(parLength, 2, "%d", _params[i]->getValueLength());
|
snprintf(parLength, 5, "%d", _params[i]->getValueLength());
|
||||||
pitem.replace("{l}", parLength);
|
pitem.replace("{l}", parLength);
|
||||||
pitem.replace("{v}", _params[i]->getValue());
|
pitem.replace("{v}", _params[i]->getValue());
|
||||||
pitem.replace("{c}", _params[i]->getCustomHTML());
|
pitem.replace("{c}", _params[i]->getCustomHTML());
|
||||||
@@ -522,6 +587,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
|||||||
|
|
||||||
page += FPSTR(HTTP_END);
|
page += FPSTR(HTTP_END);
|
||||||
|
|
||||||
|
server->sendHeader("Content-Length", String(page.length()));
|
||||||
server->send(200, "text/html", page);
|
server->send(200, "text/html", page);
|
||||||
|
|
||||||
|
|
||||||
@@ -544,7 +610,7 @@ void WiFiManager::handleWifiSave() {
|
|||||||
//read parameter
|
//read parameter
|
||||||
String value = 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 + 1);
|
||||||
DEBUG_WM(F("Parameter"));
|
DEBUG_WM(F("Parameter"));
|
||||||
DEBUG_WM(_params[i]->getID());
|
DEBUG_WM(_params[i]->getID());
|
||||||
DEBUG_WM(value);
|
DEBUG_WM(value);
|
||||||
@@ -579,6 +645,7 @@ void WiFiManager::handleWifiSave() {
|
|||||||
page += FPSTR(HTTP_SAVED);
|
page += FPSTR(HTTP_SAVED);
|
||||||
page += FPSTR(HTTP_END);
|
page += FPSTR(HTTP_END);
|
||||||
|
|
||||||
|
server->sendHeader("Content-Length", String(page.length()));
|
||||||
server->send(200, "text/html", page);
|
server->send(200, "text/html", page);
|
||||||
|
|
||||||
DEBUG_WM(F("Sent wifi save page"));
|
DEBUG_WM(F("Sent wifi save page"));
|
||||||
@@ -621,6 +688,7 @@ void WiFiManager::handleInfo() {
|
|||||||
page += F("</dl>");
|
page += F("</dl>");
|
||||||
page += FPSTR(HTTP_END);
|
page += FPSTR(HTTP_END);
|
||||||
|
|
||||||
|
server->sendHeader("Content-Length", String(page.length()));
|
||||||
server->send(200, "text/html", page);
|
server->send(200, "text/html", page);
|
||||||
|
|
||||||
DEBUG_WM(F("Sent info page"));
|
DEBUG_WM(F("Sent info page"));
|
||||||
@@ -638,6 +706,8 @@ void WiFiManager::handleReset() {
|
|||||||
page += FPSTR(HTTP_HEAD_END);
|
page += FPSTR(HTTP_HEAD_END);
|
||||||
page += F("Module will reset in a few seconds.");
|
page += F("Module will reset in a few seconds.");
|
||||||
page += FPSTR(HTTP_END);
|
page += FPSTR(HTTP_END);
|
||||||
|
|
||||||
|
server->sendHeader("Content-Length", String(page.length()));
|
||||||
server->send(200, "text/html", page);
|
server->send(200, "text/html", page);
|
||||||
|
|
||||||
DEBUG_WM(F("Sent reset page"));
|
DEBUG_WM(F("Sent reset page"));
|
||||||
@@ -646,17 +716,6 @@ void WiFiManager::handleReset() {
|
|||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//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", "");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void WiFiManager::handleNotFound() {
|
void WiFiManager::handleNotFound() {
|
||||||
if (captivePortal()) { // If captive portal redirect instead of displaying the error page.
|
if (captivePortal()) { // If captive portal redirect instead of displaying the error page.
|
||||||
return;
|
return;
|
||||||
@@ -676,6 +735,7 @@ void WiFiManager::handleNotFound() {
|
|||||||
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
server->sendHeader("Pragma", "no-cache");
|
server->sendHeader("Pragma", "no-cache");
|
||||||
server->sendHeader("Expires", "-1");
|
server->sendHeader("Expires", "-1");
|
||||||
|
server->sendHeader("Content-Length", String(message.length()));
|
||||||
server->send ( 404, "text/plain", message );
|
server->send ( 404, "text/plain", message );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,7 +797,7 @@ int WiFiManager::getRSSIasQuality(int RSSI) {
|
|||||||
|
|
||||||
/** Is this an IP? */
|
/** Is this an IP? */
|
||||||
boolean WiFiManager::isIp(String str) {
|
boolean WiFiManager::isIp(String str) {
|
||||||
for (int i = 0; i < str.length(); i++) {
|
for (size_t i = 0; i < str.length(); i++) {
|
||||||
int c = str.charAt(i);
|
int c = str.charAt(i);
|
||||||
if (c != '.' && (c < '0' || c > '9')) {
|
if (c != '.' && (c < '0' || c > '9')) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
inspired by:
|
inspired by:
|
||||||
http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||||
https://github.com/chriscook8/esp-arduino-apboot
|
https://github.com/chriscook8/esp-arduino-apboot
|
||||||
https://github.com/esp8266/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/DNSServer/examples/CaptivePortalAdvanced
|
https://github.com/esp8266/Arduino/tree/master/libraries/DNSServer/examples/CaptivePortalAdvanced
|
||||||
Built by AlexT https://github.com/tzapu
|
Built by AlexT https://github.com/tzapu
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
@@ -29,19 +29,26 @@ const char HTTP_HEAD_END[] PROGMEM = "</head><body><div style='text-align
|
|||||||
const char HTTP_PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>";
|
const char HTTP_PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>";
|
||||||
const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
||||||
const char HTTP_FORM_START[] PROGMEM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 type='password' placeholder='password'><br/>";
|
const char HTTP_FORM_START[] PROGMEM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 type='password' placeholder='password'><br/>";
|
||||||
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' length={l} placeholder='{p}' value='{v}' {c}>";
|
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='{p}' value='{v}' {c}>";
|
||||||
const char HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
const char HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
||||||
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
||||||
const char HTTP_SAVED[] PROGMEM = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
|
const char HTTP_SAVED[] PROGMEM = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
|
||||||
const char HTTP_END[] PROGMEM = "</div></body></html>";
|
const char HTTP_END[] PROGMEM = "</div></body></html>";
|
||||||
|
|
||||||
|
#ifndef WIFI_MANAGER_MAX_PARAMS
|
||||||
#define WIFI_MANAGER_MAX_PARAMS 10
|
#define WIFI_MANAGER_MAX_PARAMS 10
|
||||||
|
#endif
|
||||||
|
|
||||||
class WiFiManagerParameter {
|
class WiFiManagerParameter {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
Create custom parameters that can be added to the WiFiManager setup web page
|
||||||
|
@id is used for HTTP queries and must not contain spaces nor other special characters
|
||||||
|
*/
|
||||||
WiFiManagerParameter(const char *custom);
|
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);
|
||||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
|
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
|
||||||
|
~WiFiManagerParameter();
|
||||||
|
|
||||||
const char *getID();
|
const char *getID();
|
||||||
const char *getValue();
|
const char *getValue();
|
||||||
@@ -65,11 +72,13 @@ class WiFiManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WiFiManager();
|
WiFiManager();
|
||||||
|
~WiFiManager();
|
||||||
|
|
||||||
boolean autoConnect();
|
boolean autoConnect();
|
||||||
boolean autoConnect(char const *apName, char const *apPassword = NULL);
|
boolean autoConnect(char const *apName, char const *apPassword = NULL);
|
||||||
|
|
||||||
//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();
|
||||||
boolean startConfigPortal(char const *apName, char const *apPassword = NULL);
|
boolean startConfigPortal(char const *apName, char const *apPassword = NULL);
|
||||||
|
|
||||||
// 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
|
||||||
@@ -78,12 +87,12 @@ class WiFiManager
|
|||||||
void resetSettings();
|
void resetSettings();
|
||||||
|
|
||||||
//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
|
//useful for devices that failed to connect at some point and got stuck in a webserver loop
|
||||||
//in seconds setConfigPortalTimeout is a new name for setTimeout
|
//in seconds setConfigPortalTimeout is a new name for setTimeout
|
||||||
void setConfigPortalTimeout(unsigned long seconds);
|
void setConfigPortalTimeout(unsigned long seconds);
|
||||||
void setTimeout(unsigned long seconds);
|
void setTimeout(unsigned long seconds);
|
||||||
|
|
||||||
//sets timeout for which to attempt connecting, usefull if you get a lot of failed connects
|
//sets timeout for which to attempt connecting, useful if you get a lot of failed connects
|
||||||
void setConnectTimeout(unsigned long seconds);
|
void setConnectTimeout(unsigned long seconds);
|
||||||
|
|
||||||
|
|
||||||
@@ -98,9 +107,9 @@ class WiFiManager
|
|||||||
void setAPCallback( void (*func)(WiFiManager*) );
|
void setAPCallback( void (*func)(WiFiManager*) );
|
||||||
//called when settings have been changed and connection was successful
|
//called when settings have been changed and connection was successful
|
||||||
void setSaveConfigCallback( void (*func)(void) );
|
void setSaveConfigCallback( void (*func)(void) );
|
||||||
//adds a custom parameter
|
//adds a custom parameter, returns false on failure
|
||||||
void addParameter(WiFiManagerParameter *p);
|
bool 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 unsuccessful.
|
||||||
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)
|
//if this is set, try WPS setup when starting (this will delay config portal for up to 2 mins)
|
||||||
//TODO
|
//TODO
|
||||||
@@ -159,6 +168,7 @@ class WiFiManager
|
|||||||
void handleNotFound();
|
void handleNotFound();
|
||||||
void handle204();
|
void handle204();
|
||||||
boolean captivePortal();
|
boolean captivePortal();
|
||||||
|
boolean configPortalHasTimeout();
|
||||||
|
|
||||||
// DNS server
|
// DNS server
|
||||||
const byte DNS_PORT = 53;
|
const byte DNS_PORT = 53;
|
||||||
@@ -174,7 +184,8 @@ class WiFiManager
|
|||||||
void (*_apcallback)(WiFiManager*) = NULL;
|
void (*_apcallback)(WiFiManager*) = NULL;
|
||||||
void (*_savecallback)(void) = NULL;
|
void (*_savecallback)(void) = NULL;
|
||||||
|
|
||||||
WiFiManagerParameter* _params[WIFI_MANAGER_MAX_PARAMS];
|
int _max_params;
|
||||||
|
WiFiManagerParameter** _params;
|
||||||
|
|
||||||
template <typename Generic>
|
template <typename Generic>
|
||||||
void DEBUG_WM(Generic text);
|
void DEBUG_WM(Generic text);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ void setup() {
|
|||||||
//wifiManager.resetSettings();
|
//wifiManager.resetSettings();
|
||||||
|
|
||||||
//set custom ip for portal
|
//set custom ip for portal
|
||||||
//wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
|
//wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
|
||||||
|
|
||||||
//fetches ssid and pass from eeprom and tries to connect
|
//fetches ssid and pass from eeprom and tries to connect
|
||||||
//if it does not connect it starts an access point with the specified name
|
//if it does not connect it starts an access point with the specified name
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ void setup() {
|
|||||||
} else {
|
} else {
|
||||||
Serial.println("failed to load json config");
|
Serial.println("failed to load json config");
|
||||||
}
|
}
|
||||||
|
configFile.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||||
|
|
||||||
// select wich pin will trigger the configuraton portal when set to LOW
|
// select which pin will trigger the configuration portal when set to LOW
|
||||||
// ESP-01 users please note: the only pins available (0 and 2), are shared
|
// ESP-01 users please note: the only pins available (0 and 2), are shared
|
||||||
// with the bootloader, so always set them HIGH at power-up
|
// with the bootloader, so always set them HIGH at power-up
|
||||||
#define TRIGGER_PIN 0
|
#define TRIGGER_PIN 0
|
||||||
|
|||||||
@@ -1,8 +1,32 @@
|
|||||||
<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>
|
<!-- HTTP_HEAD -->
|
||||||
<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;} .l{background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==") no-repeat left center;background-size: 1em;}</style>
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/>
|
||||||
|
<title>{v}</title>
|
||||||
|
<!-- /HTTP_HEAD -->
|
||||||
|
<!-- HTTP_STYLE -->
|
||||||
|
<style>
|
||||||
|
.c{text-align: center;}
|
||||||
|
div,input{padding:5px;font-size:1em;}
|
||||||
|
input{width:95%;}
|
||||||
|
body{text-align: center;font-family:verdana;}
|
||||||
|
button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}
|
||||||
|
.q{float: right;width: 64px;text-align: right;}
|
||||||
|
.l{background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==") no-repeat left center;background-size: 1em;}
|
||||||
|
</style>
|
||||||
|
<!-- /HTTP_STYLE -->
|
||||||
|
<!-- HTTP_SCRIPT -->
|
||||||
|
<script>
|
||||||
|
function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}
|
||||||
|
</script>
|
||||||
|
<!-- /HTTP_SCRIPT -->
|
||||||
|
<!-- HTTP_HEAD_END -->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="text-align:left;display:inline-block;min-width:260px;">
|
||||||
|
<!-- /HTTP_HEAD_END -->
|
||||||
|
|
||||||
<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}</script>
|
|
||||||
</head><body><div style="text-align:left;display:inline-block;min-width:260px;">
|
|
||||||
<!--
|
<!--
|
||||||
<div><a href='#' onclick='c(this)'>{v}</a> {r}% {i}</div>
|
<div><a href='#' onclick='c(this)'>{v}</a> {r}% {i}</div>
|
||||||
<div><a href='#' onclick='c(this)'>{v}</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAKCAMAAAC+Ge+yAAAACVBMVEUAAAC7u7v///9etNz6AAAAI0lEQVQI133GsQ3AMAAEoXv2H9qNJacKFbEaWTQJ+uQB/nMdEaYAXeJkZ9AAAAAASUVORK5CYII='/></div>
|
<div><a href='#' onclick='c(this)'>{v}</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAKCAMAAAC+Ge+yAAAACVBMVEUAAAC7u7v///9etNz6AAAAI0lEQVQI133GsQ3AMAAEoXv2H9qNJacKFbEaWTQJ+uQB/nMdEaYAXeJkZ9AAAAAASUVORK5CYII='/></div>
|
||||||
@@ -12,27 +36,45 @@
|
|||||||
<div><a href='#'>PMica</a> 110% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==' width="13px"/></div>
|
<div><a href='#'>PMica</a> 110% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==' width="13px"/></div>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<style>
|
<!--style>
|
||||||
.q{float: right;width: 64px;text-align: right;}
|
.q{float: right;width: 64px;text-align: right;}
|
||||||
.l{background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==") no-repeat left center;background-size: 1em;}
|
.l{background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==") no-repeat left center;background-size: 1em;}
|
||||||
</style>
|
</style-->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- HTTP_PORTAL_OPTIONS -->
|
||||||
|
<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>
|
||||||
|
<!-- /HTTP_PORTAL_OPTIONS -->
|
||||||
|
|
||||||
<div><a href='#' onclick='c(this)'>{v}</a> <span class="q {i}">{r}%</span></div>
|
<div><a href='#' onclick='c(this)'>{v}</a> <span class="q {i}">{r}%</span></div>
|
||||||
<div><a href='#'>PMisa</a> <span class="q l">100%</span> </div>
|
<div><a href='#'>PMisa</a> <span class="q l">100%</span> </div>
|
||||||
<div><a href='#'>Dragos_Networks</a> <span class="q l">10%</span> </div>
|
<div><a href='#'>Dragos_Networks</a> <span class="q l">10%</span> </div>
|
||||||
<div><a href='#'>PMisa</a> <span class="q l">8%</span> </div>
|
<div><a href='#'>PMisa</a> <span class="q l">8%</span> </div>
|
||||||
|
|
||||||
|
<!-- HTTP_ITEM -->
|
||||||
|
<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>
|
||||||
|
<!-- /HTTP_ITEM -->
|
||||||
|
<!-- HTTP_FORM_START -->
|
||||||
|
<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 type='password' placeholder='password'><br/>
|
||||||
|
<!-- /HTTP_FORM_START -->
|
||||||
|
<!-- HTTP_FORM_PARAM -->
|
||||||
|
<br/><input id='{i}' name='{n}' length='{l}' placeholder='{p}' value='{v}' {c}>
|
||||||
|
<!-- /HTTP_FORM_PARAM -->
|
||||||
|
<!-- HTTP_FORM_END -->
|
||||||
|
<br/><button type='submit'>save</button></form>
|
||||||
|
<!-- /HTTP_FORM_END -->
|
||||||
|
<!-- HTTP_SCAN_LINK -->
|
||||||
|
<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>
|
||||||
|
<!-- /HTTP_SCAN_LINK -->
|
||||||
|
<!-- HTTP_SAVED -->
|
||||||
|
<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>
|
||||||
|
<!-- /HTTP_SAVED -->
|
||||||
|
|
||||||
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
|
|
||||||
<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 placeholder='password'><br/><button type='submit'>save</button></form>
|
<!-- HTTP_END -->
|
||||||
<br/><div></div>
|
|
||||||
<br/>
|
|
||||||
<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/>
|
|
||||||
<form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form>
|
|
||||||
<br>
|
|
||||||
<div class="c"><a href=\"/wifi\">Scan</a></div>
|
|
||||||
</div>
|
</div>
|
||||||
</body></html>
|
</body>
|
||||||
|
</html>
|
||||||
|
<!-- /HTTP_END -->
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
console.log('starting');
|
||||||
|
|
||||||
|
const inFile = 'WiFiManager.template.html';
|
||||||
|
const outFile = 'template.h';
|
||||||
|
|
||||||
|
const defineRegEx = /<!-- ([A-Z_]+) -->/gm;
|
||||||
|
console.log('parsing', inFile);
|
||||||
|
|
||||||
|
fs.readFile(inFile, 'utf8', function (err,data) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
//console.log(data);
|
||||||
|
|
||||||
|
let defines = data.match(defineRegEx);
|
||||||
|
|
||||||
|
//console.log(defines);
|
||||||
|
var stream = fs.createWriteStream(outFile);
|
||||||
|
stream.once('open', function(fd) {
|
||||||
|
for (const i in defines) {
|
||||||
|
|
||||||
|
const start = defines[i];
|
||||||
|
const end = start.replace('<!-- ', '<!-- /')
|
||||||
|
defineRegEx.lastIndex = 0;
|
||||||
|
const constantName = defineRegEx.exec(start)[1];
|
||||||
|
|
||||||
|
console.log(constantName);
|
||||||
|
var extractRE = new RegExp(start + '([\\s\\S]+)' + end, 'gm');
|
||||||
|
let extractArray = extractRE.exec(data);
|
||||||
|
if(extractArray.length > 1) {
|
||||||
|
let def = extractArray[1];
|
||||||
|
//console.log(def);
|
||||||
|
//minimise a bit
|
||||||
|
def = def.replace(/\s+/g, ' ');
|
||||||
|
def = def.replace(/>\s+</g, '><');
|
||||||
|
def = def.trim();
|
||||||
|
//more extraneous spaces - possible bad results, needs to be checked
|
||||||
|
//def = def.replace(/(\w)\s(\W)|(\W)\s(\w)|(\W)\s(\W)/g, '$1$2$3$4$5$6');
|
||||||
|
def = def.replace(/(\w)\s(\W)|(\W)\s(\w)/g, '$1$2$3$4');
|
||||||
|
//escape double quotes
|
||||||
|
def = def.replace(/\\([\s\S])|(")/g, "\\$1$2");
|
||||||
|
|
||||||
|
|
||||||
|
console.log(def);
|
||||||
|
//const char HTTP_HEAD[] PROGMEM =
|
||||||
|
let string = 'const char ' + constantName + '[] PROGMEM';
|
||||||
|
for (let i = string.length; i < 42; i++) {
|
||||||
|
string += ' ';
|
||||||
|
}
|
||||||
|
string += '= "' + def + '";\n';
|
||||||
|
stream.write(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stream.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
const char HTTP_HEAD[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\"content=\"width=device-width,initial-scale=1,user-scalable=no\"/><title>{v}</title>";
|
||||||
|
const char HTTP_STYLE[] PROGMEM = "<style> .c{text-align:center;}div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align:center;font-family:verdana;}button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float:right;width:64px;text-align:right;} .l{background:url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==\")no-repeat left center;background-size:1em;} </style>";
|
||||||
|
const char HTTP_SCRIPT[] PROGMEM = "<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();} </script>";
|
||||||
|
const char HTTP_HEAD_END[] PROGMEM = "</head><body><div style=\"text-align:left;display:inline-block;min-width:260px;\">";
|
||||||
|
const char HTTP_PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\"method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\"method=\"get\"><button>Configure WiFi(No Scan)</button></form><br/><form action=\"/i\"method=\"get\"><button>Info</button></form><br/><form action=\"/r\"method=\"post\"><button>Reset</button></form>";
|
||||||
|
const char HTTP_ITEM[] PROGMEM = "<div><a href='#p'onclick='c(this)'>{v}</a> <span class='q{i}'>{r}%</span></div>";
|
||||||
|
const char HTTP_FORM_START[] PROGMEM = "<form method='get'action='wifisave'><input id='s'name='s'length=32 placeholder='SSID'><br/><input id='p'name='p'length=64 type='password'placeholder='password'><br/>";
|
||||||
|
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}'name='{n}'length={l}placeholder='{p}'value='{v}' {c}>";
|
||||||
|
const char HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
||||||
|
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
||||||
|
const char HTTP_SAVED[] PROGMEM = "<div>Credentials Saved<br/>Trying to connect ESP to network.<br/>If it fails reconnect to AP to try again</div>";
|
||||||
|
const char HTTP_END[] PROGMEM = "</div></body></html>";
|
||||||
@@ -8,6 +8,6 @@
|
|||||||
"url": "https://github.com/tzapu/WiFiManager.git"
|
"url": "https://github.com/tzapu/WiFiManager.git"
|
||||||
},
|
},
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "espressif",
|
"platforms": "espressif8266",
|
||||||
"version": "0.12"
|
"version": "0.14"
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
name=WiFiManager
|
name=WiFiManager
|
||||||
version=0.12
|
version=0.14
|
||||||
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
|
||||||
|
|||||||
Reference in new issue
Block a user