MiLightHttpServer.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. const char TEXT_PLAIN[] PROGMEM = "text/plain";
  11. const char APPLICATION_JSON[] PROGMEM = "application/json";
  12. class MiLightHttpServer {
  13. public:
  14. MiLightHttpServer(Settings& settings, MiLightClient*& milightClient)
  15. : server(WebServer(80)),
  16. milightClient(milightClient),
  17. settings(settings)
  18. {
  19. this->applySettings(settings);
  20. }
  21. void begin();
  22. void handleClient();
  23. void onSettingsSaved(SettingsSavedHandler handler);
  24. void on(const char* path, HTTPMethod method, ESP8266WebServer::THandlerFunction handler);
  25. WiFiClient client();
  26. protected:
  27. ESP8266WebServer::THandlerFunction handleServeFile(
  28. const char* filename,
  29. const char* contentType,
  30. const char* defaultText = NULL);
  31. bool serveFile(const char* file, const char* contentType = "text/html");
  32. ESP8266WebServer::THandlerFunction handleUpdateFile(const char* filename);
  33. void applySettings(Settings& settings);
  34. void handleUpdateSettings();
  35. void handleGetRadioConfigs();
  36. void handleAbout();
  37. void handleGetLatestRelease();
  38. void handleSystemPost();
  39. void handleListenGateway(const UrlTokenBindings* urlBindings);
  40. void handleSendRaw(const UrlTokenBindings* urlBindings);
  41. void handleUpdateGroup(const UrlTokenBindings* urlBindings);
  42. void handleDownloadUpdate(const UrlTokenBindings* urlBindings);
  43. void handleRequest(const JsonObject& request);
  44. File updateFile;
  45. WebServer server;
  46. Settings& settings;
  47. MiLightClient*& milightClient;
  48. SettingsSavedHandler settingsSavedHandler;
  49. };
  50. #endif