From 0a065f48be99d4ebae49de622a335f23e50c6ca0 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 18 Dec 2022 06:31:24 +0300 Subject: pump-mqtt-bot: wip; relayctl: somewhat stable --- platformio/relayctl/src/http_server.h | 45 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'platformio/relayctl/src/http_server.h') diff --git a/platformio/relayctl/src/http_server.h b/platformio/relayctl/src/http_server.h index c7e3d9c..35f7c08 100644 --- a/platformio/relayctl/src/http_server.h +++ b/platformio/relayctl/src/http_server.h @@ -1,37 +1,56 @@ #pragma once - +#include +#include #include #include -#include #include -#include -#include "static.h" #include "config.h" #include "wifi.h" +#include "static.h" namespace homekit { +struct OTAStatus { + bool invalidMd5; + + OTAStatus() : invalidMd5(false) {} + + inline void clean() { + invalidMd5 = false; + } +}; + using files::StaticFile; class HttpServer { private: - AsyncWebServer _server; + ESP8266WebServer server; Ticker restartTimer; - std::shared_ptr> _scanResults; - char buf1k[1024]; + std::shared_ptr> scanResults; + OTAStatus ota; - static void sendGzip(AsyncWebServerRequest* req, StaticFile file, const char* content_type); - static void sendError(AsyncWebServerRequest* req, const String& message); + char* scanBuf; + size_t scanBufSize; - static bool handleInputStr(AsyncWebServerRequest* req, const char* field_name, size_t max_len, char** dst); - // static bool handle_input_addr(AsyncWebServerRequest* req, const char* field_name, ConfigIPv4Addr* addr_dst); + void sendGzip(const StaticFile& file, PGM_P content_type); + void sendError(const String& message); + + bool getInputParam(const char* field_name, size_t max_len, String& dst); public: explicit HttpServer(std::shared_ptr> scanResults) - : _server(80) - , _scanResults(std::move(scanResults)) {}; + : server(80) + , scanResults(std::move(scanResults)) + , scanBufSize(512) { + scanBuf = new char[scanBufSize]; + }; + + ~HttpServer() { + delete[] scanBuf; + } void start(); + void loop(); }; } \ No newline at end of file -- cgit v1.2.3