Skip to content

Adding ESP32 support and fix for ESP32 v 1.0.2 #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a mechanism for setting the timeout:
https://www.arduino.cc/en/Reference/EthernetClientSetConnectionTimeout

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);
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related: #88
It seems like it would be better for the ESP32 core developers to follow the standard Arduino core API, rather than forcing every library to be patched to deal with the breakage they caused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the ESP folks appear to have strayed from the Arduino API. Not good.

#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();
Expand Down
15 changes: 15 additions & 0 deletions src/EthernetClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 19 additions & 1 deletion src/EthernetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down