MiLightHttpServer.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <WebServer.h>
  2. #include <MiLightClient.h>
  3. #include <Settings.h>
  4. #ifndef _MILIGHT_HTTP_SERVER
  5. #define _MILIGHT_HTTP_SERVER
  6. #define MILIGHT_RESEND_COUNT_FOR_HTTP 50
  7. typedef std::function<void(void)> SettingsSavedHandler;
  8. class MiLightHttpServer {
  9. public:
  10. MiLightHttpServer(Settings& settings, MiLightClient*& milightClient)
  11. : server(WebServer(80)),
  12. milightClient(milightClient),
  13. settings(settings)
  14. {
  15. this->applySettings(settings);
  16. }
  17. void begin();
  18. void handleClient();
  19. void onSettingsSaved(SettingsSavedHandler handler);
  20. protected:
  21. ESP8266WebServer::THandlerFunction handleServeFile(
  22. const char* filename,
  23. const char* contentType,
  24. const char* defaultText = NULL);
  25. bool serveFile(const char* file, const char* contentType = "text/html");
  26. ESP8266WebServer::THandlerFunction handleUpdateFile(const char* filename);
  27. void applySettings(Settings& settings);
  28. void handleUpdateSettings();
  29. void handleListenGateway();
  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