-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase_data_upload.ino
74 lines (58 loc) · 1.61 KB
/
firebase_data_upload.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
#include "DHT.h" // including the library of DHT11 temperature and humidity sensor
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#define FIREBASE_HOST "agricultureiot-15069.firebaseio.com"
#define FIREBASE_AUTH "lr37reWAOmI2NNZx4MpK8y1baqR6yNfglMRpl5N2"
#define WIFI_SSID "IoT_Lab"
#define WIFI_PASSWORD "iiitbbsr"
#define DHTTYPE DHT11 // DHT 11
#define dht_dpin D3
DHT dht(dht_dpin, DHTTYPE);
int soil_sensor = A0;
int moisture_val;
float h,t;
WiFiServer server(80);
void setup() {
dht.begin();
delay(700);
Serial.begin(9600);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
server.begin();
Serial.print(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
// temp_humid_value = DHT.read11(temp_humid_sensor);
// humid_val = DHT.humidity;
// temp_val = DHT.temperature;
h = dht.readHumidity();
delay(700);
t = dht.readTemperature();
if( isnan(t) || isnan(h))
{return;}
else{
moisture_val= analogRead(soil_sensor);
moisture_val = map(moisture_val,1023,0,0,100);
}
Serial.print("humidity:");
Serial.println(h);
Serial.print("temperature:");
Serial.println(t);
Serial.print("Soil Moisture:");
Serial.println(moisture_val);
//PUSIHNG INTO LOGS.....
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["Temperature"] = t;
root["Humidity"] = h;
root["Moisture"] = moisture_val;
String name = Firebase.push("/sensors/data", root);
Serial.print("pushed: /logs/");
Serial.println(name);
delay(5000);
}