diff --git a/data/Fermenter/http/index.html b/data/Fermenter/http/index.html index 3937531..3a933c6 100644 --- a/data/Fermenter/http/index.html +++ b/data/Fermenter/http/index.html @@ -2,7 +2,6 @@ - Gärbox + + +

Gewächshaus

+ TODO + + \ No newline at end of file diff --git a/src/Fermenter.cpp b/src/Fermenter.cpp index b8c5af5..39fe1ca 100644 --- a/src/Fermenter.cpp +++ b/src/Fermenter.cpp @@ -1,6 +1,5 @@ #ifdef NODE_FERMENTER -#include #include #include #include @@ -9,6 +8,7 @@ #include "patrix/PIDController.h" #include "patrix/PWMOutput.h" #include "patrix/Rotary.h" +#include "patrix/http.h" #define HEATER_POWER_W 30 @@ -16,8 +16,6 @@ void rotaryCallback(int delta); -AsyncWebServer server(80); - DS18B20 ds18b20("DS18B20", D4); DS18B20Sensor input(ds18b20, 0, ""); @@ -171,21 +169,7 @@ void httpTargetAdd(AsyncWebServerRequest *request) { httpStatus(request); } -void httpNotFound(AsyncWebServerRequest *request) { - if (request->method() == HTTP_OPTIONS) { - request->send(200); - } else { - request->send(404, "text/plain", "not found"); - } -} - void patrixSetup() { - if (LittleFS.begin()) { - Log.info("Filesystem mounted."); - } else { - Log.error("Failed to mount filesystem!"); - } - ds18b20.setup(); heater.setup(); rotary.setup(); @@ -193,16 +177,10 @@ void patrixSetup() { targetFileSetup(); pid.setup(); - DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); - DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT"); - DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type"); - server.serveStatic("/", LittleFS, "/http/", "max-age=86400").setDefaultFile("index.html"); server.on("/status", httpStatus); server.on("/status/", httpStatus); server.on("/target/add", httpTargetAdd); server.on("/target/add/", httpTargetAdd); - server.onNotFound(httpNotFound); - server.begin(); } void patrixLoop() { diff --git a/src/patrix/Patrix.cpp b/src/patrix/Patrix.cpp index f5e2498..a9fbf26 100644 --- a/src/patrix/Patrix.cpp +++ b/src/patrix/Patrix.cpp @@ -1,16 +1,24 @@ +#include #include "Patrix.h" +#include "http.h" void setup() { Log.info("Startup."); + if (LittleFS.begin()) { + Log.info("Filesystem mounted."); + } else { + Log.error("Failed to mount filesystem!"); + } wifiConnect(); } void loop() { wifiLoop(); mqttLoop(); - if (isAfterBootDelay()) { + if (isBootDelayComplete()) { if (isSetupTimeAfterBootDelay()) { patrixSetup(); + httpSetup(); } patrixLoop(); } diff --git a/src/patrix/http.cpp b/src/patrix/http.cpp new file mode 100644 index 0000000..ef5310a --- /dev/null +++ b/src/patrix/http.cpp @@ -0,0 +1,22 @@ +#include "http.h" + +#include + +AsyncWebServer server(80); + +void httpNotFound(AsyncWebServerRequest *request) { + if (request->method() == HTTP_OPTIONS) { + request->send(200); + } else { + request->send(404, "text/plain", "not found"); + } +} + +void httpSetup() { + DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); + DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT"); + DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type"); + server.serveStatic("/", LittleFS, "/http/", "max-age=86400").setDefaultFile("index.html"); + server.onNotFound(httpNotFound); + server.begin(); +} diff --git a/src/patrix/http.h b/src/patrix/http.h new file mode 100644 index 0000000..d24ef36 --- /dev/null +++ b/src/patrix/http.h @@ -0,0 +1,10 @@ +#ifndef HELLIGKEIT_HTTP_H +#define HELLIGKEIT_HTTP_H + +#include + +extern AsyncWebServer server; + +void httpSetup(); + +#endif diff --git a/src/patrix/wifi.cpp b/src/patrix/wifi.cpp index cd553e4..322e790 100644 --- a/src/patrix/wifi.cpp +++ b/src/patrix/wifi.cpp @@ -156,6 +156,6 @@ bool isSetupTimeAfterBootDelay() { return false; } -bool isAfterBootDelay() { +bool isBootDelayComplete() { return bootDelayOver; } diff --git a/src/patrix/wifi.h b/src/patrix/wifi.h index 8b968da..b0c74d5 100644 --- a/src/patrix/wifi.h +++ b/src/patrix/wifi.h @@ -13,7 +13,7 @@ bool isWifiConnected(); bool isSetupTimeAfterBootDelay(); -bool isAfterBootDelay(); +bool isBootDelayComplete(); uint64_t uptimeMillis();