From 1a4cebad0d46cc564a5f3d8498d4aa42fe3b4c6e Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 3 Feb 2023 00:01:50 +0100 Subject: [PATCH 1/4] wrappers allowing to compile and run esp32-arduino basic examples (AdvancedWebServer FSBrowser HelloServer SimpleAuthentification) --- cores/esp8266/FS.h | 2 ++ libraries/WiFi/keywords.txt | 16 ++++++++++++++++ libraries/WiFi/library.properties | 6 ++++++ libraries/WiFi/src/ESPmDNS.h | 6 ++++++ libraries/WiFi/src/FFat.h | 6 ++++++ libraries/WiFi/src/SPIFFS.h | 4 ++++ libraries/WiFi/src/WebServer.h | 6 ++++++ libraries/WiFi/src/WiFi.h | 6 ++++++ 8 files changed, 52 insertions(+) create mode 100644 libraries/WiFi/keywords.txt create mode 100644 libraries/WiFi/library.properties create mode 100644 libraries/WiFi/src/ESPmDNS.h create mode 100644 libraries/WiFi/src/FFat.h create mode 100644 libraries/WiFi/src/SPIFFS.h create mode 100644 libraries/WiFi/src/WebServer.h create mode 100644 libraries/WiFi/src/WiFi.h diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index 55305e9688..5cb08851ff 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -79,6 +79,7 @@ class File : public Stream operator bool() const; const char* name() const; const char* fullName() const; // Includes path + const char* path() const { return fullName(); } // esp32 compat bool truncate(uint32_t size); bool isFile() const; @@ -225,6 +226,7 @@ class FS File open(const char* path, const char* mode); File open(const String& path, const char* mode); + File open(const String& path) { return open(path, "r"); } // esp32 compat bool exists(const char* path); bool exists(const String& path); diff --git a/libraries/WiFi/keywords.txt b/libraries/WiFi/keywords.txt new file mode 100644 index 0000000000..ad410807c8 --- /dev/null +++ b/libraries/WiFi/keywords.txt @@ -0,0 +1,16 @@ +####################################### +# Datatypes (KEYWORD1) +####################################### + +ESPmDNS KEYWORD1 +FFat KEYWORD1 +WebServer KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/libraries/WiFi/library.properties b/libraries/WiFi/library.properties new file mode 100644 index 0000000000..fc75427459 --- /dev/null +++ b/libraries/WiFi/library.properties @@ -0,0 +1,6 @@ +name=WiFi +version=1.0 +author=esp8266-arduino +maintainer=esp8266-arduino +sentence=convergence headers for esp32-Arduino compatibility +architectures=esp8266 diff --git a/libraries/WiFi/src/ESPmDNS.h b/libraries/WiFi/src/ESPmDNS.h new file mode 100644 index 0000000000..fdf99857f0 --- /dev/null +++ b/libraries/WiFi/src/ESPmDNS.h @@ -0,0 +1,6 @@ + +#pragma once + +#include + +using ESPmDNS = MDNSResponder; diff --git a/libraries/WiFi/src/FFat.h b/libraries/WiFi/src/FFat.h new file mode 100644 index 0000000000..c1618896d1 --- /dev/null +++ b/libraries/WiFi/src/FFat.h @@ -0,0 +1,6 @@ + +#pragma once + +#include + +#define FFat LittleFS diff --git a/libraries/WiFi/src/SPIFFS.h b/libraries/WiFi/src/SPIFFS.h new file mode 100644 index 0000000000..ead67e0b47 --- /dev/null +++ b/libraries/WiFi/src/SPIFFS.h @@ -0,0 +1,4 @@ + +#pragma once + +#include \ No newline at end of file diff --git a/libraries/WiFi/src/WebServer.h b/libraries/WiFi/src/WebServer.h new file mode 100644 index 0000000000..2ddf558e98 --- /dev/null +++ b/libraries/WiFi/src/WebServer.h @@ -0,0 +1,6 @@ + +#pragma once + +#include + +using WebServer = ESP8266WebServer; diff --git a/libraries/WiFi/src/WiFi.h b/libraries/WiFi/src/WiFi.h new file mode 100644 index 0000000000..4d9633d58b --- /dev/null +++ b/libraries/WiFi/src/WiFi.h @@ -0,0 +1,6 @@ + +#pragma once + +#include + +using WiFiClass = ESP8266WiFiClass; From cd40f219db63df29c606cc046e530931804aecea Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Tue, 28 Feb 2023 23:49:35 +0100 Subject: [PATCH 2/4] avoid declaration complexity --- .../src/ESP8266WebServer-impl.h | 27 --------------- .../ESP8266WebServer/src/ESP8266WebServer.h | 34 +++++++++++++------ 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h b/libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h index 6ffdbbd3b6..0746a1ac7f 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h @@ -457,21 +457,6 @@ void ESP8266WebServerTemplate::_prepareHeader(String& response, int _responseHeaders = ""; } -template -void ESP8266WebServerTemplate::send(int code, char* content_type, const String& content) { - return send(code, (const char*)content_type, content); -} - -template -void ESP8266WebServerTemplate::send(int code, const char* content_type, const String& content) { - return send(code, content_type, content.c_str(), content.length()); -} - -template -void ESP8266WebServerTemplate::send(int code, const String& content_type, const String& content) { - return send(code, (const char*)content_type.c_str(), content); -} - template void ESP8266WebServerTemplate::sendContent(const String& content) { StreamConstPtr ref(content.c_str(), content.length()); @@ -491,18 +476,6 @@ void ESP8266WebServerTemplate::send(int code, const char* content_ty return sendContent(stream, content_length); } -template -void ESP8266WebServerTemplate::send_P(int code, PGM_P content_type, PGM_P content) { - StreamConstPtr ref(content, strlen_P(content)); - return send(code, String(content_type).c_str(), &ref); -} - -template -void ESP8266WebServerTemplate::send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) { - StreamConstPtr ref(content, contentLength); - return send(code, String(content_type).c_str(), &ref); -} - template void ESP8266WebServerTemplate::sendContent(Stream* content, ssize_t content_length /* = 0*/) { if (_currentMethod == HTTP_HEAD) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index e0dba27a90..4b72df4637 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -155,25 +155,37 @@ class ESP8266WebServerTemplate // code - HTTP response code, can be 200 or 404 // content_type - HTTP content type, like "text/plain" or "image/png" // content - actual content body - void send(int code, const char* content_type = NULL, const String& content = emptyString); - void send(int code, char* content_type, const String& content); - void send(int code, const String& content_type, const String& content); - void send(int code, const char *content_type, const char *content) { + void send(int code, const char* content_type = NULL, const String& content = emptyString) { + return send(code, content_type, content.c_str(), content.length()); + } + void send(int code, char* content_type, const String& content) { + return send(code, (const char*)content_type, content); + } + void send(int code, const String& content_type, const String& content) { + return send(code, (const char*)content_type.c_str(), content); + } + void send(int code, const char* content_type, const char* content) { send_P(code, content_type, content); } - void send(int code, const char *content_type, const char *content, size_t content_length) { + void send(int code, const char* content_type, const char* content, size_t content_length) { send_P(code, content_type, content, content_length); } - void send(int code, const char *content_type, const uint8_t *content, size_t content_length) { - send_P(code, content_type, (const char *)content, content_length); + void send(int code, const char* content_type, const uint8_t* content, size_t content_length) { + send_P(code, content_type, (const char* )content, content_length); } - 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 send(int code, const char* content_type, Stream* stream, size_t content_length = 0); void send(int code, const char* content_type, Stream& stream, size_t content_length = 0) { send(code, content_type, &stream, content_length); } + void send_P(int code, PGM_P content_type, PGM_P content) { + StreamConstPtr ref(content, strlen_P(content)); + return send(code, String(content_type).c_str(), &ref); + } + void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) { + StreamConstPtr ref(content, contentLength); + return send(code, String(content_type).c_str(), &ref); + } + + void send(int code, const char* content_type, Stream* stream, size_t content_length = 0); void setContentLength(const size_t contentLength); void sendHeader(const String& name, const String& value, bool first = false); From 235746c3839a3f992c1d4787aa7e773a6e52c839 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 6 Mar 2023 21:30:32 +0100 Subject: [PATCH 3/4] wip --- .../ESP8266WebServer/src/ESP8266WebServer.h | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index 4b72df4637..0ca61553ee 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -155,6 +155,40 @@ class ESP8266WebServerTemplate // code - HTTP response code, can be 200 or 404 // content_type - HTTP content type, like "text/plain" or "image/png" // content - actual content body + +#if 0 + + void send(int code) { send(code, nullptr, nullptr); } + + template + void send(int code, CT&& content_type, CD&& content) + { + String(std::forward(content_type)) content_type_forwarded; + StreamConstPtr(std::forward(content)) content_forwarded; + send(code, content_type_forwarded.c_str(), &content_forwarded); + } + + template + void send(int code, CT&& content_type, C&& content, size_t content_length) + { + String(std::forward(content_type)) content_type_forwarded; + StreamConstPtr(std::forward(content), content_length) content_forwarded; + send(code, content_type_forwarded.c_str(), &content_forwarded); + } + + template + void send(int code, CT&& content_type, Stream* stream, size_t content_length = 0) + { + String(std::forward(content_type)) content_type_forwarded; + send(code, content_type_forwarded.c_str(), stream, content_length); + } + +send_P + + +#else + + void send(int code, const char* content_type = NULL, const String& content = emptyString) { return send(code, content_type, content.c_str(), content.length()); } @@ -185,6 +219,8 @@ class ESP8266WebServerTemplate return send(code, String(content_type).c_str(), &ref); } +#endif + void send(int code, const char* content_type, Stream* stream, size_t content_length = 0); void setContentLength(const size_t contentLength); From 00ee06205e8a1132e77b9368a802fd870e0e00a5 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Sat, 9 Dec 2023 16:34:38 +0100 Subject: [PATCH 4/4] remove duplicate --- libraries/ESP8266WiFi/src/WiFi.h | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 libraries/ESP8266WiFi/src/WiFi.h diff --git a/libraries/ESP8266WiFi/src/WiFi.h b/libraries/ESP8266WiFi/src/WiFi.h deleted file mode 100644 index 379989252d..0000000000 --- a/libraries/ESP8266WiFi/src/WiFi.h +++ /dev/null @@ -1,2 +0,0 @@ - -#include "ESP8266WiFi.h" \ No newline at end of file