From fe1cc18ddb760dab3b916b327c6f42eb8e3de708 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Fri, 4 Sep 2015 09:52:27 -0400 Subject: [PATCH 1/7] add W25Q40 chipid --- cores/esp8266/Esp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index 4b34762af..4ced05286 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -280,6 +280,8 @@ uint32_t EspClass::getFlashChipSizeByChipId(void) { return (2_MB); case 0x1440EF: // W25Q80 return (1_MB); + case 0x1340EF: // W25Q40 + return (512_kB); default: return 0; From 389107f09d27fd356783727397273567a35926d3 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Sun, 6 Sep 2015 13:09:57 -0400 Subject: [PATCH 2/7] fix bug in WiFiClient::write_P when content was binary --- libraries/ESP8266WiFi/src/WiFiClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClient.cpp b/libraries/ESP8266WiFi/src/WiFiClient.cpp index 8165ba3ba..653594f13 100644 --- a/libraries/ESP8266WiFi/src/WiFiClient.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClient.cpp @@ -190,7 +190,7 @@ size_t WiFiClient::write_P(PGM_P buf, size_t size) { size_t chunkUnitLen; PGM_P chunkNext; - chunkNext = (PGM_P)memccpy_P((void*)chunkUnit, (PGM_VOID_P)buf, 0, WIFICLIENT_MAX_PACKET_SIZE); + chunkNext = (PGM_P)memcpy_P((void*)chunkUnit, (PGM_VOID_P)buf, WIFICLIENT_MAX_PACKET_SIZE); if (chunkNext == NULL) { // no terminator, more data available From 82748a872cecc2115ca821ded1717b8e2fce7210 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Sun, 6 Sep 2015 13:27:12 -0400 Subject: [PATCH 3/7] add ESP8266WebServer::sendContent_P with 'size_t size' argument for binary content --- .../ESP8266WebServer/src/ESP8266WebServer.cpp | 29 +++++++++++++++++++ .../ESP8266WebServer/src/ESP8266WebServer.h | 1 + 2 files changed, 30 insertions(+) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index 3af856184..f2f21c781 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -221,6 +221,35 @@ void ESP8266WebServer::sendContent_P(PGM_P content) { } } +void ESP8266WebServer::sendContent_P(PGM_P content, size_t size) { + char contentUnit[HTTP_DOWNLOAD_UNIT_SIZE + 1]; + + contentUnit[HTTP_DOWNLOAD_UNIT_SIZE] = '\0'; + + while (content != NULL) { + size_t contentUnitLen; + PGM_P contentNext; + + // due to the memcpy signature, lots of casts are needed + contentNext = (PGM_P)memcpy_P((void*)contentUnit, (PGM_VOID_P)content, HTTP_DOWNLOAD_UNIT_SIZE); + + if (contentNext == NULL) { + // no terminator, more data available + content += HTTP_DOWNLOAD_UNIT_SIZE; + contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE; + } + else { + // reached terminator + contentUnitLen = contentNext - content; + content = NULL; + } + + if (size < WIFICLIENT_MAX_PACKET_SIZE) contentUnitLen = size; + // write is so overloaded, had to use the cast to get it pick the right one + _currentClient.write((const char*)contentUnit, contentUnitLen); + } +} + String ESP8266WebServer::arg(const char* name) { for (int i = 0; i < _currentArgCount; ++i) { if (_currentArgs[i].key == name) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index 33b7b8401..4f455c377 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -95,6 +95,7 @@ public: void sendHeader(const String& name, const String& value, bool first = false); void sendContent(const String& content); void sendContent_P(PGM_P content); + void sendContent_P(PGM_P content, size_t size); template size_t streamFile(T &file, const String& contentType){ setContentLength(file.size()); From e3e25da792d4412eeddb46ab3d6187d01fa15074 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Sun, 6 Sep 2015 14:04:57 -0400 Subject: [PATCH 4/7] fix bug in WiFiClient::write_P/ESP8266WebServer::sendContent_P introduced few minutes ago when changing memccpy_P to memcpy_P --- libraries/ESP8266WiFi/src/WiFiClient.cpp | 31 ++++++++++-------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClient.cpp b/libraries/ESP8266WiFi/src/WiFiClient.cpp index 653594f13..d881c4a87 100644 --- a/libraries/ESP8266WiFi/src/WiFiClient.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClient.cpp @@ -186,24 +186,19 @@ size_t WiFiClient::write_P(PGM_P buf, size_t size) char chunkUnit[WIFICLIENT_MAX_PACKET_SIZE + 1]; chunkUnit[WIFICLIENT_MAX_PACKET_SIZE] = '\0'; - while (buf != NULL) - { - size_t chunkUnitLen; - PGM_P chunkNext; - chunkNext = (PGM_P)memcpy_P((void*)chunkUnit, (PGM_VOID_P)buf, WIFICLIENT_MAX_PACKET_SIZE); - if (chunkNext == NULL) - { - // no terminator, more data available - buf += WIFICLIENT_MAX_PACKET_SIZE; - chunkUnitLen = WIFICLIENT_MAX_PACKET_SIZE; - } - else - { - // reached terminator - chunkUnitLen = chunkNext - buf; - buf = NULL; - } - if (size < WIFICLIENT_MAX_PACKET_SIZE) chunkUnitLen = size; + size_t remaining_size = size; + + while (buf != NULL && remaining_size > 0) { + size_t chunkUnitLen = WIFICLIENT_MAX_PACKET_SIZE; + + if (remaining_size < WIFICLIENT_MAX_PACKET_SIZE) chunkUnitLen = remaining_size; + // due to the memcpy signature, lots of casts are needed + memcpy_P((void*)chunkUnit, (PGM_VOID_P)buf, chunkUnitLen); + + buf += chunkUnitLen; + remaining_size -= chunkUnitLen; + + // write is so overloaded, had to use the cast to get it pick the right one _client->write((const char*)chunkUnit, chunkUnitLen); } return size; From 1c9456ac9d5c6b3424e6c9ebdec07e5944d5d246 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Sun, 6 Sep 2015 14:14:36 -0400 Subject: [PATCH 5/7] fix bug in WiFiClient::write_P/ESP8266WebServer::sendContent_P introduced few minutes ago when changing memccpy_P to memcpy_P --- .../ESP8266WebServer/src/ESP8266WebServer.cpp | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index f2f21c781..326ed24bc 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -223,28 +223,19 @@ void ESP8266WebServer::sendContent_P(PGM_P content) { void ESP8266WebServer::sendContent_P(PGM_P content, size_t size) { char contentUnit[HTTP_DOWNLOAD_UNIT_SIZE + 1]; - contentUnit[HTTP_DOWNLOAD_UNIT_SIZE] = '\0'; + size_t remaining_size = size; - while (content != NULL) { - size_t contentUnitLen; - PGM_P contentNext; + while (content != NULL && remaining_size > 0) { + size_t contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE; + if (remaining_size < HTTP_DOWNLOAD_UNIT_SIZE) contentUnitLen = remaining_size; // due to the memcpy signature, lots of casts are needed - contentNext = (PGM_P)memcpy_P((void*)contentUnit, (PGM_VOID_P)content, HTTP_DOWNLOAD_UNIT_SIZE); + memcpy_P((void*)contentUnit, (PGM_VOID_P)content, contentUnitLen); - if (contentNext == NULL) { - // no terminator, more data available - content += HTTP_DOWNLOAD_UNIT_SIZE; - contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE; - } - else { - // reached terminator - contentUnitLen = contentNext - content; - content = NULL; - } + content += contentUnitLen; + remaining_size -= contentUnitLen; - if (size < WIFICLIENT_MAX_PACKET_SIZE) contentUnitLen = size; // write is so overloaded, had to use the cast to get it pick the right one _currentClient.write((const char*)contentUnit, contentUnitLen); } From 27b67f4adc5fb720a6e80b18bb988daed87842d8 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Sun, 6 Sep 2015 14:17:23 -0400 Subject: [PATCH 6/7] add ESP8266WebServer::send_P with contentLength argument --- libraries/ESP8266WebServer/src/ESP8266WebServer.cpp | 7 +++++++ libraries/ESP8266WebServer/src/ESP8266WebServer.h | 1 + 2 files changed, 8 insertions(+) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index 326ed24bc..2bd6bbea1 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -169,6 +169,13 @@ void ESP8266WebServer::send_P(int code, PGM_P content_type, PGM_P content) { sendContent_P(content); } +void ESP8266WebServer::send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) { + String header; + _prepareHeader(header, code, String(FPSTR(content_type)).c_str(), contentLength); + sendContent(header); + sendContent_P(content, contentLength); +} + void ESP8266WebServer::send(int code, char* content_type, const String& content) { send(code, (const char*)content_type, content); } diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index 4f455c377..fad9fc55c 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -90,6 +90,7 @@ public: void send(int code, char* content_type, const String& content); void send(int code, const String& content_type, const String& content); void send_P(int code, PGM_P content_type, PGM_P content); + void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength); void setContentLength(size_t contentLength) { _contentLength = contentLength; } void sendHeader(const String& name, const String& value, bool first = false); From 5cb086bc05681e0e8ecc780631a04803089f73b2 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Wed, 9 Sep 2015 12:03:07 -0400 Subject: [PATCH 7/7] temporarly fix for handling PGM_P content_type properly in ESP8266WebServer::send_P() functions --- libraries/ESP8266WebServer/src/ESP8266WebServer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index 2bd6bbea1..722751660 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -164,14 +164,18 @@ void ESP8266WebServer::send_P(int code, PGM_P content_type, PGM_P content) { } String header; - _prepareHeader(header, code, String(FPSTR(content_type)).c_str(), contentLength); + char type[64]; + memccpy_P((void*)type, (PGM_VOID_P)content_type, 0, sizeof(type)); + _prepareHeader(header, code, (const char* )type, contentLength); sendContent(header); sendContent_P(content); } void ESP8266WebServer::send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) { String header; - _prepareHeader(header, code, String(FPSTR(content_type)).c_str(), contentLength); + char type[64]; + memccpy_P((void*)type, (PGM_VOID_P)content_type, 0, sizeof(type)); + _prepareHeader(header, code, (const char* )type, contentLength); sendContent(header); sendContent_P(content, contentLength); }