[WIP] Fermenter http NOT WORKING
This commit is contained in:
parent
1bde26489b
commit
eadd267749
130
data/http/index.htm
Normal file
130
data/http/index.htm
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, user-scalable=no">
|
||||||
|
<title>Gärbox</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-size: 16vw;
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin: 0.1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry {
|
||||||
|
padding-bottom: 0.5em;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 60%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
float: right;
|
||||||
|
|
||||||
|
.control {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlUp {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlDown {
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#overlay {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
color: red;
|
||||||
|
font-size: 10vw;
|
||||||
|
line-height: 100vh;
|
||||||
|
text-align: center;
|
||||||
|
background-color: rgba(0, 0, 0, 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="entry">
|
||||||
|
<div class="title">
|
||||||
|
Ist-Temperatur
|
||||||
|
</div>
|
||||||
|
<div class="value" id="currentCelsius">
|
||||||
|
<!-- via js -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="entry">
|
||||||
|
<div class="title">
|
||||||
|
Ziel-Temperatur
|
||||||
|
</div>
|
||||||
|
<div class="value" id="targetCelsius">
|
||||||
|
<!-- via js -->
|
||||||
|
</div>
|
||||||
|
<div class="controls">
|
||||||
|
<div class="control controlUp" onclick="get('/up')">↑</div>
|
||||||
|
<div class="control controlDown" onclick="get('/down')">↓</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="overlay">
|
||||||
|
Nicht verbunden
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const overlay = document.getElementById('overlay');
|
||||||
|
const currentCelsius = document.getElementById('currentCelsius');
|
||||||
|
const targetCelsius = document.getElementById('targetCelsius');
|
||||||
|
|
||||||
|
function get(url) {
|
||||||
|
const request = new XMLHttpRequest();
|
||||||
|
request.onreadystatechange = function () {
|
||||||
|
if (this.readyState === 4) {
|
||||||
|
currentCelsius.classList.remove("tooCold");
|
||||||
|
currentCelsius.classList.remove("tooWarm");
|
||||||
|
currentCelsius.classList.remove("good");
|
||||||
|
if (this.status === 200) {
|
||||||
|
overlay.classList.add("noOverlay");
|
||||||
|
|
||||||
|
const json = JSON.parse(this.responseText);
|
||||||
|
currentCelsius.innerText = (json.currentCelsius || '---') + ' °C';
|
||||||
|
targetCelsius.innerText = (json.targetCelsius || '---') + ' °C';
|
||||||
|
const difference = json.currentCelsius - json.targetCelsius;
|
||||||
|
if (Math.abs(difference) <= 0.5) {
|
||||||
|
currentCelsius.classList.add("good");
|
||||||
|
} else if (difference < 0) {
|
||||||
|
currentCelsius.classList.add("tooCold");
|
||||||
|
} else {
|
||||||
|
currentCelsius.classList.add("tooWarm");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
request.open("GET", url);
|
||||||
|
request.send();
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/get");
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -34,7 +34,7 @@ void configReset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String configGetString(const char *name, const char *fallback, bool allowEmpty) {
|
String configGetString(const char *name, const char *fallback, bool allowEmpty) {
|
||||||
if (!config.containsKey(name)) {
|
if (!config[name].is<String>()) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
String value = config[name];
|
String value = config[name];
|
||||||
@ -52,7 +52,7 @@ void configPutString(const char *name, const char *value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double configGetDouble(const char *name, double fallback) {
|
double configGetDouble(const char *name, double fallback) {
|
||||||
if (!config.containsKey(name)) {
|
if (!config[name].is<double>()) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
return config[name];
|
return config[name];
|
||||||
@ -66,7 +66,7 @@ void configPutDouble(const char *name, double value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t configGetUint64_t(const char *name, uint64_t fallback) {
|
uint64_t configGetUint64_t(const char *name, uint64_t fallback) {
|
||||||
if (!config.containsKey(name)) {
|
if (!config[name].is<uint64>()) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
return config[name];
|
return config[name];
|
||||||
@ -80,7 +80,7 @@ void configPutUint64_t(const char *name, uint64_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t configGetUint8_t(const char *name, uint8_t fallback) {
|
uint8_t configGetUint8_t(const char *name, uint8_t fallback) {
|
||||||
if (!config.containsKey(name)) {
|
if (!config[name].is<uint8>()) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
return config[name];
|
return config[name];
|
||||||
@ -97,7 +97,7 @@ void configPrint() {
|
|||||||
info("Config (%s):", lastChangeMillis == 0 ? "PERSISTED" : "TRANSIENT");
|
info("Config (%s):", lastChangeMillis == 0 ? "PERSISTED" : "TRANSIENT");
|
||||||
for (JsonPair pair: config.as<JsonObject>()) {
|
for (JsonPair pair: config.as<JsonObject>()) {
|
||||||
const char *key = pair.key().c_str();
|
const char *key = pair.key().c_str();
|
||||||
const JsonVariant &value = pair.value();
|
const JsonVariant& value = pair.value();
|
||||||
|
|
||||||
char valueStr[64];
|
char valueStr[64];
|
||||||
if (strcmp(key, "WIFI_PKEY") == 0) {
|
if (strcmp(key, "WIFI_PKEY") == 0) {
|
||||||
|
|||||||
@ -50,7 +50,6 @@ void wifiConnect() {
|
|||||||
|
|
||||||
sntp_stop();
|
sntp_stop();
|
||||||
if (otaInitialized) {
|
if (otaInitialized) {
|
||||||
ArduinoOTA.end();
|
|
||||||
otaInitialized = false;
|
otaInitialized = false;
|
||||||
}
|
}
|
||||||
mqttDisconnect();
|
mqttDisconnect();
|
||||||
@ -195,7 +194,7 @@ time_t getTime() {
|
|||||||
return epochSeconds;
|
return epochSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void correctTime(time_t &value) {
|
void correctTime(time_t& value) {
|
||||||
if (timeSet && value < MIN_EPOCH_SECONDS) {
|
if (timeSet && value < MIN_EPOCH_SECONDS) {
|
||||||
value = getTime() - preTimeOffset + value;
|
value = getTime() - preTimeOffset + value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ usb_speed = 921600
|
|||||||
ota_protocol = espota
|
ota_protocol = espota
|
||||||
monitor_port = /dev/ttyUSB0
|
monitor_port = /dev/ttyUSB0
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
board_build.filesystem = littlefs
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
WIFI_SSID = HappyNet
|
WIFI_SSID = HappyNet
|
||||||
WIFI_PKEY = 1Grausame!Sackratte7
|
WIFI_PKEY = 1Grausame!Sackratte7
|
||||||
@ -57,12 +58,26 @@ upload_protocol = ${COMMON.ota_protocol}
|
|||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
framework = ${COMMON.framework}
|
framework = ${COMMON.framework}
|
||||||
|
board_build.filesystem = ${COMMON.board_build.filesystem}
|
||||||
monitor_port = ${COMMON.monitor_port}
|
monitor_port = ${COMMON.monitor_port}
|
||||||
monitor_speed = ${COMMON.monitor_speed}
|
monitor_speed = ${COMMON.monitor_speed}
|
||||||
monitor_filters = esp8266_exception_decoder
|
monitor_filters = esp8266_exception_decoder
|
||||||
lib_deps = ${COMMON.lib_deps}
|
lib_deps = ${COMMON.lib_deps}
|
||||||
build_flags = -D FERMENTER -D HOSTNAME=\"Fermenter\" -D WIFI_SSID=\"${COMMON.WIFI_SSID}\" -D WIFI_PKEY=\"${COMMON.WIFI_PKEY}\" -D OTA_PASSWORD=\"OtaAuthPatrixFermenter\" -D BOOT_DELAY=true -D DEBUG_LOG=false
|
build_flags = -D FERMENTER -D HOSTNAME=\"Fermenter\" -D WIFI_SSID=\"${COMMON.WIFI_SSID}\" -D WIFI_PKEY=\"${COMMON.WIFI_PKEY}\" -D OTA_PASSWORD=\"OtaAuthPatrixFermenter\" -D BOOT_DELAY=true -D DEBUG_LOG=false
|
||||||
|
|
||||||
|
[env:FermenterUSB]
|
||||||
|
;upload_port = ${COMMON.usb_port}
|
||||||
|
;upload_speed = ${COMMON.usb_speed}
|
||||||
|
platform = espressif8266
|
||||||
|
board = esp12e
|
||||||
|
framework = ${COMMON.framework}
|
||||||
|
board_build.filesystem = ${COMMON.board_build.filesystem}
|
||||||
|
monitor_port = ${COMMON.monitor_port}
|
||||||
|
monitor_speed = ${COMMON.monitor_speed}
|
||||||
|
monitor_filters = esp8266_exception_decoder
|
||||||
|
lib_deps = ${COMMON.lib_deps}
|
||||||
|
build_flags = -D FERMENTER -D HOSTNAME=\"Fermenter2\" -D WIFI_SSID=\"${COMMON.WIFI_SSID}\" -D WIFI_PKEY=\"${COMMON.WIFI_PKEY}\" -D OTA_PASSWORD=\"OtaAuthPatrixFermenter\" -D BOOT_DELAY=true -D DEBUG_LOG=false
|
||||||
|
|
||||||
[env:Greenhouse]
|
[env:Greenhouse]
|
||||||
;upload_port = 10.0.0.
|
;upload_port = 10.0.0.
|
||||||
;upload_flags = --auth=OtaAuthPatrixGreenhouse
|
;upload_flags = --auth=OtaAuthPatrixGreenhouse
|
||||||
|
|||||||
@ -1,16 +1,66 @@
|
|||||||
#if defined(FERMENTER) || defined(TEST8266)
|
#if defined(FERMENTER) || defined(TEST8266)
|
||||||
|
|
||||||
#include <Patrix.h>
|
#include <Patrix.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
#include "FermenterData.h"
|
#include "FermenterData.h"
|
||||||
#include "FementerDisplay.h"
|
#include "FementerDisplay.h"
|
||||||
#include "FermenterPID.h"
|
#include "FermenterPID.h"
|
||||||
#include "FermenterSensor.h"
|
#include "FermenterSensor.h"
|
||||||
|
#include "ESPAsyncWebServer.h"
|
||||||
|
|
||||||
Cache<FermenterData, 800> cache;
|
Cache<FermenterData, 800> cache;
|
||||||
|
|
||||||
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
|
void httpGet(AsyncWebServerRequest *request) {
|
||||||
|
JsonDocument json;
|
||||||
|
json["currentCelsius"] = temperature;
|
||||||
|
json["targetCelsius"] = target;
|
||||||
|
|
||||||
|
char buffer[250];
|
||||||
|
serializeJson(json, buffer, sizeof buffer);
|
||||||
|
request->send(200, "application/json", buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void change(AsyncWebServerRequest *request, double delta) {
|
||||||
|
target = max(0.0, min(40.0, target + delta));
|
||||||
|
info("HTTP: target set to: %.1f%cC", target, char(176));
|
||||||
|
httpGet(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
void httpUp(AsyncWebServerRequest *request) {
|
||||||
|
change(request, +0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void httpDown(AsyncWebServerRequest *request) {
|
||||||
|
change(request, -0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void httpNotFound(AsyncWebServerRequest *request) {
|
||||||
|
if (request->method() == HTTP_OPTIONS) {
|
||||||
|
request->send(200);
|
||||||
|
} else {
|
||||||
|
request->send(404, "text/plain", F("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.on("/get", httpGet);
|
||||||
|
server.on("/up", httpUp);
|
||||||
|
server.on("/down", httpDown);
|
||||||
|
server.onNotFound(httpNotFound);
|
||||||
|
server.serveStatic("/", LittleFS, "/http/");
|
||||||
|
server.begin();
|
||||||
|
}
|
||||||
|
|
||||||
void patrixSetup() {
|
void patrixSetup() {
|
||||||
sensorSetup();
|
sensorSetup();
|
||||||
pidSetup(&temperature);
|
pidSetup(&temperature);
|
||||||
|
httpSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void patrixLoop() {
|
void patrixLoop() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user