-
Notifications
You must be signed in to change notification settings - Fork 2
/
firebase.ino
79 lines (58 loc) · 1.95 KB
/
firebase.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
#include "FirebaseESP8266.h" // Install Firebase ESP8266 library
#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#define FIREBASE_HOST "potholes-cde20-default-rtdb.firebaseio.com/" //Without http:// or https:// schemes
#define FIREBASE_AUTH "cst7eKImsrW2Wy9zyFAE6AOE9kNBgd8WCRjJTfjA"
#define WIFI_SSID "test"
#define WIFI_PASSWORD "12345678"
FirebaseData firebaseData;
FirebaseData Data;
FirebaseJson json;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
String hrMin = "", curDay = "", monthYr = "", epoch="";
void setup() {
Serial.begin(9600);
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);
timeClient.begin();
timeClient.setTimeOffset((5 * 60 + 30) * 60);
}
void loop() {
//Firebase.set(firebaseData, "/users/sindhu/", 4);
getTime();
while (Serial.available()) {
String readStr = String(Serial.readString());
// Firebase.set(firebaseData, "/users/" + epoch + "/", readStr);
Firebase.setString(firebaseData, "/users/" + epoch, readStr);
Serial.print("/users/" + epoch + "/");
Serial.println(readStr);
}
}
void getTime() {
timeClient.update();
int currentHour = timeClient.getHours();
int currentMinute = timeClient.getMinutes();
time_t epochTime = timeClient.getEpochTime();
epoch = String(epochTime);
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
int currentMonth = ptm->tm_mon + 1;
int currentYear = ptm->tm_year + 1900;
monthYr = String(currentMonth) + "-" + String(currentYear);
curDay = String(monthDay);
hrMin = String(currentHour) + String(currentMinute);
//Serial.println(monthYr + "\n" + curDay + "\n" + hrMin);
return;
}