some more strings in progmem

This commit is contained in:
Shawn A
2018-02-14 13:24:00 -06:00
parent cbb32fdd61
commit c43551f85a
2 changed files with 53 additions and 36 deletions
+36 -36
View File
@@ -583,12 +583,12 @@ void WiFiManager::handleRoot() {
reportStatus(page);
page += FPSTR(HTTP_END);
server->sendHeader(F("Content-Length"), String(page.length()));
server->send(200, F("text/html"), page);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
// server->close(); // testing reliability fix for content length mismatches during mutiple flood hits
}
/**
/**
* HTTPD CALLBACK Wifi config page handler
*/
void WiFiManager::handleWifi(boolean scan) {
@@ -610,8 +610,8 @@ void WiFiManager::handleWifi(boolean scan) {
reportStatus(page);
page += FPSTR(HTTP_END);
server->sendHeader(F("Content-Length"), String(page.length()));
server->send(200, F("text/html"), page);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
// server->close(); // testing reliability fix for content length mismatches during mutiple flood hits
// Serial.println(page);
@@ -736,11 +736,11 @@ String WiFiManager::getStaticOut(){
if (_staShowStaticFields || _sta_static_ip) {
// @todo how can we get these accurate settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not
page += getIpForm(F("ip"),FPSTR(S_staticip),(_sta_static_ip ? _sta_static_ip.toString() : "")); // @token staticip
page += getIpForm(FPSTR(S_ip),FPSTR(S_staticip),(_sta_static_ip ? _sta_static_ip.toString() : "")); // @token staticip
// WiFi.localIP().toString();
page += getIpForm(F("gw"),FPSTR(S_staticgw),(_sta_static_gw ? _sta_static_gw.toString() : "")); // @token staticgw
page += getIpForm(FPSTR(S_gw),FPSTR(S_staticgw),(_sta_static_gw ? _sta_static_gw.toString() : "")); // @token staticgw
// WiFi.gatewayIP().toString();
page += getIpForm(F("sn"),FPSTR(S_subnet),(_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet
page += getIpForm(FPSTR(S_sn),FPSTR(S_subnet),(_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet
// WiFi.subnetMask().toString();
page += F("<br/>"); // @todo remove these, use css
}
@@ -822,8 +822,8 @@ void WiFiManager::handleWiFiStatus(){
#ifdef JSTEST
page = FPSTR(HTTP_JS);
#endif
server->sendHeader(F("Content-Length"), String(page.length()));
server->send(200, F("text/html"), page);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
}
/**
@@ -831,7 +831,7 @@ void WiFiManager::handleWiFiStatus(){
*/
void WiFiManager::handleWifiSave() {
DEBUG_WM(F("<- HTTP WiFi save "));
DEBUG_WM(F("Method:"),server->method() == HTTP_GET ? (String)F("GET") : (String)F("POST"));
DEBUG_WM(F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
handleRequest();
//SAVE/connect here
@@ -841,7 +841,7 @@ void WiFiManager::handleWifiSave() {
//parameters
if(_paramsCount > 0){
DEBUG_WM(F("Parameters"));
DEBUG_WM(F("-----------"));
DEBUG_WM(FPSTR(D_HR));
for (int i = 0; i < _paramsCount; i++) {
if (_params[i] == NULL) {
break;
@@ -855,22 +855,22 @@ void WiFiManager::handleWifiSave() {
value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated
DEBUG_WM((String)_params[i]->getID() + ":",value);
}
DEBUG_WM(F("-----------"));
DEBUG_WM(FPSTR(D_HR));
}
if (server->arg(F("ip")) != "") {
//_sta_static_ip.fromString(server->arg(F("ip")));
String ip = server->arg(F("ip"));
if (server->arg(FPSTR(S_ip)) != "") {
//_sta_static_ip.fromString(server->arg(FPSTR(S_ip));
String ip = server->arg(FPSTR(S_ip));
optionalIPFromString(&_sta_static_ip, ip.c_str());
DEBUG_WM(F("static ip:"),ip);
}
if (server->arg(F("gw")) != "") {
String gw = server->arg(F("gw"));
if (server->arg(FPSTR(S_gw)) != "") {
String gw = server->arg(FPSTR(S_gw));
optionalIPFromString(&_sta_static_gw, gw.c_str());
DEBUG_WM(F("static gateway:"),gw);
}
if (server->arg(F("sn")) != "") {
String sn = server->arg(F("sn"));
if (server->arg(FPSTR(S_sn)) != "") {
String sn = server->arg(FPSTR(S_sn));
optionalIPFromString(&_sta_static_sn, sn.c_str());
DEBUG_WM(F("static netmask:"),sn);
}
@@ -879,8 +879,8 @@ void WiFiManager::handleWifiSave() {
page += FPSTR(HTTP_SAVED);
page += FPSTR(HTTP_END);
server->sendHeader(F("Content-Length"), String(page.length()));
server->send(200, F("text/html"), page);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
DEBUG_WM(F("Sent wifi save page"));
@@ -935,8 +935,8 @@ void WiFiManager::handleInfo() {
page += FPSTR(HTTP_HELP);
page += FPSTR(HTTP_END);
server->sendHeader(F("Content-Length"), String(page.length()));
server->send(200, F("text/html"), page);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
DEBUG_WM(F("Sent info page"));
}
@@ -1063,8 +1063,8 @@ void WiFiManager::handleExit() {
handleRequest();
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
page += FPSTR(S_exiting); // @token exiting
server->sendHeader(F("Content-Length"), String(page.length()));
server->send(200, F("text/html"), page);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
abort = true;
}
@@ -1078,8 +1078,8 @@ void WiFiManager::handleReset() {
page += FPSTR(S_resetting); //@token resetting
page += FPSTR(HTTP_END);
server->sendHeader(F("Content-Length"), String(page.length()));
server->send(200, F("text/html"), page);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
DEBUG_WM(F("RESETTING ESP"));
delay(1000);
@@ -1104,8 +1104,8 @@ void WiFiManager::handleErase() {
}
page += FPSTR(HTTP_END);
server->sendHeader(F("Content-Length"), String(page.length()));
server->send(200, F("text/html"), page);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
if(ret){
delay(2000);
@@ -1124,7 +1124,7 @@ void WiFiManager::handleNotFound() {
message += FPSTR(S_uri); // @token uri
message += server->uri();
message += FPSTR(S_method); // @token method
message += ( server->method() == HTTP_GET ) ? F("GET") : F("POST");
message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST);
message += FPSTR(S_args); // @token args
message += server->args();
message += F("\n");
@@ -1135,8 +1135,8 @@ void WiFiManager::handleNotFound() {
server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"));
server->sendHeader(F("Pragma"), F("no-cache"));
server->sendHeader(F("Expires"), F("-1"));
server->sendHeader(F("Content-Length"), String(message.length()));
server->send ( 404, F("text/plain"), message );
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(message.length()));
server->send ( 404, FPSTR(HTTP_HEAD_CT2), message );
}
/**
@@ -1152,7 +1152,7 @@ boolean WiFiManager::captivePortal() {
if (!isIp(server->hostHeader())) {
DEBUG_WM(F("<- Request redirected to captive portal"));
server->sendHeader(F("Location"), (String)F("http://") + toStringIp(server->client().localIP()), true);
server->send ( 302, F("text/plain"), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
server->client().stop(); // Stop is needed because we sent no content length
return true;
}
@@ -1267,7 +1267,7 @@ void WiFiManager::debugSoftAPConfig(){
wifi_softap_get_config(&config);
DEBUG_WM(F("SoftAP Configuration"));
DEBUG_WM(F("--------------------"));
DEBUG_WM(FPSTR(D_HR));
DEBUG_WM(F("ssid: "),(char *) config.ssid);
DEBUG_WM(F("password: "),(char *) config.password);
DEBUG_WM(F("ssid_len: "),config.ssid_len);
@@ -1276,7 +1276,7 @@ void WiFiManager::debugSoftAPConfig(){
DEBUG_WM(F("ssid_hidden: "),config.ssid_hidden);
DEBUG_WM(F("max_connection: "),config.max_connection);
DEBUG_WM(F("beacon_interval: "),(String)config.beacon_interval + "(ms)");
DEBUG_WM(F("--------------------"));
DEBUG_WM(FPSTR(D_HR));
}
void WiFiManager::debugPlatformInfo(){
+17
View File
@@ -8,18 +8,23 @@
const char HTTP_HEAD[] PROGMEM = "<!DOCTYPE html><html lang='en'><head><meta name='format-detection' content='telephone=no'><meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'/><title>{v}</title>";
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 class='wrap'>";
const char HTTP_ROOT_MAIN[] PROGMEM = "<h1>{v}</h1><h3>WiFiManager</h3>";
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='GET'><button>Restart</button></form><br/><form action='/exit' method='GET'><button>Quit</button></form>";
const char HTTP_ITEM_QI[] PROGMEM = "<div role='img' aria-label='{r}%' title='{r}%' class='q q-{q} {i}'></div>"; // rssi icons
const char HTTP_ITEM_QP[] PROGMEM = "<div class='q'>{r}%</div>"; // rssi percentage
const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a>{q}</div>"; // {q} = HTTP_ITEM_QI, {r} = HTTP_ITEM_QP
// const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> {R} {r}% {q} {e}</div>"; // test all tokens
const char HTTP_FORM_START[] PROGMEM = "<form method='POST' action='wifisave'><label for='s'>SSID</label><input id='s' name='s' maxlength=32 placeholder='{v}'><br/><label for='p'>Password</label><input id='p' name='p' maxlength='64' type='password' placeholder=''><br/>";
const char HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>Save</button></form>";
const char HTTP_FORM_LABEL[] PROGMEM = "<label for='{i}'>{t}</label>";
const char HTTP_FORM_PARAM_START[] PROGMEM = "<hr>";
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='' value='{v}' {c}>";
const char HTTP_FORM_PARAM_END[] PROGMEM = "<br/>";
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><form action='/wifi' method='get'><button>Refresh</button></form>";
const char HTTP_SAVED[] PROGMEM = "<div class='msg'>Saving Credentials<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>";
@@ -122,11 +127,20 @@ const char HTTP_INFO_stamac[] PROGMEM = "<dt>Station MAC</dt><dd>{1}</dd>";
const char HTTP_INFO_conx[] PROGMEM = "<dt>Connected</dt><dd>{1}</dd>";
const char HTTP_INFO_autoconx[] PROGMEM = "<dt>Autoconnect</dt><dd>{1}</dd>";
const char HTTP_HEAD_CL[] PROGMEM = "Content-Length";
const char HTTP_HEAD_CT[] PROGMEM = "text/html";
const char HTTP_HEAD_CT2[] PROGMEM = "text/plain";
// Strings
const char S_GET[] PROGMEM = "GET";
const char S_POST[] PROGMEM = "POST";
const char S_y[] PROGMEM = "Yes";
const char S_n[] PROGMEM = "No";
const char S_enable[] PROGMEM = "Enabled";
const char S_disable[] PROGMEM = "Disabled";
const char S_ip[] PROGMEM = "ip";
const char S_gw[] PROGMEM = "gw";
const char S_sn[] PROGMEM = "sn";
const char S_titlewifisaved[] PROGMEM = "Credentials Saved"; // @token titlewifisaved
const char S_titlewifi[] PROGMEM = "Config ESP"; // @token titlewifi
@@ -164,4 +178,7 @@ const char T_q[] PROGMEM = "{q}"; // @token q
const char T_r[] PROGMEM = "{r}"; // @token r
const char T_R[] PROGMEM = "{R}"; // @token R
// debug strings
const char D_HR[] PROGMEM = "--------------------";
#endif