From 0aba139aeff8ff80757c5d36502413299a0b449e Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Thu, 11 May 2023 04:18:08 +0300 Subject: mqtt, esp: add new esp8266-based device --- platformio/temphum/src/http_server.h | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 platformio/temphum/src/http_server.h (limited to 'platformio/temphum/src/http_server.h') diff --git a/platformio/temphum/src/http_server.h b/platformio/temphum/src/http_server.h new file mode 100644 index 0000000..35f7c08 --- /dev/null +++ b/platformio/temphum/src/http_server.h @@ -0,0 +1,56 @@ +#pragma once +#include +#include +#include +#include +#include +#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: + ESP8266WebServer server; + Ticker restartTimer; + std::shared_ptr> scanResults; + OTAStatus ota; + + char* scanBuf; + size_t scanBufSize; + + 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)) + , scanBufSize(512) { + scanBuf = new char[scanBufSize]; + }; + + ~HttpServer() { + delete[] scanBuf; + } + + void start(); + void loop(); +}; + +} \ No newline at end of file -- cgit v1.2.3