Update to Sming 0b646a58 to fix DHT library

master
informatic 2018-09-02 18:32:13 +02:00
parent a242d95c9d
commit dbe39193a7
3 changed files with 17 additions and 16 deletions

View File

@ -3,19 +3,16 @@
void DHTEndpoint::bind(String _name, SpejsNode* _parent) { void DHTEndpoint::bind(String _name, SpejsNode* _parent) {
Endpoint::bind(_name, _parent); Endpoint::bind(_name, _parent);
sensor.begin(); sensor.setup(pin, sensor_type);
samplingTimer.initializeMs(samplingRate, TimerDelegate(&DHTEndpoint::sample, this)).start(); samplingTimer.initializeMs(samplingRate, TimerDelegate(&DHTEndpoint::sample, this)).start();
} }
void DHTEndpoint::sample() { void DHTEndpoint::sample() {
TempAndHumidity th; TempAndHumidity th = sensor.getTempAndHumidity();
if(sensor.readTempAndHumidity(th)) if(sensor.getStatus() == DHTesp::ERROR_NONE) {
{ notify("degree", String(th.temperature));
notify("degree", String(th.temp)); notify("humidity", String(th.humidity));
notify("humidity", String(th.humid)); } else {
} debugf("Failed to read from DHT: %d", sensor.getStatus());
else
{
debugf("Failed to read from DHT: %d", sensor.getLastError());
} }
} }

View File

@ -2,11 +2,14 @@
#define DHTENDPOINT_H #define DHTENDPOINT_H
#include <Endpoint.h> #include <Endpoint.h>
#include <Libraries/DHT/DHT.h> #include <Libraries/DHTesp/DHTesp.h>
class DHTEndpoint : public ValueEndpoint<float> { class DHTEndpoint : public ValueEndpoint<float> {
private: private:
DHT sensor; DHTesp sensor;
DHTesp::DHT_MODEL_t sensor_type;
uint8_t pin;
Timer samplingTimer; Timer samplingTimer;
int samplingRate; int samplingRate;
@ -14,8 +17,8 @@ protected:
void sample(); void sample();
public: public:
DHTEndpoint(int _pin, int _samplingRate = 10000, int _sensor_type=DHT11) : DHTEndpoint(int _pin, int _samplingRate = 10000, DHTesp::DHT_MODEL_t _sensor_type=DHTesp::DHT11) :
ValueEndpoint("dht"), sensor(_pin, _sensor_type), ValueEndpoint("dht"), pin(_pin), sensor_type(_sensor_type),
samplingRate(_samplingRate) {} samplingRate(_samplingRate) {}
void bind(String name, SpejsNode* _parent); void bind(String name, SpejsNode* _parent);

View File

@ -4,6 +4,7 @@
SpejsNode node("ambient"); SpejsNode node("ambient");
void init() { void init() {
node.init(); node.statusLED.config(2, LOW);
node.registerEndpoint("environment", new DHTEndpoint(2, 10000, DHT22)); node.init(true);
node.registerEndpoint("environment", new DHTEndpoint(2, 2000, DHTesp::DHT22));
} }