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 all commits
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,16 @@ class EthernetClient : public Client {
class EthernetServer : public Server {
private:
uint16_t _port;
void initSocket();
public:
EthernetServer(uint16_t port) : _port(port) { }
EthernetClient available();
EthernetClient accept();
#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
19 changes: 17 additions & 2 deletions src/EthernetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

uint16_t EthernetServer::server_port[MAX_SOCK_NUM];


void EthernetServer::begin()
void EthernetServer::initSocket()
{
uint8_t sockindex = Ethernet.socketBegin(SnMR::TCP, _port);
if (sockindex < MAX_SOCK_NUM) {
Expand All @@ -37,6 +36,22 @@ void EthernetServer::begin()
}
}

#ifdef ESP32
void EthernetServer::begin(uint16_t port)
{
if (port) {
_port = port;
}

initSocket();
}
#else
void EthernetServer::begin()
{
initSocket();
}
#endif

EthernetClient EthernetServer::available()
{
bool listening = false;
Expand Down