#pragma once #define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG // System includes #include #include #include #include #include #include #include #include class AstroWebServer { public: using WScommand = std::function; public: AstroWebServer(const uint8_t port, fs::FS &filesystem); ~AstroWebServer(); void sendWsData(const String &data); void registerWsCommand(const std::string &cmd, const WScommand func); void unRegisterWsCommand(const std::string &cmd); private: void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len); void onUploadRequest(AsyncWebServerRequest *request); void onUploadHandler(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final); void onSetTme(const ArduinoJson::JsonDocument &doc); private: const uint8_t c_port = 80; const uint32_t c_pingTime = 5000; fs::FS &m_filesystem; AsyncWebServer m_webserver; AsyncWebSocket m_websocket; bool m_uploadFailed = false; fs::File m_uploadFile; TimerHandle_t m_pingTimer = NULL; std::map m_webserverCommands; };