Esp8266 Sollwert.ino als Arduino Tab.
Sollwert.ino
// ****************************************************************
// Sketch Esp8266 Sollwert Modular(Tab)
// created: Jens Fleischer, 2020-09-29
// last mod: Jens Fleischer, 2020-09-29
// For more information visit: https://fipsok.de
// ****************************************************************
// Hardware: Esp8266
// Software: Esp8266 Arduino Core 2.4.2 - 3.1.0
// Getestet auf: Nodemcu, Wemos D1 Mini Pro, Sonoff Dual
/******************************************************************
Copyright (c) 2020 Jens Fleischer. All rights reserved.
This file is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*******************************************************************/
// Diese Version von Sollwert kann als Tab eingebunden werden.
// #include <ESP8266WebServer.h> müssen im Haupttab aufgerufen werden
// Die Funktionalität des ESP8266 Webservers ist erforderlich.
// Die Funktion "setupModify();" muss im Setup aufgerufen werden.
/**************************************************************************************/
float setpoint = 25.5; // Diese Variable Deklaration in den Haupttab vor "setup()" verschieben um sie im gesamten Sketch verfügbar zu machen.
void setupModify() {
server.on("/modified", []() {
char buf[13];
if (server.args()) setpoint = atof(server.arg(0).c_str());
snprintf(buf, sizeof buf, "\"%8.3f\"", setpoint);
server.send(200, "application/json", buf);
});
}
Die Webseite zum Esp8266 DS18B20.
sollwert.html
<!DOCTYPE HTML> <!-- For more information visit: https://fipsok.de -->
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<title>ESP8266</title>
<script>
function sendEsp(data) {
fetch('/modified', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
body: data
}).then(resp => {
return resp.json();
}).then( (text) => {
document.querySelector('output').innerText = text;
});
}
window.addEventListener('DOMContentLoaded', () => {
document.querySelector('button').addEventListener('click', () => {
let obj = document.querySelector('input');
if (obj.checkValidity()) {
sendEsp('new=' + obj.value);
obj.value = "";
obj.focus();
}
});
}, sendEsp());
</script>
<style>
div {
background: #eee;
border: 5px inset;
padding: .5em;
margin: 1em;
}
</style>
</head>
<body>
<h2>Sollwert ESP8266</h2>
<div>Aktuell: <output></output></div>
<label>Eingabe Sollwert:</label>
<input autofocus title="Es dürfen nur Vorzeichen, Dezimalpunkt und Ziffern enthalten sein. Maximal +99999.999" pattern="[+|-]?[\d]{0,5}(\.\d{0,3})?" required>
<button type="button">Senden</button>
</body>
</html>