spejsiot/spejsiot/endpoints/DHTEndpoint.cpp

22 lines
538 B
C++

#include <endpoints/DHTEndpoint.h>
void DHTEndpoint::bind(String _name, SpejsNode* _parent) {
Endpoint::bind(_name, _parent);
sensor.begin();
samplingTimer.initializeMs(samplingRate, TimerDelegate(&DHTEndpoint::sample, this)).start();
}
void DHTEndpoint::sample() {
TempAndHumidity th;
if(sensor.readTempAndHumidity(th))
{
notify("degree", String(th.temp));
notify("humidity", String(th.humid));
}
else
{
debugf("Failed to read from DHT: %d", sensor.getLastError());
}
}