MiLightHttpServer.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 handleSendRaw(const UrlTokenBindings* urlBindings);
  30. void handleUpdateGroup(const UrlTokenBindings* urlBindings);
  31. void handleUpdateGateway(const UrlTokenBindings* urlBindings);
  32. File updateFile;
  33. WebServer server;
  34. Settings& settings;
  35. MiLightClient*& milightClient;
  36. SettingsSavedHandler settingsSavedHandler;
  37. };
  38. #endif