implement EthWebServer
This commit is contained in:
@@ -30,6 +30,7 @@ file(GLOB SRCFILES
|
|||||||
Version.h
|
Version.h
|
||||||
webserver/AbstractWebServer.h
|
webserver/AbstractWebServer.h
|
||||||
webserver/EthWebServer.cpp
|
webserver/EthWebServer.cpp
|
||||||
|
webserver/WifiWebServer.cpp
|
||||||
lib/ESP32_BLE_Arduino-1.0.1/src/*.cpp
|
lib/ESP32_BLE_Arduino-1.0.1/src/*.cpp
|
||||||
lib/ESP32_BLE_Arduino-1.0.1/src/*.h
|
lib/ESP32_BLE_Arduino-1.0.1/src/*.h
|
||||||
lib/WiFiManager/WiFiManager.cpp
|
lib/WiFiManager/WiFiManager.cpp
|
||||||
@@ -54,7 +55,7 @@ add_executable(${PROJECT_NAME}
|
|||||||
main.cpp
|
main.cpp
|
||||||
${SRCFILES}
|
${SRCFILES}
|
||||||
${SRCFILESREC}
|
${SRCFILESREC}
|
||||||
webserver/EthWebServer.cpp webserver/EthWebServer.h)
|
)
|
||||||
|
|
||||||
# Arduino.h is included in hello_world.cpp, so link with Arduino core
|
# Arduino.h is included in hello_world.cpp, so link with Arduino core
|
||||||
target_link_arduino_libraries(${PROJECT_NAME}
|
target_link_arduino_libraries(${PROJECT_NAME}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "EthernetWebServer.h"
|
#include <functional>
|
||||||
|
#include <WString.h>
|
||||||
|
|
||||||
|
typedef std::function<void(void)> THandlerFunction;
|
||||||
|
class Uri;
|
||||||
|
|
||||||
class AbstractWebServer
|
class AbstractWebServer
|
||||||
{
|
{
|
||||||
@@ -9,10 +13,10 @@ public:
|
|||||||
|
|
||||||
virtual void begin() = 0;
|
virtual void begin() = 0;
|
||||||
virtual bool authenticate(const char * username, const char * password) = 0;
|
virtual bool authenticate(const char * username, const char * password) = 0;
|
||||||
virtual void requestAuthentication(HTTPAuthMethod mode, const char* realm, const String& authFailMsg) = 0;
|
virtual void requestAuthentication(int mode, const char* realm, const String& authFailMsg) = 0;
|
||||||
virtual void requestAuthentication() = 0;
|
virtual void requestAuthentication() = 0;
|
||||||
virtual void send(int code, const char* content_type, const String& content) = 0;
|
virtual void send(int code, const char* content_type, const String& content) = 0;
|
||||||
virtual void on(const Uri &uri, EthernetWebServer::THandlerFunction handler) = 0;
|
virtual void on(const Uri &uri, THandlerFunction handler) = 0;
|
||||||
virtual int args() = 0;
|
virtual int args() = 0;
|
||||||
virtual String arg(int i) = 0;
|
virtual String arg(int i) = 0;
|
||||||
virtual String argName(int i) = 0;
|
virtual String argName(int i) = 0;
|
||||||
|
|||||||
@@ -17,9 +17,14 @@ bool EthWebServer::authenticate(const char *username, const char *password)
|
|||||||
return _server.authenticate(username, password);
|
return _server.authenticate(username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthWebServer::requestAuthentication(HTTPAuthMethod mode, const char *realm, const String &authFailMsg)
|
void EthWebServer::requestAuthentication(int mode, const char *realm, const String &authFailMsg)
|
||||||
{
|
{
|
||||||
return _server.requestAuthentication(mode, realm, authFailMsg);
|
return _server.requestAuthentication((HTTPAuthMethod)mode, realm, authFailMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EthWebServer::requestAuthentication()
|
||||||
|
{
|
||||||
|
return requestAuthentication(HTTPAuthMethod::BASIC_AUTH, "*", "Authentication failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthWebServer::send(int code, const char *content_type, const String &content)
|
void EthWebServer::send(int code, const char *content_type, const String &content)
|
||||||
@@ -32,11 +37,6 @@ void EthWebServer::on(const Uri &uri, EthernetWebServer::THandlerFunction handle
|
|||||||
_server.on(uri, handler);
|
_server.on(uri, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthWebServer::requestAuthentication()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int EthWebServer::args()
|
int EthWebServer::args()
|
||||||
{
|
{
|
||||||
return _server.args();
|
return _server.args();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "AbstractWebServer.h"
|
#include "AbstractWebServer.h"
|
||||||
|
#include "EthernetWebServer.h"
|
||||||
|
|
||||||
class EthWebServer : public AbstractWebServer
|
class EthWebServer : public AbstractWebServer
|
||||||
{
|
{
|
||||||
@@ -9,17 +10,13 @@ public:
|
|||||||
|
|
||||||
virtual void begin();
|
virtual void begin();
|
||||||
virtual bool authenticate(const char *username, const char *password);
|
virtual bool authenticate(const char *username, const char *password);
|
||||||
virtual void requestAuthentication(HTTPAuthMethod mode, const char *realm, const String &authFailMsg);
|
virtual void requestAuthentication(int mode, const char *realm, const String &authFailMsg);
|
||||||
virtual void requestAuthentication();
|
virtual void requestAuthentication();
|
||||||
virtual void send(int code, const char *content_type, const String &content);
|
virtual void send(int code, const char *content_type, const String &content);
|
||||||
virtual void on(const Uri &uri, EthernetWebServer::THandlerFunction handler);
|
virtual void on(const Uri &uri, THandlerFunction handler);
|
||||||
|
|
||||||
virtual int args();
|
virtual int args();
|
||||||
|
|
||||||
virtual String arg(int i);
|
virtual String arg(int i);
|
||||||
|
|
||||||
virtual String argName(int i);
|
virtual String argName(int i);
|
||||||
|
|
||||||
virtual void handleClient();
|
virtual void handleClient();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
57
webserver/WifiWebServer.cpp
Normal file
57
webserver/WifiWebServer.cpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include "WifiWebServer.h"
|
||||||
|
|
||||||
|
WifiWebServer::WifiWebServer(int port)
|
||||||
|
: AbstractWebServer(port),
|
||||||
|
_server(port)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void WifiWebServer::begin()
|
||||||
|
{
|
||||||
|
_server.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WifiWebServer::authenticate(const char *username, const char *password)
|
||||||
|
{
|
||||||
|
return _server.authenticate(username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WifiWebServer::requestAuthentication(int mode, const char *realm, const String &authFailMsg)
|
||||||
|
{
|
||||||
|
return _server.requestAuthentication((HTTPAuthMethod)mode, realm, authFailMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WifiWebServer::send(int code, const char *content_type, const String &content)
|
||||||
|
{
|
||||||
|
_server.send(code, content_type, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WifiWebServer::on(const Uri &uri, WebServer::THandlerFunction handler)
|
||||||
|
{
|
||||||
|
_server.on(uri, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WifiWebServer::requestAuthentication()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int WifiWebServer::args()
|
||||||
|
{
|
||||||
|
return _server.args();
|
||||||
|
}
|
||||||
|
|
||||||
|
String WifiWebServer::arg(int i)
|
||||||
|
{
|
||||||
|
return _server.arg(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
String WifiWebServer::argName(int i)
|
||||||
|
{
|
||||||
|
return _server.argName(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WifiWebServer::handleClient()
|
||||||
|
{
|
||||||
|
_server.handleClient();
|
||||||
|
}
|
||||||
24
webserver/WifiWebServer.h
Normal file
24
webserver/WifiWebServer.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <WebServer.h>
|
||||||
|
#include "AbstractWebServer.h"
|
||||||
|
|
||||||
|
class WifiWebServer : public AbstractWebServer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit WifiWebServer(int port);
|
||||||
|
|
||||||
|
virtual void begin();
|
||||||
|
virtual bool authenticate(const char *username, const char *password);
|
||||||
|
virtual void requestAuthentication(int mode, const char *realm, const String &authFailMsg);
|
||||||
|
virtual void requestAuthentication();
|
||||||
|
virtual void send(int code, const char *content_type, const String &content);
|
||||||
|
virtual void on(const Uri &uri, WebServer::THandlerFunction handler);
|
||||||
|
virtual int args();
|
||||||
|
virtual String arg(int i);
|
||||||
|
virtual String argName(int i);
|
||||||
|
virtual void handleClient();
|
||||||
|
|
||||||
|
private:
|
||||||
|
WebServer _server;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user