centralized LittleFS + AsyncWebServer
This commit is contained in:
parent
bd422c3991
commit
4ca795501b
@ -2,7 +2,6 @@
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Gärbox</title>
|
||||
<style>
|
||||
|
||||
31
data/Greenhouse/http/index.html
Normal file
31
data/Greenhouse/http/index.html
Normal file
@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Gewächshaus</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
font-size: 4vw;
|
||||
margin: 1em;
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
div {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Gewächshaus</h1>
|
||||
TODO
|
||||
</body>
|
||||
</html>
|
||||
@ -1,6 +1,5 @@
|
||||
#ifdef NODE_FERMENTER
|
||||
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <LedControl.h>
|
||||
#include <LittleFS.h>
|
||||
#include <ArduinoOTA.h>
|
||||
@ -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() {
|
||||
|
||||
@ -1,16 +1,24 @@
|
||||
#include <LittleFS.h>
|
||||
#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();
|
||||
}
|
||||
|
||||
22
src/patrix/http.cpp
Normal file
22
src/patrix/http.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "http.h"
|
||||
|
||||
#include <LittleFS.h>
|
||||
|
||||
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();
|
||||
}
|
||||
10
src/patrix/http.h
Normal file
10
src/patrix/http.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef HELLIGKEIT_HTTP_H
|
||||
#define HELLIGKEIT_HTTP_H
|
||||
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
extern AsyncWebServer server;
|
||||
|
||||
void httpSetup();
|
||||
|
||||
#endif
|
||||
@ -156,6 +156,6 @@ bool isSetupTimeAfterBootDelay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isAfterBootDelay() {
|
||||
bool isBootDelayComplete() {
|
||||
return bootDelayOver;
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ bool isWifiConnected();
|
||||
|
||||
bool isSetupTimeAfterBootDelay();
|
||||
|
||||
bool isAfterBootDelay();
|
||||
bool isBootDelayComplete();
|
||||
|
||||
uint64_t uptimeMillis();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user