From 547f841124fcefad34f915d7d725c1bb545d3de3 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Mon, 30 Sep 2019 19:30:07 +0100
Subject: [PATCH] Write ESP DHT22 demo

---
 .gitmodules                     |  4 +++
 dht22-esp8266/dht22-esp8266.ino | 33 ++++++++++++++++++++++++
 dht22-esp8266/lib/esp8266-dht22 |  1 +
 dht22/dht22.ino                 | 45 ++++++++++++++++-----------------
 dht22/lib/SimpleDHT             |  2 +-
 5 files changed, 61 insertions(+), 24 deletions(-)
 create mode 100644 dht22-esp8266/dht22-esp8266.ino
 create mode 160000 dht22-esp8266/lib/esp8266-dht22

diff --git a/.gitmodules b/.gitmodules
index 0812ed3..8cba6a8 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,3 +4,7 @@
 [submodule "dht22/lib/SimpleDHT"]
 	path = dht22/lib/SimpleDHT
 	url = https://github.com/winlinvip/SimpleDHT
+[submodule "dht22-esp8266/lib/esp8266-dht22"]
+	path = dht22-esp8266/lib/esp8266-dht22
+	url = https://github.com/Defozo/esp8266-dht22.git
+	branch = patch-1
diff --git a/dht22-esp8266/dht22-esp8266.ino b/dht22-esp8266/dht22-esp8266.ino
new file mode 100644
index 0000000..cc265fb
--- /dev/null
+++ b/dht22-esp8266/dht22-esp8266.ino
@@ -0,0 +1,33 @@
+#include "lib/esp8266-dht22/dht22.h"
+#include "lib/esp8266-dht22/dht22.c"
+
+#define DHT_TYPE		DHT22
+// D1
+#define DHT_PIN_DATA	5
+
+void setup() {
+	Serial.begin(115200);
+	Serial.println("DHT22 Demo");
+	Serial.println("==========");
+	Serial.println("Board: ESP8266");
+	
+	Serial.print("Initialising the DHT - ");
+	DHT_init(DHT_PIN_DATA, DHT_TYPE, 1);
+	DHT_begin();
+	
+    Serial.println("done"); 
+	Serial.print("Waiting to warm DHT22 up - ");
+	delay(2000); // Give the DHT22 time to warm up
+}
+
+void loop() {
+	float temp, humidity;
+	
+	temp = readTemperature(false);
+	humidity = readHumidity();
+	
+	Serial.print("Temperature: "); Serial.print(temp); Serial.println("°C");
+	Serial.print("Humidity: "); Serial.print(humidity); Serial.println("%");
+	
+	delay(1000);
+}
diff --git a/dht22-esp8266/lib/esp8266-dht22 b/dht22-esp8266/lib/esp8266-dht22
new file mode 160000
index 0000000..b949ac3
--- /dev/null
+++ b/dht22-esp8266/lib/esp8266-dht22
@@ -0,0 +1 @@
+Subproject commit b949ac35a553e4089f3e81dc7e4d739a02a00f78
diff --git a/dht22/dht22.ino b/dht22/dht22.ino
index 4a26322..b04e04b 100644
--- a/dht22/dht22.ino
+++ b/dht22/dht22.ino
@@ -16,27 +16,26 @@ void setup() {
 }
 
 void loop() {
-  float temp = 0, humidity = 0;
-  
-  int read_error = dhtA.read2(dhtA_pin, &temp, &humidity, NULL);
-  Serial.println("Read complete - analysing result");
-  if(read_error != SimpleDHTErrSuccess) {
-    Serial.print("Error: Failed reading from the DHT22. Code: ");
-    Serial.println(read_error);
-    delay(2000); // We can only read every 2 seconds or so
-    return;
-  }
-  
-  Serial.print("Error code: ");
-  Serial.println(read_error);
-  Serial.print("Temperature: ");
-  Serial.print(temp);
-  Serial.println(" deg celsius");
-  Serial.print("Humidity: ");
-  Serial.print(humidity);
-  Serial.println("%");
-  Serial.println("*****");
-  
-  delay(2000); // We can only read every 2 seconds
-}
+    float temp = 0, humidity = 0;
 
+    int read_error = dhtA.read2(dhtA_pin, &temp, &humidity, NULL);
+    Serial.println("Read complete - analysing result");
+    if(read_error != SimpleDHTErrSuccess) {
+        Serial.print("Error: Failed reading from the DHT22. Code: ");
+        Serial.println(read_error);
+        delay(2000); // We can only read every 2 seconds or so
+        return;
+    }
+
+    Serial.print("Error code: ");
+    Serial.println(read_error);
+    Serial.print("Temperature: ");
+    Serial.print(temp);
+    Serial.println(" deg celsius");
+    Serial.print("Humidity: ");
+    Serial.print(humidity);
+    Serial.println("%");
+    Serial.println("*****");
+
+    delay(2000); // We can only read every 2 seconds
+}
diff --git a/dht22/lib/SimpleDHT b/dht22/lib/SimpleDHT
index 80ac2b4..155f774 160000
--- a/dht22/lib/SimpleDHT
+++ b/dht22/lib/SimpleDHT
@@ -1 +1 @@
-Subproject commit 80ac2b47c9caca07edf75f38289cfd64023872c9
+Subproject commit 155f77445daa0b4757f79d984865ba68a59a7cf8
