Update to Sming 0b646a58 to fix DHT library
parent
a242d95c9d
commit
dbe39193a7
|
@ -3,19 +3,16 @@
|
|||
void DHTEndpoint::bind(String _name, SpejsNode* _parent) {
|
||||
Endpoint::bind(_name, _parent);
|
||||
|
||||
sensor.begin();
|
||||
sensor.setup(pin, sensor_type);
|
||||
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());
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
#define DHTENDPOINT_H
|
||||
|
||||
#include <Endpoint.h>
|
||||
#include <Libraries/DHT/DHT.h>
|
||||
#include <Libraries/DHTesp/DHTesp.h>
|
||||
|
||||
class DHTEndpoint : public ValueEndpoint<float> {
|
||||
private:
|
||||
DHT sensor;
|
||||
DHTesp sensor;
|
||||
DHTesp::DHT_MODEL_t sensor_type;
|
||||
uint8_t pin;
|
||||
|
||||
Timer samplingTimer;
|
||||
int samplingRate;
|
||||
|
||||
|
@ -14,8 +17,8 @@ protected:
|
|||
void sample();
|
||||
|
||||
public:
|
||||
DHTEndpoint(int _pin, int _samplingRate = 10000, int _sensor_type=DHT11) :
|
||||
ValueEndpoint("dht"), sensor(_pin, _sensor_type),
|
||||
DHTEndpoint(int _pin, int _samplingRate = 10000, DHTesp::DHT_MODEL_t _sensor_type=DHTesp::DHT11) :
|
||||
ValueEndpoint("dht"), pin(_pin), sensor_type(_sensor_type),
|
||||
samplingRate(_samplingRate) {}
|
||||
|
||||
void bind(String name, SpejsNode* _parent);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
SpejsNode node("ambient");
|
||||
|
||||
void init() {
|
||||
node.init();
|
||||
node.registerEndpoint("environment", new DHTEndpoint(2, 10000, DHT22));
|
||||
node.statusLED.config(2, LOW);
|
||||
node.init(true);
|
||||
node.registerEndpoint("environment", new DHTEndpoint(2, 2000, DHTesp::DHT22));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue