Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FirebaseDemo_ESP8266 is a sample that demo the different functions
- // of the FirebaseArduino API.
- #include <Firebase.h>
- #include <FirebaseCloudMessaging.h>
- #include <FirebaseError.h>
- #include <FirebaseHttpClient.h>
- #include <FirebaseObject.h>
- #include <ESP8266WiFi.h>
- #include <FirebaseArduino.h>
- // Set these to run example.
- #define WIFI_SSID "Funhall int"
- #define WIFI_PASSWORD "venovej1"
- #define FIREBASE_HOST "funhallproject.firebaseio.com"
- #define FIREBASE_AUTH "8azfYqqSHrfJLFvygX1Qa54oV1i33Ih16PwJElUj"
- #define Relay1 14 //D5
- #define Relay2 12 //D6
- //#define Relay3 13 //D7
- //#define Relay4 15 //D8
- int rel1,rel2;
- int button1 = D1;
- int button2 = D2;
- void setup()
- {
- Serial.begin(115200); // Select the same baud rate if you want to see the datas on Serial Monitor
- pinMode(Relay1,OUTPUT);
- pinMode(Relay2,OUTPUT);
- // pinMode(Relay3,OUTPUT);
- // pinMode(Relay4,OUTPUT);
- pinMode(button1, INPUT);
- pinMode(button2, INPUT);
- digitalWrite(Relay1,HIGH);
- digitalWrite(Relay2,HIGH);
- // digitalWrite(Relay3,HIGH);
- // digitalWrite(Relay4,HIGH);
- WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
- Serial.print("connecting");
- while (WiFi.status()!=WL_CONNECTED){
- Serial.print(".");
- delay(50);
- }
- Serial.println();
- Serial.print("connected:");
- Serial.println(WiFi.localIP());
- Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH);
- //Firebase.setInt("tryk1",0);
- //Firebase.setInt("tryk2",0);
- //Firebase.setInt("Terminal_4/Dropoff_ind",0); //Here the varialbe"FB1","FB2","FB3" and "FB4" needs to be the one which is used in our Firebase and MIT App Inventor
- // Firebase.setInt("Terminal_4/Dropoff_ud",0);
- Firebase.setInt("Terminal_4/Dropoff_ind",1);
- Firebase.setInt("Terminal_4/Dropoff_ud",1);
- }
- void firebasereconnect()
- {
- Serial.println("Trying to reconnect");
- Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
- }
- void loop()
- {
- // rel1=Firebase.getString("Terminal_4/Dropoff_ind").toInt(); //Reading the value of the varialble Status from the firebase
- // rel2=Firebase.getString("Terminal_4/Dropoff_ud").toInt(); //Reading the value of the varialble Status from the firebase
- rel1=Firebase.getString("Terminal_4/Dropoff_ind").toInt(); //Reading the value of the varialble Status from the firebase
- rel2=Firebase.getString("FB1").toInt(); //Reading the value of the varialble Status from the firebase
- if(rel1==1) // If, the Status is 1, turn on the Relay1
- {
- digitalWrite(Relay1,LOW);
- Serial.println("Relay 1 ON");
- }
- if(rel1==0) // If, the Status is 0, turn Off the Relay1
- {
- digitalWrite(Relay1,HIGH);
- Serial.println("Relay 1 OFF");
- }
- if(rel2==1) // If, the Status is 1, turn on the Relay2
- {
- digitalWrite(Relay2,LOW);
- Serial.println("Relay 2 ON");
- }
- if(rel2==0) // If, the Status is 0, turn Off the Relay2
- {
- digitalWrite(Relay2,HIGH);
- Serial.println("Relay 2 OFF");
- }
- /*
- if(rel3==1) // If, the Status is 1, turn on the Relay3
- {
- digitalWrite(Relay3,LOW);
- Serial.println("Relay 3 ON");
- }
- if(rel3==0) // If, the Status is 0, turn Off the Relay3
- {
- digitalWrite(Relay3,HIGH);
- Serial.println("Relay 3 OFF");
- }
- if(rel4==1) // If, the Status is 1, turn on the Relay4
- {
- digitalWrite(Relay4,LOW);
- Serial.println("Relay 4 ON");
- }
- if(rel4==0) // If, the Status is 0, turn Off the Relay4
- {
- digitalWrite(Relay4,HIGH);
- Serial.println("Relay 4 OFF");
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement