MiLightHttpServer.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <WebServer.h>
  2. #include <MiLightClient.h>
  3. #include <Settings.h>
  4. #ifndef _MILIGHT_HTTP_SERVER
  5. #define _MILIGHT_HTTP_SERVER
  6. #define MAX_DOWNLOAD_ATTEMPTS 3
  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 handleGetRadioConfigs();
  30. void handleAbout();
  31. void handleListenGateway(const UrlTokenBindings* urlBindings);
  32. void handleSendRaw(const UrlTokenBindings* urlBindings);
  33. void handleUpdateGroup(const UrlTokenBindings* urlBindings);
  34. void handleUpdateGateway(const UrlTokenBindings* urlBindings);
  35. void handleDownloadUpdate(const UrlTokenBindings* urlBindings);
  36. File updateFile;
  37. WebServer server;
  38. Settings& settings;
  39. MiLightClient*& milightClient;
  40. SettingsSavedHandler settingsSavedHandler;
  41. };
  42. #endif