MiLightHttpServer.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <WebServer.h>
  2. #include <MiLightClient.h>
  3. #include <Settings.h>
  4. #ifndef _MILIGHT_HTTP_SERVER
  5. #define _MILIGHT_HTTP_SERVER
  6. typedef std::function<void(void)> SettingsSavedHandler;
  7. class MiLightHttpServer {
  8. public:
  9. MiLightHttpServer(Settings& settings, MiLightClient*& milightClient)
  10. : server(WebServer(80)),
  11. milightClient(milightClient),
  12. settings(settings)
  13. {
  14. this->applySettings(settings);
  15. }
  16. void begin();
  17. void handleClient();
  18. void onSettingsSaved(SettingsSavedHandler handler);
  19. protected:
  20. ESP8266WebServer::THandlerFunction handleServeFile(
  21. const char* filename,
  22. const char* contentType,
  23. const char* defaultText = NULL);
  24. bool serveFile(const char* file, const char* contentType = "text/html");
  25. ESP8266WebServer::THandlerFunction handleUpdateFile(const char* filename);
  26. void applySettings(Settings& settings);
  27. void handleUpdateSettings();
  28. void handleListenGateway(const UrlTokenBindings* urlBindings);
  29. void handleUpdateGroup(const UrlTokenBindings* urlBindings);
  30. void handleUpdateGateway(const UrlTokenBindings* urlBindings);
  31. File updateFile;
  32. WebServer server;
  33. Settings& settings;
  34. MiLightClient*& milightClient;
  35. SettingsSavedHandler settingsSavedHandler;
  36. };
  37. #endif