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();
|
||||
}
|
||||
|
||||
double Temperature::getTemp() {
|
||||
sensors_event_t event;
|
||||
dht.temperature().getEvent(&event);
|
||||
if (isnan(event.temperature)) {
|
||||
float Temperature::getTemp() {
|
||||
float temp = dht.readTemperature();
|
||||
Serial.println("read temp is: " + String(temp));
|
||||
if (isnan(temp)) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return event.temperature;
|
||||
} else {
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
double Temperature::getHum() {
|
||||
sensors_event_t event;
|
||||
dht.humidity().getEvent(&event);
|
||||
if (isnan(event.relative_humidity)) {
|
||||
float Temperature::getHum() {
|
||||
float hum = dht.readHumidity();
|
||||
Serial.println("read hum is: " + String(hum));
|
||||
if (isnan(hum)) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
|
||||
return event.relative_humidity;
|
||||
|
||||
} else {
|
||||
return hum;
|
||||
}
|
||||
}
|
||||
|
@ -6,16 +6,28 @@
|
||||
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
#include <DHT_U.h>
|
||||
|
||||
class Temperature {
|
||||
public:
|
||||
Temperature(): dht(4, DHT22){};
|
||||
Temperature() : dht(4, DHT22){};
|
||||
|
||||
/**
|
||||
* initialize the temperature sensor
|
||||
*/
|
||||
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:
|
||||
DHT_Unified dht;
|
||||
DHT dht;
|
||||
};
|
||||
|
@ -30,6 +30,9 @@ void WifiManager::init() {
|
||||
} else {
|
||||
Serial.println("Wifi Setup failed!");
|
||||
}
|
||||
|
||||
// init temperature sensor
|
||||
temp.init();
|
||||
}
|
||||
|
||||
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>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>";
|
||||
|
||||
server.send(200, "text/html", index_html);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include "Temperature.h"
|
||||
|
||||
class WifiManager {
|
||||
public:
|
||||
@ -53,6 +54,7 @@ private:
|
||||
static const uint8_t DruckSensorPin = 12;
|
||||
|
||||
ESP8266WebServer server;
|
||||
Temperature temp;
|
||||
|
||||
void handleRoot();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user