ESP8266_Treppenlicht/include/httpserver.h

48 lines
1.1 KiB
C
Raw Normal View History

2021-06-22 18:25:27 +00:00
#ifndef __HTTPSERVER_H
#define __HTTPSERVER_H
2021-06-23 13:22:38 +00:00
#include "filesys.h"
2021-06-22 18:25:27 +00:00
#include <ESP8266WebServer.h>
2021-06-23 13:22:38 +00:00
2021-06-23 14:12:19 +00:00
class HTTPServer : public ESP8266WebServer {
2021-06-22 18:25:27 +00:00
private:
2021-06-23 13:22:38 +00:00
const char* rootDir;
bool addRootFileHandler();
bool formatFS() {
return format_fs();
}
void listRoot() {
ls(rootDir);
}
2021-06-22 18:25:27 +00:00
public:
2021-06-23 14:12:19 +00:00
HTTPServer(const int _port, const char* _rootDir) :
ESP8266WebServer(_port), rootDir(_rootDir)
2021-06-23 13:22:38 +00:00
{ }
~HTTPServer()
{
2021-06-23 14:12:19 +00:00
Serial.printf("[HTTPServer] shut down ...\n\r");
2021-06-22 18:25:27 +00:00
}
2021-06-23 13:22:38 +00:00
bool start() {
if(!mount_fs())
return false;
2021-06-23 14:12:19 +00:00
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;
2021-06-22 18:25:27 +00:00
}
};
#endif // __HTTPSERVER_H