From cdd6fa31c01827708a3e916e19519df1dbed2082 Mon Sep 17 00:00:00 2001 From: Plamen Kovandjiev Date: Sun, 21 Apr 2019 20:28:51 +0300 Subject: [PATCH 1/2] Add ESP32 support Adding ESP32 support in Ethernet 2.0.0 library. Especially for ESP32 v1.0.2 --- src/Ethernet.h | 12 ++++++++++++ src/EthernetClient.cpp | 15 +++++++++++++++ src/EthernetServer.cpp | 20 +++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Ethernet.h b/src/Ethernet.h index 376e6c59..e1ee885f 100644 --- a/src/Ethernet.h +++ b/src/Ethernet.h @@ -219,6 +219,11 @@ class EthernetClient : public Client { uint8_t status(); virtual int connect(IPAddress ip, uint16_t port); virtual int connect(const char *host, uint16_t port); + // 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. +#ifdef ESP32 + virtual int connect(IPAddress ip, uint16_t port, int timeout); + virtual int connect(const char *host, uint16_t port, int timeout); +#endif virtual int availableForWrite(void); virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buf, size_t size); @@ -253,11 +258,18 @@ class EthernetClient : public Client { class EthernetServer : public Server { private: uint16_t _port; + // 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. + void init(); public: EthernetServer(uint16_t port) : _port(port) { } EthernetClient available(); EthernetClient accept(); + // 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. +#ifdef ESP32 + virtual void begin(uint16_t port = 0); +#else virtual void begin(); +#endif virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buf, size_t size); virtual operator bool(); diff --git a/src/EthernetClient.cpp b/src/EthernetClient.cpp index e2406d7d..c08ebafa 100644 --- a/src/EthernetClient.cpp +++ b/src/EthernetClient.cpp @@ -69,6 +69,21 @@ int EthernetClient::connect(IPAddress ip, uint16_t port) return 0; } +// 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. +#ifdef ESP32 +int EthernetClient::connect(const char * host, uint16_t port, int timeout) +{ + // timeout processing is not implemented. + return connect(host, port); +} + +int EthernetClient::connect(IPAddress ip, uint16_t port, int timeout) +{ + // timeout processing is not implemented. + return connect(ip, port); +} +#endif + int EthernetClient::availableForWrite(void) { if (sockindex >= MAX_SOCK_NUM) return 0; diff --git a/src/EthernetServer.cpp b/src/EthernetServer.cpp index ddebd154..0af83694 100644 --- a/src/EthernetServer.cpp +++ b/src/EthernetServer.cpp @@ -25,7 +25,8 @@ uint16_t EthernetServer::server_port[MAX_SOCK_NUM]; -void EthernetServer::begin() +// 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. +void EthernetServer::init() { uint8_t sockindex = Ethernet.socketBegin(SnMR::TCP, _port); if (sockindex < MAX_SOCK_NUM) { @@ -37,6 +38,23 @@ void EthernetServer::begin() } } +// 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. +#ifdef ESP32 +void EthernetServer::begin(uint16_t port) +{ + if (port) { + _port = port; + } + + init(); +} +#else +void EthernetServer::begin() +{ + init(); +} +#endif + EthernetClient EthernetServer::available() { bool listening = false; From c607a1b764c5185eb5fc3c62aa5b1fa8ff5106ab Mon Sep 17 00:00:00 2001 From: Plamen Kovandjiev Date: Thu, 26 Sep 2019 20:50:37 +0300 Subject: [PATCH 2/2] Remove EthernetClient::connect() specific method for ESP32 --- AUTHORS | 1 + src/Ethernet.h | 9 +-------- src/EthernetClient.cpp | 15 --------------- src/EthernetServer.cpp | 9 +++------ 4 files changed, 5 insertions(+), 29 deletions(-) diff --git a/AUTHORS b/AUTHORS index 14097dff..80168838 100644 --- a/AUTHORS +++ b/AUTHORS @@ -29,6 +29,7 @@ Michael Margolis https://github.com/michaelmargolis Norbert Truchsess https://github.com/ntruchsess Paul Stoffregen https://github.com/PaulStoffregen per1234 https://github.com/per1234 +KMPElectronics https://github.com/kmpelectronics Richard Sim Scott Fitzgerald https://github.com/shfitz Thibaut Viard https://github.com/aethaniel diff --git a/src/Ethernet.h b/src/Ethernet.h index e1ee885f..7f8fcb0e 100644 --- a/src/Ethernet.h +++ b/src/Ethernet.h @@ -219,11 +219,6 @@ class EthernetClient : public Client { uint8_t status(); virtual int connect(IPAddress ip, uint16_t port); virtual int connect(const char *host, uint16_t port); - // 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. -#ifdef ESP32 - virtual int connect(IPAddress ip, uint16_t port, int timeout); - virtual int connect(const char *host, uint16_t port, int timeout); -#endif virtual int availableForWrite(void); virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buf, size_t size); @@ -258,13 +253,11 @@ class EthernetClient : public Client { class EthernetServer : public Server { private: uint16_t _port; - // 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. - void init(); + void initSocket(); public: EthernetServer(uint16_t port) : _port(port) { } EthernetClient available(); EthernetClient accept(); - // 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. #ifdef ESP32 virtual void begin(uint16_t port = 0); #else diff --git a/src/EthernetClient.cpp b/src/EthernetClient.cpp index c08ebafa..e2406d7d 100644 --- a/src/EthernetClient.cpp +++ b/src/EthernetClient.cpp @@ -69,21 +69,6 @@ int EthernetClient::connect(IPAddress ip, uint16_t port) return 0; } -// 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. -#ifdef ESP32 -int EthernetClient::connect(const char * host, uint16_t port, int timeout) -{ - // timeout processing is not implemented. - return connect(host, port); -} - -int EthernetClient::connect(IPAddress ip, uint16_t port, int timeout) -{ - // timeout processing is not implemented. - return connect(ip, port); -} -#endif - int EthernetClient::availableForWrite(void) { if (sockindex >= MAX_SOCK_NUM) return 0; diff --git a/src/EthernetServer.cpp b/src/EthernetServer.cpp index 0af83694..d9b7bf8b 100644 --- a/src/EthernetServer.cpp +++ b/src/EthernetServer.cpp @@ -24,9 +24,7 @@ uint16_t EthernetServer::server_port[MAX_SOCK_NUM]; - -// 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. -void EthernetServer::init() +void EthernetServer::initSocket() { uint8_t sockindex = Ethernet.socketBegin(SnMR::TCP, _port); if (sockindex < MAX_SOCK_NUM) { @@ -38,7 +36,6 @@ void EthernetServer::init() } } -// 20190421 https://kmpelectronics.eu/ Plamen Kovandjiev - We added support for ESP32. #ifdef ESP32 void EthernetServer::begin(uint16_t port) { @@ -46,12 +43,12 @@ void EthernetServer::begin(uint16_t port) _port = port; } - init(); + initSocket(); } #else void EthernetServer::begin() { - init(); + initSocket(); } #endif