summaryrefslogtreecommitdiff
path: root/platformio/temphum/src/http_server.h
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-11 04:18:08 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-05-11 04:18:12 +0300
commit0aba139aeff8ff80757c5d36502413299a0b449e (patch)
tree2b8e760ff14d4691783eb7c7d341f093199aab82 /platformio/temphum/src/http_server.h
parent586d84b0c0a8b4dc1b5057733892b754397234ec (diff)
mqtt, esp: add new esp8266-based device
Diffstat (limited to 'platformio/temphum/src/http_server.h')
-rw-r--r--platformio/temphum/src/http_server.h56
1 files changed, 56 insertions, 0 deletions
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 <ESP8266WebServer.h>
+#include <Ticker.h>
+#include <memory>
+#include <list>
+#include <utility>
+#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<std::list<wifi::ScanResult>> 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<std::list<wifi::ScanResult>> 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