MiLightHttpServer.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 handleSystemPost();
  37. void handleListenGateway(const UrlTokenBindings* urlBindings);
  38. void handleSendRaw(const UrlTokenBindings* urlBindings);
  39. void handleUpdateGroup(const UrlTokenBindings* urlBindings);
  40. void handleRequest(const JsonObject& request);
  41. File updateFile;
  42. WebServer server;
  43. Settings& settings;
  44. MiLightClient*& milightClient;
  45. SettingsSavedHandler settingsSavedHandler;
  46. };
  47. #endif