add feature to show temp and hum in web gui
This commit is contained in:
parent
7e1dc425c4
commit
1929251bfc
@ -8,26 +8,22 @@ void Temperature::init() {
|
|||||||
dht.begin();
|
dht.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
double Temperature::getTemp() {
|
float Temperature::getTemp() {
|
||||||
sensors_event_t event;
|
float temp = dht.readTemperature();
|
||||||
dht.temperature().getEvent(&event);
|
Serial.println("read temp is: " + String(temp));
|
||||||
if (isnan(event.temperature)) {
|
if (isnan(temp)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
else {
|
return temp;
|
||||||
return event.temperature;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double Temperature::getHum() {
|
float Temperature::getHum() {
|
||||||
sensors_event_t event;
|
float hum = dht.readHumidity();
|
||||||
dht.humidity().getEvent(&event);
|
Serial.println("read hum is: " + String(hum));
|
||||||
if (isnan(event.relative_humidity)) {
|
if (isnan(hum)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
else {
|
return hum;
|
||||||
|
|
||||||
return event.relative_humidity;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,28 @@
|
|||||||
|
|
||||||
#include <Adafruit_Sensor.h>
|
#include <Adafruit_Sensor.h>
|
||||||
#include <DHT.h>
|
#include <DHT.h>
|
||||||
#include <DHT_U.h>
|
|
||||||
|
|
||||||
class Temperature {
|
class Temperature {
|
||||||
public:
|
public:
|
||||||
Temperature(): dht(4, DHT22){};
|
Temperature() : dht(4, DHT22){};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize the temperature sensor
|
||||||
|
*/
|
||||||
void init();
|
void init();
|
||||||
double getTemp();
|
|
||||||
double getHum();
|
/**
|
||||||
|
* read the temperature value in C
|
||||||
|
* @return float value of temperature
|
||||||
|
*/
|
||||||
|
float getTemp();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read current humidity value in %
|
||||||
|
* @return float value of humidity
|
||||||
|
*/
|
||||||
|
float getHum();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DHT_Unified dht;
|
DHT dht;
|
||||||
};
|
};
|
||||||
|
@ -30,6 +30,9 @@ void WifiManager::init() {
|
|||||||
} else {
|
} else {
|
||||||
Serial.println("Wifi Setup failed!");
|
Serial.println("Wifi Setup failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init temperature sensor
|
||||||
|
temp.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiManager::WifiManager() : server(80), lastPumpTime(0), lastWaterOutage(0), lastPumpDuration(0) {}
|
WifiManager::WifiManager() : server(80), lastPumpTime(0), lastWaterOutage(0), lastPumpDuration(0) {}
|
||||||
@ -104,6 +107,9 @@ void WifiManager::handleRoot() {
|
|||||||
index_html += "<div>Drucksensor: " + String((digitalRead(DruckSensorPin) ? "EIN" : "AUS")) + "</div>";
|
index_html += "<div>Drucksensor: " + String((digitalRead(DruckSensorPin) ? "EIN" : "AUS")) + "</div>";
|
||||||
index_html += "<div>Wassersensor: " + String((digitalRead(WasserSensorPin) ? "EIN" : "AUS")) + "</div>";
|
index_html += "<div>Wassersensor: " + String((digitalRead(WasserSensorPin) ? "EIN" : "AUS")) + "</div>";
|
||||||
|
|
||||||
|
index_html += "</br><div>Temperatur: " + String(this->temp.getTemp()) + "C</div>";
|
||||||
|
index_html += "<div>Relative Luftfeuchtigkeit: " + String(this->temp.getHum()) + "%</div>";
|
||||||
|
|
||||||
index_html += "</body></html>";
|
index_html += "</body></html>";
|
||||||
|
|
||||||
server.send(200, "text/html", index_html);
|
server.send(200, "text/html", index_html);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
#include "Temperature.h"
|
||||||
|
|
||||||
class WifiManager {
|
class WifiManager {
|
||||||
public:
|
public:
|
||||||
@ -53,6 +54,7 @@ private:
|
|||||||
static const uint8_t DruckSensorPin = 12;
|
static const uint8_t DruckSensorPin = 12;
|
||||||
|
|
||||||
ESP8266WebServer server;
|
ESP8266WebServer server;
|
||||||
|
Temperature temp;
|
||||||
|
|
||||||
void handleRoot();
|
void handleRoot();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user