ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

httpserver.h 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef __HTTPSERVER_H
  2. #define __HTTPSERVER_H
  3. #include "filesys.h"
  4. #include <ESP8266WebServer.h>
  5. class HTTPServer : public ESP8266WebServer {
  6. private:
  7. const char* rootDir;
  8. bool addRootFileHandler();
  9. bool formatFS() {
  10. return format_fs();
  11. }
  12. void listRoot() {
  13. ls(rootDir);
  14. }
  15. public:
  16. HTTPServer(const int _port, const char* _rootDir) :
  17. ESP8266WebServer(_port), rootDir(_rootDir)
  18. { }
  19. ~HTTPServer()
  20. {
  21. Serial.printf("[HTTPServer] shut down ...\n\r");
  22. }
  23. bool start() {
  24. if(!mount_fs())
  25. return false;
  26. Serial.printf("[HTTPServer] LittleFS mounted !\n\r");
  27. Serial.printf("[HTTPServer] root:\n\r");
  28. this->listRoot();
  29. Serial.printf("\n\r");
  30. if( this->addRootFileHandler() ){
  31. this->begin();
  32. Serial.printf("[HTTPServer] Server active on Port 80 !\n\r");
  33. return true;
  34. }
  35. Serial.printf("[HTTPServer] Not starting Server, something went wrong !\n\r");
  36. return false;
  37. }
  38. };
  39. #endif // __HTTPSERVER_H