added httpserver with inheritance

This commit is contained in:
2021-06-23 16:12:19 +02:00
parent 006404fccf
commit ff6b82867c
3 changed files with 33 additions and 34 deletions
+17 -17
View File
@@ -5,12 +5,9 @@
#include <ESP8266WebServer.h>
class HTTPServer {
class HTTPServer : public ESP8266WebServer {
private:
bool configured = false;
const int port;
const char* rootDir;
std::function<void ()> callbackFn;
bool addRootFileHandler();
bool formatFS() {
@@ -21,28 +18,31 @@ private:
}
public:
ESP8266WebServer server;
HTTPServer(const int _port, const char* _rootDir, std::function<void ()> fn) :
port(_port), rootDir(_rootDir), callbackFn(fn)
HTTPServer(const int _port, const char* _rootDir) :
ESP8266WebServer(_port), rootDir(_rootDir)
{ }
~HTTPServer()
{
server.stop();
Serial.printf("[HTTPServer] shut down ...\n\r");
}
bool start() {
if(!mount_fs())
return false;
Serial.printf("LittleFS mounted => Starting Webserver on Port %d\n\r", this->port);
server.begin(port);
return true;
}
void handleClient() {
server.handleClient();
Serial.printf("[HTTPServer] LittleFS mounted !\n\r");
Serial.printf("[HTTPServer] root:\n\r");
this->listRoot();
Serial.printf("\n\r");
if( this->addRootFileHandler() ){
this->begin();
Serial.printf("[HTTPServer] Server active on Port 80 !\n\r");
return true;
}
Serial.printf("[HTTPServer] Not starting Server, something went wrong !\n\r");
return false;
}
};
#endif // __HTTPSERVER_H