MiLightHttpServer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. void on(const char* path, HTTPMethod method, ESP8266WebServer::THandlerFunction handler);
  23. WiFiClient client();
  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 handleGetLatestRelease();
  36. void handleSystemPost();
  37. void handleListenGateway(const UrlTokenBindings* urlBindings);
  38. void handleSendRaw(const UrlTokenBindings* urlBindings);
  39. void handleUpdateGroup(const UrlTokenBindings* urlBindings);
  40. void handleDownloadUpdate(const UrlTokenBindings* urlBindings);
  41. void handleRequest(const JsonObject& request);
  42. File updateFile;
  43. WebServer server;
  44. Settings& settings;
  45. MiLightClient*& milightClient;
  46. SettingsSavedHandler settingsSavedHandler;
  47. };
  48. #endif