Add DHT Sensor
This commit is contained in:
parent
366b221ea3
commit
d9c22f14ab
|
@ -5,6 +5,13 @@
|
|||
#include <ArduinoOTA.h>
|
||||
#include <Encoder.h> //Library download: https://github.com/PaulStoffregen/Encoder
|
||||
|
||||
#include "DHT.h"
|
||||
DHT dht(D1,DHT22);
|
||||
float temperature=0;
|
||||
float humidity=0;
|
||||
double lastSensorMillis=0;
|
||||
#define SENSORPERIOD 5000
|
||||
|
||||
//D4 auf ground macht led leuchten
|
||||
|
||||
#define PIN_ENCA D6
|
||||
|
@ -45,7 +52,24 @@ void loopHandler() {
|
|||
lastPositionCheck=millis();
|
||||
}
|
||||
|
||||
if ((lastSensorMillis+SENSORPERIOD)<millis()){
|
||||
float _currentTemperature=dht.readTemperature();
|
||||
if (temperature!=_currentTemperature && (!isnan(_currentTemperature) ==1) && _currentTemperature>-40){
|
||||
|
||||
temperature=_currentTemperature;
|
||||
Homie.getLogger() << "temperature= " << temperature << endl;
|
||||
char tempstring[16];
|
||||
dtostrf(temperature,1,1,tempstring);
|
||||
knobNode.setProperty("temperature").send(tempstring);
|
||||
}
|
||||
float _currentHumidity=dht.readHumidity();
|
||||
if (humidity!=_currentHumidity && (!isnan(_currentHumidity) ==1) && _currentHumidity>0){
|
||||
humidity=_currentHumidity;
|
||||
Homie.getLogger() << "humidity= " << humidity << endl;
|
||||
knobNode.setProperty("humidity").send(String(humidity));
|
||||
}
|
||||
lastSensorMillis=millis();
|
||||
}
|
||||
|
||||
|
||||
ArduinoOTA.handle();
|
||||
|
@ -70,6 +94,8 @@ void setup() {
|
|||
|
||||
knobNode.advertise("encoder");
|
||||
knobNode.advertise("btnknob");
|
||||
knobNode.advertise("temperature");
|
||||
knobNode.advertise("humidity");
|
||||
|
||||
Homie.setup();
|
||||
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
|
||||
|
|
Loading…
Reference in New Issue