-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHTboth_sendFirebase.ino
105 lines (82 loc) · 2.53 KB
/
DHTboth_sendFirebase.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <FirebaseESP32.h>
#include <WiFi.h>
#include "DHT.h"
#define DHTPIN1 13
#define DHTPIN2 15
#define DHTTYPE DHT22
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
#define FIREBASE_HOST "https://smartsilo-4115a-default-rtdb.firebaseio.com/"
#define WIFI_SSID "AndroidAPD9EE" // Change the name of your WIFI
#define WIFI_PASSWORD "Vedant@1712" // Change the password of your WIFI
#define FIREBASE_Authorization_key "olLWg0GODF6Y5IqQ8FgshqvknrkMUyR2B2W2V9UM"
FirebaseData firebaseData1;
FirebaseJson json;
float h1,t1,h2,t2;
int bottomfanpin=26;
int topfanpin=25;
void setup() {
Serial.begin(9600);
pinMode(bottomfanpin,OUTPUT);
pinMode(topfanpin,OUTPUT);
Serial.println(F("DHTxx test!"));
dht1.begin();
dht2.begin();
WiFi.begin (WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting...");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
Serial.println();
Firebase.begin(FIREBASE_HOST, FIREBASE_Authorization_key);
if (!Firebase.beginStream(firebaseData1, "Electriculture" ))
{
Serial.println("------------------------------------");
Serial.println("Can't begin stream connection...");
Serial.println("REASON: " + firebaseData1.errorReason());
Serial.println("------------------------------------");
Serial.println();
}
else
{
Serial.println("Stream success");
}
}
void loop() {
//delay(2000);
h1 = dht1.readHumidity();
t1 = dht1.readTemperature();
h2 = dht2.readHumidity();
t2 = dht2.readTemperature();
if (isnan(h1) || isnan(t1) || isnan(h2) || isnan(t2) ) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity 1 : "));
Serial.print(h1);
Serial.print(F("% Temperature 1 : "));
Serial.print(t1);
Serial.print(F("°C "));
Serial.print(F("Humidity 2 : "));
Serial.print(h2);
Serial.print(F("% Temperature 2 : "));
Serial.print(t2);
Serial.print(F("°C "));
Firebase.setFloat(firebaseData1, "/EFarm/Humidity1", h1);
Firebase.setFloat(firebaseData1, "/EFarm/Temperature1", t1);
Firebase.setFloat(firebaseData1, "/EFarm/Humidity2", h2);
Firebase.setFloat(firebaseData1, "/EFarm/Temperature2", t2);
if(t1>=28){
digitalWrite(topfanpin,HIGH);
digitalWrite(bottomfanpin,HIGH);
}
else{
digitalWrite(topfanpin,LOW);
digitalWrite(bottomfanpin,LOW);
}
}