Chtěl bych zprovoznit malý web server (NodeMCU). Používám pro rozdělení kódu knihovnu Tasker.h. Na webu jsem si našel tutoriál na web server:
Kód: Vybrat vše
https://randomnerdtutorials.com/esp8266-dht11dht22-temperature-and-humidity-web-server-with-arduino-ide/
Kód: Vybrat vše
#include <Tasker.h>
Tasker tasker;
void setup() {
Serial.begin(9600);
// ********* Spuštěné úlohy - začátek *****************************************
// test - smazat
tasker.setInterval(testTask, 1000);
// ********* Spuštěné úlohy - konec *****************************************
}
void loop() {
tasker.loop();
}
Kód: Vybrat vše
void testTask() {
Serial.println("Test");
}
Kód: Vybrat vše
'testTask' was not declared in this scope
Kód: Vybrat vše
#include <Tasker.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
Tasker tasker;
//******** Přihlašovací údaje k sítím - začátek *****************************
/*// Přihlášení k iPhone
const char* ssid = "iPhone";
const char* password = "********";
*/
// Přihlášení k TP-Link
const char* ssid = "TP-Link_1C18";
const char* password = "********";
//******** Přihlašovací údaje k sítím - začátek *****************************
// prozatimní proměnné
// current temperature & humidity, updated in loop()
float t = 0.0;
float h = 0.0;
boolean smazat = true;
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
/*
//********************** Webová stránka - začátek *****************************
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<style>
html {
font-family: Arial;
display: inline-block;
margin: 0px auto;
text-align: center;
}
h2 { font-size: 3.0rem; }
p { font-size: 3.0rem; }
.units { font-size: 1.2rem; }
.dht-labels{
font-size: 1.5rem;
vertical-align:middle;
padding-bottom: 15px;
}
</style>
</head>
<body>
<h2>ESP8266 DHT Server</h2>
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
<span class="dht-labels">Temperature</span>
<span id="temperature">%TEMPERATURE%</span>
<sup class="units">°C</sup>
</p>
<p>
<i class="fas fa-tint" style="color:#00add6;"></i>
<span class="dht-labels">Humidity</span>
<span id="humidity">%HUMIDITY%</span>
<sup class="units">%</sup>
</p>
</body>
<script>
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperature", true);
xhttp.send();
}, 10000 ) ;
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("humidity").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/humidity", true);
xhttp.send();
}, 10000 ) ;
</script>
</html>)rawliteral";
*/
//********************** Webová stránka - konec ********************************
void setup() {
Serial.begin(9600);
// ********* Spuštěné úlohy - začátek *****************************************
// test - smazat
tasker.setInterval(testTask, 1000);
// ********* Spuštěné úlohy - konec *****************************************
}
void loop() {
tasker.loop();
}
Kód: Vybrat vše
void testTask() {
Serial.println("Test");
}