Skip to content

Commit

Permalink
Put longer string literals into PROGMEM (esp8266#6588)
Browse files Browse the repository at this point in the history
* Put longer string literals into PROGMEM

* Use Flash Strings for Debug output

This is hopefully very infrequently used, so it shouldn't
be in main memory.
  • Loading branch information
dirkmueller authored and devyte committed Oct 4, 2019
1 parent fb2cbe3 commit 3890e1a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
12 changes: 6 additions & 6 deletions libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class BearSSLTraits : public TransportTraits
* constructor
*/
HTTPClient::HTTPClient()
: _client(nullptr), _userAgent(F("ESP8266HTTPClient"))
{
_client = nullptr;
#if HTTPCLIENT_1_1_COMPATIBLE
_tcpDeprecated.reset(nullptr);
#endif
Expand Down Expand Up @@ -1294,21 +1294,21 @@ int HTTPClient::handleHeaderResponse()
String headerValue = headerLine.substring(headerLine.indexOf(':') + 1);
headerValue.trim();

if(headerName.equalsIgnoreCase("Content-Length")) {
if(headerName.equalsIgnoreCase(F("Content-Length"))) {
_size = headerValue.toInt();
}

if(_canReuse && headerName.equalsIgnoreCase("Connection")) {
if(_canReuse && headerName.equalsIgnoreCase(F("Connection"))) {
if(headerValue.indexOf("close") >= 0 && headerValue.indexOf("keep-alive") < 0) {
_canReuse = false;
}
}

if(headerName.equalsIgnoreCase("Transfer-Encoding")) {
if(headerName.equalsIgnoreCase(F("Transfer-Encoding"))) {
transferEncoding = headerValue;
}

if(headerName.equalsIgnoreCase("Location")) {
if(headerName.equalsIgnoreCase(F("Location"))) {
_location = headerValue;
}

Expand All @@ -1334,7 +1334,7 @@ int HTTPClient::handleHeaderResponse()

if(transferEncoding.length() > 0) {
DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] Transfer-Encoding: %s\n", transferEncoding.c_str());
if(transferEncoding.equalsIgnoreCase("chunked")) {
if(transferEncoding.equalsIgnoreCase(F("chunked"))) {
_transferEncoding = HTTPC_TE_CHUNKED;
} else {
return HTTPC_ERROR_ENCODING;
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class HTTPClient
String _uri;
String _protocol;
String _headers;
String _userAgent = "ESP8266HTTPClient";
String _userAgent;
String _base64Authorization;

/// Response handling
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WebServer/src/Parsing-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseRequest(ClientType& client) {
DEBUG_OUTPUT.println(headerValue);
#endif

if (headerName.equalsIgnoreCase("Host")){
if (headerName.equalsIgnoreCase(F("Host"))){
_hostHeader = headerValue;
}
}
Expand Down
30 changes: 11 additions & 19 deletions libraries/ESP8266WiFi/src/ESP8266WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ extern "C" {
* @param p Print interface
*/
void ESP8266WiFiClass::printDiag(Print& p) {
const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };
p.print("Mode: ");
const char* const modes[] = { "NULL", "STA", "AP", "STA+AP" };
p.print(F("Mode: "));
p.println(modes[wifi_get_opmode()]);

const char* phymodes[] = { "", "B", "G", "N" };
p.print("PHY mode: ");
const char* const phymodes[] = { "", "B", "G", "N" };
p.print(F("PHY mode: "));
p.println(phymodes[(int) wifi_get_phy_mode()]);

p.print("Channel: ");
p.print(F("Channel: "));
p.println(wifi_get_channel());

p.print("AP id: ");
p.print(F("AP id: "));
p.println(wifi_station_get_current_ap_id());

p.print("Status: ");
p.print(F("Status: "));
p.println(wifi_station_get_connect_status());

p.print("Auto connect: ");
p.print(F("Auto connect: "));
p.println(wifi_station_get_auto_connect());

struct station_config conf;
Expand All @@ -75,22 +75,14 @@ void ESP8266WiFiClass::printDiag(Print& p) {
char ssid[33]; //ssid can be up to 32chars, => plus null term
memcpy(ssid, conf.ssid, sizeof(conf.ssid));
ssid[32] = 0; //nullterm in case of 32 char ssid

p.print("SSID (");
p.print(strlen(ssid));
p.print("): ");
p.println(ssid);
p.printf_P(PSTR("SSID (%d): %s\n"), strlen(ssid), ssid);

char passphrase[65];
memcpy(passphrase, conf.password, sizeof(conf.password));
passphrase[64] = 0;
p.printf_P(PSTR("Passphrase (%d): %s\n"), strlen(passphrase), passphrase);

p.print("Passphrase (");
p.print(strlen(passphrase));
p.print("): ");
p.println(passphrase);

p.print("BSSID set: ");
p.print(F("BSSID set: "));
p.println(conf.bssid_set);

}
Expand Down

0 comments on commit 3890e1a

Please sign in to comment.