MiLightHttpServer.h 1.6 KB

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