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

Small tweaks to avoid a class of the #define with the latest ESP SDK. #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 35 additions & 35 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,18 +401,18 @@ void WiFiManager::handleRoot() {
return;
}

String page = FPSTR(HTTP_HEAD);
String page = FPSTR(WM_HTTP_HEAD);
page.replace("{v}", "Options");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += FPSTR(WM_HTTP_SCRIPT);
page += FPSTR(WM_HTTP_STYLE);
page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += FPSTR(WM_HTTP_HEAD_END);
page += "<h1>";
page += _apName;
page += "</h1>";
page += F("<h3>WiFiManager</h3>");
page += FPSTR(HTTP_PORTAL_OPTIONS);
page += FPSTR(HTTP_END);
page += FPSTR(WM_HTTP_PORTAL_OPTIONS);
page += FPSTR(WM_HTTP_END);

server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
Expand All @@ -422,12 +422,12 @@ void WiFiManager::handleRoot() {
/** Wifi config page handler */
void WiFiManager::handleWifi(boolean scan) {

String page = FPSTR(HTTP_HEAD);
String page = FPSTR(WM_HTTP_HEAD);
page.replace("{v}", "Config ESP");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += FPSTR(WM_HTTP_SCRIPT);
page += FPSTR(WM_HTTP_STYLE);
page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += FPSTR(WM_HTTP_HEAD_END);

if (scan) {
int n = WiFi.scanNetworks();
Expand Down Expand Up @@ -482,7 +482,7 @@ void WiFiManager::handleWifi(boolean scan) {
int quality = getRSSIasQuality(WiFi.RSSI(indices[i]));

if (_minimumQuality == -1 || _minimumQuality < quality) {
String item = FPSTR(HTTP_ITEM);
String item = FPSTR(WM_HTTP_ITEM);
String rssiQ;
rssiQ += quality;
item.replace("{v}", WiFi.SSID(indices[i]));
Expand All @@ -508,15 +508,15 @@ void WiFiManager::handleWifi(boolean scan) {
}
}

page += FPSTR(HTTP_FORM_START);
page += FPSTR(WM_HTTP_FORM_START);
char parLength[2];
// add the extra parameters to the form
for (int i = 0; i < _paramsCount; i++) {
if (_params[i] == NULL) {
break;
}

String pitem = FPSTR(HTTP_FORM_PARAM);
String pitem = FPSTR(WM_HTTP_FORM_PARAM);
if (_params[i]->getID() != NULL) {
pitem.replace("{i}", _params[i]->getID());
pitem.replace("{n}", _params[i]->getID());
Expand All @@ -537,7 +537,7 @@ void WiFiManager::handleWifi(boolean scan) {

if (_sta_static_ip) {

String item = FPSTR(HTTP_FORM_PARAM);
String item = FPSTR(WM_HTTP_FORM_PARAM);
item.replace("{i}", "ip");
item.replace("{n}", "ip");
item.replace("{p}", "Static IP");
Expand All @@ -546,7 +546,7 @@ void WiFiManager::handleWifi(boolean scan) {

page += item;

item = FPSTR(HTTP_FORM_PARAM);
item = FPSTR(WM_HTTP_FORM_PARAM);
item.replace("{i}", "gw");
item.replace("{n}", "gw");
item.replace("{p}", "Static Gateway");
Expand All @@ -555,7 +555,7 @@ void WiFiManager::handleWifi(boolean scan) {

page += item;

item = FPSTR(HTTP_FORM_PARAM);
item = FPSTR(WM_HTTP_FORM_PARAM);
item.replace("{i}", "sn");
item.replace("{n}", "sn");
item.replace("{p}", "Subnet");
Expand All @@ -567,10 +567,10 @@ void WiFiManager::handleWifi(boolean scan) {
page += "<br/>";
}

page += FPSTR(HTTP_FORM_END);
page += FPSTR(HTTP_SCAN_LINK);
page += FPSTR(WM_HTTP_FORM_END);
page += FPSTR(WM_HTTP_SCAN_LINK);

page += FPSTR(HTTP_END);
page += FPSTR(WM_HTTP_END);

server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
Expand Down Expand Up @@ -621,14 +621,14 @@ void WiFiManager::handleWifiSave() {
optionalIPFromString(&_sta_static_sn, sn.c_str());
}

String page = FPSTR(HTTP_HEAD);
String page = FPSTR(WM_HTTP_HEAD);
page.replace("{v}", "Credentials Saved");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += FPSTR(WM_HTTP_SCRIPT);
page += FPSTR(WM_HTTP_STYLE);
page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += FPSTR(HTTP_SAVED);
page += FPSTR(HTTP_END);
page += FPSTR(WM_HTTP_HEAD_END);
page += FPSTR(WM_HTTP_SAVED);
page += FPSTR(WM_HTTP_END);

server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
Expand All @@ -642,12 +642,12 @@ void WiFiManager::handleWifiSave() {
void WiFiManager::handleInfo() {
DEBUG_WM(F("Info"));

String page = FPSTR(HTTP_HEAD);
String page = FPSTR(WM_HTTP_HEAD);
page.replace("{v}", "Info");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += FPSTR(WM_HTTP_SCRIPT);
page += FPSTR(WM_HTTP_STYLE);
page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += FPSTR(WM_HTTP_HEAD_END);
page += F("<dl>");
page += F("<dt>Chip ID</dt><dd>");
page += ESP_getChipId();
Expand Down Expand Up @@ -681,7 +681,7 @@ void WiFiManager::handleInfo() {
page += WiFi.macAddress();
page += F("</dd>");
page += F("</dl>");
page += FPSTR(HTTP_END);
page += FPSTR(WM_HTTP_END);

server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
Expand All @@ -693,14 +693,14 @@ void WiFiManager::handleInfo() {
void WiFiManager::handleReset() {
DEBUG_WM(F("Reset"));

String page = FPSTR(HTTP_HEAD);
String page = FPSTR(WM_HTTP_HEAD);
page.replace("{v}", "Info");
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += FPSTR(WM_HTTP_SCRIPT);
page += FPSTR(WM_HTTP_STYLE);
page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
page += FPSTR(WM_HTTP_HEAD_END);
page += F("Module will reset in a few seconds.");
page += FPSTR(HTTP_END);
page += FPSTR(WM_HTTP_END);

server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
Expand Down
24 changes: 12 additions & 12 deletions WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ extern "C" {
#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
#endif

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/>";
const char WM_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 WM_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 WM_HTTP_SCRIPT[] PROGMEM = "<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}</script>";
const char WM_HTTP_HEAD_END[] PROGMEM = "</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>";
const char WM_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>&nbsp;<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 Weread to network.<br />If it fails reconnect to AP to try again</div>";
const char HTTP_END[] PROGMEM = "</div></body></html>";
const char WM_HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a>&nbsp;<span class='q {i}'>{r}%</span></div>";
const char WM_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 WM_HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' length={l} placeholder='{p}' value='{v}' {c}>";
const char WM_HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
const char WM_HTTP_SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
const char WM_HTTP_SAVED[] PROGMEM = "<div>Credentials Saved<br />Trying to connect Weread to network.<br />If it fails reconnect to AP to try again</div>";
const char WM_HTTP_END[] PROGMEM = "</div></body></html>";

#define WIFI_MANAGER_MAX_PARAMS 10

Expand Down