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.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "httpserver.h"
  2. bool HTTPServer::start() {
  3. if(!mount_fs()) {
  4. logf("cant mount filesystem, EXIT !\n\r");
  5. return false;
  6. }
  7. logf("[HTTPServer] LittleFS mounted !\n\r");
  8. logf("[HTTPServer] root:\n\r");
  9. this->listRoot();
  10. logf("\n\r");
  11. // default handler
  12. this->onNotFound([this]() {
  13. String message = "File Not Found\n\n";
  14. message += "URI: ";
  15. message += uri();
  16. message += "\nMethod: ";
  17. message += (method() == HTTP_GET) ? "GET" : "POST";
  18. message += "\nArguments: ";
  19. message += args();
  20. message += "\n";
  21. for (uint8_t i = 0; i < args(); i++) {
  22. message += " " + argName(i) + ": " + arg(i) + "\n";
  23. }
  24. send(404, "text/plain", message);
  25. });
  26. // add static root file handler for http
  27. this->serveStatic("/", LittleFS, "/");
  28. // application handler
  29. this->on("/app=terminal", HTTP_POST, [this]() {
  30. String log_msg = "terminal: millis: ";
  31. log_msg += millis();
  32. send(200, "text/plain", log_msg);
  33. });
  34. this->begin();
  35. Serial.printf("[HTTPServer] Server active on Port 80 !\n\r");
  36. return true;
  37. }