-
Notifications
You must be signed in to change notification settings - Fork 0
/
Central Server -without ESPfirebase.ino
68 lines (57 loc) · 2 KB
/
Central Server -without ESPfirebase.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
// C4:5B:BE:63:19:BA Sever IP Address
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <Firebase_ESP_Client.h>
#include "addons/TokenHelper.h"
#include "addons/RTDBHelper.h"
#define WIFI_SSID "Inter"
#define WIFI_PASSWORD "#helloworld"
#define API_KEY "AIzaSyA5bJvaz2rlyiGu3MtKcDLCo7Ycd4OZzkM"
#define DATABASE_URL "https://inter-iit-60162-default-rtdb.firebaseio.com/"
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
int count = 0;
bool signupOK = false;
void setup(){
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(300);
}
config.api_key = API_KEY;
config.database_url = DATABASE_URL;
if (Firebase.signUp(&config, &auth, "", "")){
signupOK = true;
}
else{
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
config.token_status_callback = tokenStatusCallback;
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
}
void loop(){
if (Firebase.ready() && signupOK && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0)){
sendDataPrevMillis = millis();
int a=random (1,20);
int b=random (1,20);
int c=random (1,20);
int d=random (1,20);
int e=random (1,20);
// Serial.print("in loop");
bool sent1=Firebase.RTDB.setInt(&fbdo, "BinPerLevel/29-84715419999999|77-8817452/height", a);
bool sent2=Firebase.RTDB.setInt(&fbdo, "BinPerLevel/29-8624811|77-8941031/height", b);
bool sent3=Firebase.RTDB.setInt(&fbdo, "BinPerLevel/29-8542626|77-8880002/height", c);
bool sent4=Firebase.RTDB.setInt(&fbdo, "BinPerLevel/29-8542626|77-8880002/height", d);
bool sent5=Firebase.RTDB.setInt(&fbdo, "BinPerLevel/29-8765003|77-8890677/height", e);
if(sent1 || sent2 || sent3 || sent4 || sent5)
Serial.print("Scuces");
}
}