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.0KB

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