Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1.  
  2.  
  3. // FirebaseDemo_ESP8266 is a sample that demo the different functions
  4. // of the FirebaseArduino API.
  5. #include <Firebase.h>
  6. #include <FirebaseCloudMessaging.h>
  7. #include <FirebaseError.h>
  8. #include <FirebaseHttpClient.h>
  9. #include <FirebaseObject.h>
  10.  
  11. #include <ESP8266WiFi.h>
  12. #include <FirebaseArduino.h>
  13.  
  14. // Set these to run example.
  15. #define WIFI_SSID "Funhall int"
  16. #define WIFI_PASSWORD "venovej1"
  17. #define FIREBASE_HOST "funhallproject.firebaseio.com"
  18. #define FIREBASE_AUTH "8azfYqqSHrfJLFvygX1Qa54oV1i33Ih16PwJElUj"
  19. #define Relay1 14 //D5
  20. #define Relay2 12 //D6
  21. //#define Relay3 13 //D7
  22. //#define Relay4 15 //D8
  23. int rel1,rel2;
  24. int button1 = D1;
  25. int button2 = D2;
  26.  
  27. void setup()
  28. {
  29. Serial.begin(115200); // Select the same baud rate if you want to see the datas on Serial Monitor
  30. pinMode(Relay1,OUTPUT);
  31. pinMode(Relay2,OUTPUT);
  32. // pinMode(Relay3,OUTPUT);
  33. // pinMode(Relay4,OUTPUT);
  34. pinMode(button1, INPUT);
  35. pinMode(button2, INPUT);
  36. digitalWrite(Relay1,HIGH);
  37. digitalWrite(Relay2,HIGH);
  38. // digitalWrite(Relay3,HIGH);
  39. // digitalWrite(Relay4,HIGH);
  40. WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
  41. Serial.print("connecting");
  42. while (WiFi.status()!=WL_CONNECTED){
  43. Serial.print(".");
  44. delay(50);
  45. }
  46. Serial.println();
  47. Serial.print("connected:");
  48. Serial.println(WiFi.localIP());
  49.  
  50. Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH);
  51. //Firebase.setInt("tryk1",0);
  52. //Firebase.setInt("tryk2",0);
  53. //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
  54. // Firebase.setInt("Terminal_4/Dropoff_ud",0);
  55. Firebase.setInt("Terminal_4/Dropoff_ind",1);
  56. Firebase.setInt("Terminal_4/Dropoff_ud",1);
  57.  
  58. }
  59. void firebasereconnect()
  60. {
  61. Serial.println("Trying to reconnect");
  62. Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  63. }
  64.  
  65. void loop()
  66.  
  67. {
  68. // rel1=Firebase.getString("Terminal_4/Dropoff_ind").toInt(); //Reading the value of the varialble Status from the firebase
  69. // rel2=Firebase.getString("Terminal_4/Dropoff_ud").toInt(); //Reading the value of the varialble Status from the firebase
  70. rel1=Firebase.getString("Terminal_4/Dropoff_ind").toInt(); //Reading the value of the varialble Status from the firebase
  71. rel2=Firebase.getString("FB1").toInt(); //Reading the value of the varialble Status from the firebase
  72.  
  73. if(rel1==1) // If, the Status is 1, turn on the Relay1
  74. {
  75. digitalWrite(Relay1,LOW);
  76. Serial.println("Relay 1 ON");
  77. }
  78. if(rel1==0) // If, the Status is 0, turn Off the Relay1
  79. {
  80. digitalWrite(Relay1,HIGH);
  81. Serial.println("Relay 1 OFF");
  82. }
  83. if(rel2==1) // If, the Status is 1, turn on the Relay2
  84. {
  85. digitalWrite(Relay2,LOW);
  86. Serial.println("Relay 2 ON");
  87. }
  88. if(rel2==0) // If, the Status is 0, turn Off the Relay2
  89. {
  90. digitalWrite(Relay2,HIGH);
  91. Serial.println("Relay 2 OFF");
  92. }
  93. /*
  94. if(rel3==1) // If, the Status is 1, turn on the Relay3
  95. {
  96. digitalWrite(Relay3,LOW);
  97. Serial.println("Relay 3 ON");
  98. }
  99.  
  100.  
  101. if(rel3==0) // If, the Status is 0, turn Off the Relay3
  102. {
  103. digitalWrite(Relay3,HIGH);
  104. Serial.println("Relay 3 OFF");
  105. }
  106. if(rel4==1) // If, the Status is 1, turn on the Relay4
  107. {
  108. digitalWrite(Relay4,LOW);
  109. Serial.println("Relay 4 ON");
  110. }
  111. if(rel4==0) // If, the Status is 0, turn Off the Relay4
  112. {
  113. digitalWrite(Relay4,HIGH);
  114. Serial.println("Relay 4 OFF");
  115. }
  116. */
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement