MiLightHttpServer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. typedef std::function<void(void)> LongPollLoopFn;
  9. const char DEFAULT_INDEX_PAGE[] PROGMEM
  10. = "Web app not installed. Click <a href=\"/download_update/web\">here</a> to attempt to download it from GitHub.";
  11. class MiLightHttpServer {
  12. public:
  13. MiLightHttpServer(Settings& settings, MiLightClient*& milightClient)
  14. : server(WebServer(80)),
  15. milightClient(milightClient),
  16. settings(settings)
  17. {
  18. this->applySettings(settings);
  19. }
  20. void begin();
  21. void handleClient();
  22. void onSettingsSaved(SettingsSavedHandler handler);
  23. void onLongPollLoop(LongPollLoopFn);
  24. protected:
  25. ESP8266WebServer::THandlerFunction handleServeFile(
  26. const char* filename,
  27. const char* contentType,
  28. const char* defaultText = NULL);
  29. bool serveFile(const char* file, const char* contentType = "text/html");
  30. ESP8266WebServer::THandlerFunction handleUpdateFile(const char* filename);
  31. void applySettings(Settings& settings);
  32. void handleUpdateSettings();
  33. void handleGetRadioConfigs();
  34. void handleAbout();
  35. void handleSystemPost();
  36. void handleListenGateway(const UrlTokenBindings* urlBindings);
  37. void handleSendRaw(const UrlTokenBindings* urlBindings);
  38. void handleUpdateGroup(const UrlTokenBindings* urlBindings);
  39. void handleDownloadUpdate(const UrlTokenBindings* urlBindings);
  40. File updateFile;
  41. WebServer server;
  42. Settings& settings;
  43. MiLightClient*& milightClient;
  44. SettingsSavedHandler settingsSavedHandler;
  45. LongPollLoopFn longPollLoopFn;
  46. };
  47. #endif