şimdi benim dht 22 sensörüm var onu web üzerinden gösterdim sonra t ilk deger sonra t sondeger nem ilk deger nem son deger diye tnımladım bunlara komut verdim onlarada bir sayı verdim ve odegerl dışına çıkarsa led yanacak bunu yaptım tek sıkıntım kodda verdim degeler yani led yanması için verdiğim değeri web üzerinden değiştireceğim yani sıcaklğım 20 ila 30 arasına çıkarsa le yanacak ben bunu web ortamında değiştirmek istiyorum 30 ila 20 değilde 40 ila 50 olmasını istiyorum nem de aynı şekilde yani web serverde 4 tane kutucuk olucak vunların 1i sıcaklık en büyük 2sıcaklık en küçük 3 nem en büyük 4 nem en küçük olucak eger sıcaklık en büyüye sayı yazdığımda artık sıcaklık en büyük değeri o olucak nem içinde geçerli
kodda aşağıda yardımcı olursanız sevinirim
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <Hash.h>
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#else
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
int led1=D0;
int led2=D4;
int t_ilk_deger=10;
int t_son_deger=20;
int h_ilk_deger=10;
int h_son_deger=20;
AsyncWebServer server(80);
unsigned long previousMillis = 0;
const long interval = 10000;
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "huysuzveuzun";
const char* password = "Mahmut3671751";
#define DHTTYPE DHT22
const int DHTPin = D2;
DHT dht(DHTPin, DHTTYPE);
const char* PARAM_INPUT_1 = " sicaklik son deger";
const char* PARAM_INPUT_2 = "nem son deger";
const char* PARAM_INPUT_3 = "sicaklik ilk deger";
const char* PARAM_INPUT_4 = "nem ilk deger";
float t = 0.0;
float h = 0.0;
// HTML web page to handle 3 input fields (input1, input2, input3)
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
<meta charset="utf-8">
<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>
<body>
<h2>Sıcaklık & Nem Kontrol Sistemi</h2>
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
<span class="dht-labels">Sıcaklık</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">Nem</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>
<title>ESP Input Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head><body>
<form action="/get">
sicaklik son deger: <input type="text" name=" sicaklik son deger">
<input type="submit" value="gonder">
</form><br>
<form action="/get">
nem son deger: <input type="text" name="nem son deger">
<input type="submit" value="gonder">
</form><br>
<form action="/get">
sicaklik ilk deger: <input type="text" name="sicaklik ilk deger">
<input type="submit" value="gonder">
</form><br>
<form action="/get">
nem ilk deger: <input type="text" name="nem ilk deger">
<input type="submit" value="gonder">
</form><br>
</body></html>)rawliteral";
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
}
String processor(const String& var){
//Serial.println(var);
if(var == "TEMPERATURE"){
return String(t);
}
else if(var == "HUMIDITY"){
return String(h);
}
return String();
}
void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
Serial.println(F("=BAŞLIYOR="));
Serial.begin(115200);
dht.begin();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed!");
return;
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Send web page with input fields to client
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html);
});
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", String(t).c_str());
});
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", String(h).c_str());
});
// Send a GET request to <ESP_IP>/get?input1=<inputMessage>
server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
String inputMessage;
String usak;
String inputParam;
String kay;
String gvs;
// GET input1 value on <ESP_IP>/get?input1=<inputMessage>
if (request->hasParam(PARAM_INPUT_1)) {
gvs= request->getParam(PARAM_INPUT_1)->value();
inputParam = PARAM_INPUT_1;
}
else {
gvs = "No message sent";
inputParam = "none";
}
// GET input2 value on <ESP_IP>/get?input2=<inputMessage>
if (request->hasParam(PARAM_INPUT_2)) {
usak = request->getParam(PARAM_INPUT_2)->value();
inputParam = PARAM_INPUT_2;
}
else {
usak = "No message sent";
inputParam = "none";
}
if (request->hasParam(PARAM_INPUT_3)) {
kay = request->getParam(PARAM_INPUT_3)->value();
inputParam = PARAM_INPUT_3;
}
else {
kay = "No message sent";
inputParam = "none";
}
// GET input2 value on <ESP_IP>/get?input2=<inputMessage>
if (request->hasParam(PARAM_INPUT_4)) {
inputMessage = request->getParam(PARAM_INPUT_4)->value();
inputParam = PARAM_INPUT_4;
}
else {
inputMessage = "No message sent";
inputParam = "none";
}
Serial.println(gvs);
request->send(200, "text/html", "HTTP GET request sent to your ESP on input field ("
+ inputParam + ") with value: " + gvs +
"<br><a href=\"/\">Return to Home Page</a>");
Serial.println(usak);
request->send(200, "text/html", "HTTP GET request sent to your ESP on input field ("
+ inputParam + ") with value: " + usak +
"<br><a href=\"/\">Return to Home Page</a>");
Serial.println(kay);
request->send(200, "text/html", "HTTP GET request sent to your ESP on input field ("
+ inputParam + ") with value: " + kay +
"<br><a href=\"/\">Return to Home Page</a>");
Serial.println( inputMessage);
request->send(200, "text/html", "HTTP GET request sent to your ESP on input field ("
+ inputParam + ") with value: " + inputMessage +
"<br><a href=\"/\">Return to Home Page</a>");
});
server.onNotFound(notFound);
server.begin();
server.begin();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you updated the DHT values
previousMillis = currentMillis;
// Read temperature as Celsius (the default)
float newT = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
//float newT = dht.readTemperature(true);
// if temperature read failed, don't change t value
if (isnan(newT)) {
Serial.println("Failed to read from DHT sensor!");
}
else {
t = newT;
Serial.println(t);
}
// Read Humidity
float newH = dht.readHumidity();
// if humidity read failed, don't change h value
if (isnan(newH)) {
Serial.println("Failed to read from DHT sensor!");
}
else {
h = newH;
Serial.println(h);
}
}
if(t>t_ilk_deger && t< t_son_deger)
{
digitalWrite(led1,LOW);
}
else
{
digitalWrite(led1,HIGH);
}
if(h>h_ilk_deger && h< h_son_deger)
{
digitalWrite(led2,LOW);
}
else
{
digitalWrite(led2,HIGH);
}
delay(2000);
}