48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
#ifndef __HTTPSERVER_H
|
|
#define __HTTPSERVER_H
|
|
|
|
#include "filesys.h"
|
|
#include <ESP8266WebServer.h>
|
|
|
|
|
|
class HTTPServer : public ESP8266WebServer {
|
|
private:
|
|
const char* rootDir;
|
|
|
|
bool addRootFileHandler();
|
|
bool formatFS() {
|
|
return format_fs();
|
|
}
|
|
void listRoot() {
|
|
ls(rootDir);
|
|
}
|
|
|
|
public:
|
|
HTTPServer(const int _port, const char* _rootDir) :
|
|
ESP8266WebServer(_port), rootDir(_rootDir)
|
|
{ }
|
|
~HTTPServer()
|
|
{
|
|
Serial.printf("[HTTPServer] shut down ...\n\r");
|
|
}
|
|
|
|
bool start() {
|
|
if(!mount_fs())
|
|
return false;
|
|
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
|