spejsiot/spejsiot/endpoints/DHTEndpoint.cpp

19 lines
589 B
C++
Raw Normal View History

2017-03-06 16:56:37 +00:00
#include <endpoints/DHTEndpoint.h>
void DHTEndpoint::bind(String _name, SpejsNode* _parent) {
Endpoint::bind(_name, _parent);
sensor.setup(pin, sensor_type);
2017-03-06 16:56:37 +00:00
samplingTimer.initializeMs(samplingRate, TimerDelegate(&DHTEndpoint::sample, this)).start();
}
void DHTEndpoint::sample() {
TempAndHumidity th = sensor.getTempAndHumidity();
if(sensor.getStatus() == DHTesp::ERROR_NONE) {
notify("degree", String(th.temperature));
notify("humidity", String(th.humidity));
} else {
debugf("Failed to read from DHT: %d", sensor.getStatus());
2017-03-06 16:56:37 +00:00
}
}