-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.ino
97 lines (75 loc) · 2.09 KB
/
code.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
#include "FirebaseESP8266.h”
#include <ESP8266WiFi.h>
#define FIREBASE_HOST "LINK OF DATABASE WITHOUT HTTps" //Without http:// or https:// schemes
#define FIREBASE_AUTH "AUTH KAY"
#define WIFI_SSID "Galaxy M124C0B"
#define WIFI_PASSWORD "Vansh123"
int led = D4; // Connect LED to D5
FirebaseData firebaseData;
FirebaseData ledData;
FirebaseJson json;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
}
void sensorUpdate(){
digitalWrite(led,true);
int t = digitalRead(led);
if (Firebase.setFloat(firebaseData, "/light_a/light_mon", t))
{
Serial.println("PASSED");
Serial.println("PATH: " + firebaseData.dataPath());
Serial.println("TYPE: " + firebaseData.dataType());
Serial.println("ETag: " + firebaseData.ETag());
Serial.println("------------------------------------");
Serial.println();
}
else
{
Serial.println("FAILED");
Serial.println("REASON: " + firebaseData.errorReason());
Serial.println("------------------------------------");
Serial.println();
}
delay(1000);
}
void sensorUpdate1(){
digitalWrite(led,false);
int t = digitalRead(led);
if (Firebase.setFloat(firebaseData, "/light_a/light_mon", t))
{
Serial.println("PASSED");
Serial.println("PATH: " + firebaseData.dataPath());
Serial.println("TYPE: " + firebaseData.dataType());
Serial.println("ETag: " + firebaseData.ETag());
Serial.println("------------------------------------");
Serial.println();
}
else
{
Serial.println("FAILED");
Serial.println("REASON: " + firebaseData.errorReason());
Serial.println("------------------------------------");
Serial.println();
}
delay(1000);
}
void loop() {
sensorUpdate();
sensorUpdate1();
delay(100);
}