48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
#pragma once
|
|
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
|
|
|
|
// System includes
|
|
#include <Arduino.h>
|
|
#include <DebugLog.h>
|
|
#include <ESPAsyncWebServer.h>
|
|
#include <AsyncTCP.h>
|
|
#include <filesystem>
|
|
#include <map>
|
|
#include <FS.h>
|
|
#include <ArduinoJson.h>
|
|
|
|
class AstroWebServer
|
|
{
|
|
public:
|
|
using WScommand = std::function<void(const ArduinoJson::JsonDocument &)>;
|
|
|
|
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<const std::string, AstroWebServer::WScommand> m_webserverCommands;
|
|
};
|