ethernet webserver works too

This commit is contained in:
technyon
2022-04-29 21:16:09 +02:00
parent 0e9baed3a4
commit 5b12e54be0
12 changed files with 263 additions and 13 deletions

View File

@@ -0,0 +1,90 @@
#include "W5500EthClient.h"
W5500EthClient::W5500EthClient(EthernetClient *wifiClient)
: _ethClient(wifiClient)
{
}
W5500EthClient::~W5500EthClient()
{
_ethClient = nullptr;
}
uint8_t W5500EthClient::connected()
{
return _ethClient->connected();
}
int W5500EthClient::setTimeout(uint32_t seconds)
{
// return _ethClient->setTimeout(seconds);
}
size_t W5500EthClient::write(const char *buffer, size_t size)
{
return _ethClient->write(buffer, size);
}
IPAddress W5500EthClient::localIP()
{
return IPAddress(0,0,0,0);
}
void W5500EthClient::stop()
{
_ethClient->stop();
}
size_t W5500EthClient::write_P(const char *buf, size_t size)
{
return _ethClient->write(buf, size);
}
int W5500EthClient::available()
{
return _ethClient->available();
}
String W5500EthClient::readStringUntil(char terminator)
{
return _ethClient->readStringUntil(terminator);
}
size_t W5500EthClient::readBytes(char *buffer, size_t length)
{
return _ethClient->readBytes(buffer, length);
}
void W5500EthClient::flush()
{
_ethClient->flush();
}
int W5500EthClient::read()
{
return _ethClient->read();
}
unsigned long W5500EthClient::getTimeout(void)
{
return _ethClient->getTimeout();
}
size_t W5500EthClient::write(Stream &stream)
{
uint8_t * buf = (uint8_t *)malloc(1360);
if(!buf){
return 0;
}
size_t toRead = 0, toWrite = 0, written = 0;
size_t available = stream.available();
while(available){
toRead = (available > 1360)?1360:available;
toWrite = stream.readBytes(buf, toRead);
written += _ethClient->write(buf, toWrite);
available = stream.available();
}
free(buf);
return written;
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <WiFiClient.h>
#include <EthernetClient.h>
#include "EthClient.h"
class W5500EthClient : public EthClient
{
public:
explicit W5500EthClient(EthernetClient* wifiClient);
virtual ~W5500EthClient();
uint8_t connected() override;
int available() override;
unsigned long getTimeout(void) override;
int setTimeout(uint32_t seconds) override;
int read() override;
size_t write(const char *buffer, size_t size) override;
size_t write(Stream &stream) override;
size_t write_P(const char *buf, size_t size) override;
String readStringUntil(char terminator) override;
size_t readBytes(char *buffer, size_t length) override;
IPAddress localIP() override;
void stop() override;
void flush() override;
private:
EthernetClient* _ethClient;
};

View File

@@ -0,0 +1,75 @@
#include "W5500EthServer.h"
W5500EthServer::W5500EthServer(IPAddress address, int port)
: EthServer(address, port),
_ethServer(address, port)
{
}
W5500EthServer::W5500EthServer(int port)
: EthServer(port),
_ethServer(port)
{
}
void W5500EthServer::close()
{
// _ethServer.close();
}
void W5500EthServer::begin(const int port)
{
_ethServer.begin(port);
}
void W5500EthServer::setNoDelay(const bool value)
{
// _ethServer.setNoDelay(value);
}
EthClient* W5500EthServer::available()
{
if(_W5500EthClient != nullptr)
{
delete _W5500EthClient;
_W5500EthClient = nullptr;
}
_ethClient = _ethServer.available();
_W5500EthClient = new W5500EthClient(&_ethClient);
return _W5500EthClient;
}
void W5500EthServer::discardClient()
{
if(_W5500EthClient != nullptr)
{
delete _W5500EthClient;
_W5500EthClient = nullptr;
}
_ethClient = EthernetClient();
}
// EthernetServerImpl
void EthernetServerImpl::begin(uint16_t port)
{
EthernetServer::begin();
}
EthernetServerImpl::EthernetServerImpl(int address, int port)
: EthernetServer(port)
{
}
EthernetServerImpl::EthernetServerImpl(int port)
: EthernetServer(port)
{
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include "EthServer.h"
#include "W5500EthClient.h"
#include <WiFiServer.h>
#include <EthernetServer.h>
class EthernetServerImpl : public EthernetServer
{
public:
EthernetServerImpl(int address, int port);
explicit EthernetServerImpl(int port);
virtual void begin(uint16_t port);
};
class W5500EthServer : public EthServer
{
public:
W5500EthServer(IPAddress address, int port);
explicit W5500EthServer(int port);
virtual EthClient* available();
virtual void discardClient();
virtual void begin(const int port = 80);
virtual void close();
virtual void setNoDelay(const bool value);
private:
EthernetServerImpl _ethServer;
EthernetClient _ethClient;
W5500EthClient* _W5500EthClient = nullptr;
};