summaryrefslogtreecommitdiff
path: root/platformio/relayctl/src/http_server.h
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-12-18 06:31:24 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-12-24 12:57:55 +0300
commit0a065f48be99d4ebae49de622a335f23e50c6ca0 (patch)
treeb591d91fac26e5bf7a4dd6d37178b978061ef060 /platformio/relayctl/src/http_server.h
parent022ec129bb8f511a7bf8cf537f165afce2303262 (diff)
pump-mqtt-bot: wip; relayctl: somewhat stable
Diffstat (limited to 'platformio/relayctl/src/http_server.h')
-rw-r--r--platformio/relayctl/src/http_server.h45
1 files changed, 32 insertions, 13 deletions
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 <ESP8266WebServer.h>
+#include <Ticker.h>
#include <memory>
#include <list>
-#include <Ticker.h>
#include <utility>
-#include <ESPAsyncWebServer.h>
-#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<std::list<wifi::ScanResult>> _scanResults;
- char buf1k[1024];
+ std::shared_ptr<std::list<wifi::ScanResult>> 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<std::list<wifi::ScanResult>> 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