MiLightHttpServer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 TEXT_PLAIN[] PROGMEM = "text/plain";
  9. const char APPLICATION_JSON[] = "application/json";
  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. ESP8266WebServer::THandlerFunction handleServe_P(const char* data, size_t length);
  32. void applySettings(Settings& settings);
  33. void handleUpdateSettings();
  34. void handleGetRadioConfigs();
  35. void handleAbout();
  36. void handleGetLatestRelease();
  37. void handleSystemPost();
  38. void handleListenGateway(const UrlTokenBindings* urlBindings);
  39. void handleSendRaw(const UrlTokenBindings* urlBindings);
  40. void handleUpdateGroup(const UrlTokenBindings* urlBindings);
  41. void handleDownloadUpdate(const UrlTokenBindings* urlBindings);
  42. void handleRequest(const JsonObject& request);
  43. File updateFile;
  44. WebServer server;
  45. Settings& settings;
  46. MiLightClient*& milightClient;
  47. SettingsSavedHandler settingsSavedHandler;
  48. };
  49. #endif