Use Adafruit dht library instead of SimpleDHT everywhere
authorEmmanuel Lacour <elacour@easter-eggs.com>
Sat, 23 Jan 2021 14:57:06 +0000 (15:57 +0100)
committerEmmanuel Lacour <elacour@easter-eggs.com>
Sat, 23 Jan 2021 14:57:06 +0000 (15:57 +0100)
garage/garage.ino
palier/palier.ino
salon/salon.ino

index 0c11eaa..67576eb 100644 (file)
@@ -1,7 +1,9 @@
 #include <WiFi.h>
 #include <WiFiUdp.h>
 #include <TeleInfo.h>
 #include <WiFi.h>
 #include <WiFiUdp.h>
 #include <TeleInfo.h>
-#include <SimpleDHT.h>
+#include <Adafruit_Sensor.h>
+#include <DHT.h>
+#include <DHT_U.h>
 
 #include "garage-config.h"
 
 
 #include "garage-config.h"
 
@@ -18,8 +20,10 @@ String city = CITY;
 String location = LOCATION;
 WiFiUDP Udp;
 
 String location = LOCATION;
 WiFiUDP Udp;
 
-int pinDHT22 = 13;
-SimpleDHT22 dht22(pinDHT22);
+// Temp
+#define DHTPIN 13
+#define DHTTYPE DHT22
+DHT_Unified dht(DHTPIN, DHTTYPE);
 
 TeleInfo teleinfo(&Serial);
 
 
 TeleInfo teleinfo(&Serial);
 
@@ -32,15 +36,30 @@ void setup() {
   while (WiFi.status() != WL_CONNECTED) {
     delay(500);
   }
   while (WiFi.status() != WL_CONNECTED) {
     delay(500);
   }
+
+  dht.begin();
+  sensor_t sensor;
+  dht.temperature().getSensor(&sensor);
+  dht.humidity().getSensor(&sensor);
+
 }
 
 void loop() {
 }
 
 void loop() {
-  float temperature = 0;
-  float humidity = 0;
-  int err = SimpleDHTErrSuccess;
-  if ((err = dht22.read2(&temperature, &humidity, NULL)) == SimpleDHTErrSuccess) {
-    sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(temperature));
-    sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(humidity));
+  delay(POLL_INT);
+
+  sensors_event_t event;
+  
+  dht.temperature().getEvent(&event);
+  if (isnan(event.temperature)) {
+    // Error
+  } else {
+      sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+  }
+  dht.humidity().getEvent(&event);
+  if (isnan(event.relative_humidity)) {
+    // Error
+  } else {
+      sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
   }
   
   teleinfo.process();
   }
   
   teleinfo.process();
@@ -57,7 +76,6 @@ void loop() {
     sendToInfluxDB("teleinfo,city="+city, "BASE", String(BASE));
     teleinfo.resetAvailable();
   }
     sendToInfluxDB("teleinfo,city="+city, "BASE", String(BASE));
     teleinfo.resetAvailable();
   }
-  delay(POLL_INT);
 }
 
 void sendToInfluxDB(String measure, String key, String value) {
 }
 
 void sendToInfluxDB(String measure, String key, String value) {
index 33ba10d..7cf3a33 100644 (file)
@@ -1,6 +1,8 @@
 #include <WiFi.h>
 #include <WiFiUdp.h>
 #include <WiFi.h>
 #include <WiFiUdp.h>
-#include <SimpleDHT.h>
+#include <Adafruit_Sensor.h>
+#include <DHT.h>
+#include <DHT_U.h>
 
 #include "palier-config.h"
 
 
 #include "palier-config.h"
 
@@ -17,8 +19,10 @@ String city = CITY;
 String location = LOCATION;
 WiFiUDP Udp;
 
 String location = LOCATION;
 WiFiUDP Udp;
 
-int pinDHT22 = 13;
-SimpleDHT22 dht22(pinDHT22);
+// Temp
+#define DHTPIN 13
+#define DHTTYPE DHT22
+DHT_Unified dht(DHTPIN, DHTTYPE);
 
 void setup() {
 
 
 void setup() {
 
@@ -29,18 +33,32 @@ void setup() {
   while (WiFi.status() != WL_CONNECTED) {
     delay(500);
   }
   while (WiFi.status() != WL_CONNECTED) {
     delay(500);
   }
+
+  dht.begin();
+  sensor_t sensor;
+  dht.temperature().getSensor(&sensor);
+  dht.humidity().getSensor(&sensor);
+
 }
 
 void loop() {
 }
 
 void loop() {
-  float temperature = 0;
-  float humidity = 0;
-  int err = SimpleDHTErrSuccess;
-  if ((err = dht22.read2(&temperature, &humidity, NULL)) == SimpleDHTErrSuccess) {
-    sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(temperature));
-    sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(humidity));
+  delay(POLL_INT);
+
+  sensors_event_t event;
+  
+  dht.temperature().getEvent(&event);
+  if (isnan(event.temperature)) {
+    // Error
+  } else {
+      sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+  }
+  dht.humidity().getEvent(&event);
+  if (isnan(event.relative_humidity)) {
+    // Error
+  } else {
+      sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
   }
   
   }
   
-  delay(POLL_INT);
 }
 
 void sendToInfluxDB(String measure, String key, String value) {
 }
 
 void sendToInfluxDB(String measure, String key, String value) {
index fb7d51f..5bcbc38 100644 (file)
@@ -1,6 +1,8 @@
 #include <WiFi.h>
 #include <WiFiUdp.h>
 #include <WiFi.h>
 #include <WiFiUdp.h>
-#include <SimpleDHT.h>
+#include <Adafruit_Sensor.h>
+#include <DHT.h>
+#include <DHT_U.h>
 
 #include "salon-config.h"
 
 
 #include "salon-config.h"
 
@@ -17,8 +19,10 @@ String city = CITY;
 String location = LOCATION;
 WiFiUDP Udp;
 
 String location = LOCATION;
 WiFiUDP Udp;
 
-int pinDHT22 = 13;
-SimpleDHT22 dht22(pinDHT22);
+// Temp
+#define DHTPIN 13
+#define DHTTYPE DHT22
+DHT_Unified dht(DHTPIN, DHTTYPE);
 
 void setup() {
 
 
 void setup() {
 
@@ -29,18 +33,32 @@ void setup() {
   while (WiFi.status() != WL_CONNECTED) {
     delay(500);
   }
   while (WiFi.status() != WL_CONNECTED) {
     delay(500);
   }
+
+  dht.begin();
+  sensor_t sensor;
+  dht.temperature().getSensor(&sensor);
+  dht.humidity().getSensor(&sensor);
+
 }
 
 void loop() {
 }
 
 void loop() {
-  float temperature = 0;
-  float humidity = 0;
-  int err = SimpleDHTErrSuccess;
-  if ((err = dht22.read2(&temperature, &humidity, NULL)) == SimpleDHTErrSuccess) {
-    sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(temperature));
-    sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(humidity));
+  delay(POLL_INT);
+
+  sensors_event_t event;
+  
+  dht.temperature().getEvent(&event);
+  if (isnan(event.temperature)) {
+    // Error
+  } else {
+      sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature));
+  }
+  dht.humidity().getEvent(&event);
+  if (isnan(event.relative_humidity)) {
+    // Error
+  } else {
+      sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
   }
   
   }
   
-  delay(POLL_INT);
 }
 
 void sendToInfluxDB(String measure, String key, String value) {
 }
 
 void sendToInfluxDB(String measure, String key, String value) {