Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2.  
  3. #include <FirebaseArduino.h>
  4.  
  5.  
  6.  
  7. int leds[2] = {D3,D4};
  8.  
  9. int states[2] = {LOW,LOW};
  10.  
  11. int totalDevices = 2;
  12.  
  13. int Firepin = D0;
  14.  
  15. FirebaseArduino mu;
  16.  
  17.  
  18. #define firebaseURl "dsdp-636be.firebaseio.com"
  19.  
  20. #define authCode "dLN2XMbJN9AjEIhFc5m1KJLhsFibpiMmeCcS3Etu"
  21.  
  22. //#define wifiName "rrr"
  23.  
  24. //#define wifiPass "12345678"
  25.  
  26.  
  27.  
  28. #define wifiName "Munif"
  29.  
  30. #define wifiPass "12345678"
  31.  
  32.  
  33.  
  34. String chipId = "123";
  35.  
  36.  
  37.  
  38.  
  39.  
  40. bool on = false;
  41.  
  42. int change(int a){
  43.  
  44.   if(a==1) return 0;
  45.  
  46.   else return 1;
  47.  
  48. }
  49.  
  50. void setupFirebase(){
  51.  
  52.   Firebase.begin( firebaseURl, authCode );
  53.  
  54.   //
  55.   mu.begin(firebaseURl, authCode);
  56.  
  57. }
  58.  
  59. void setupPinsMode(){
  60.  
  61.   pinMode(leds[0], OUTPUT);
  62.  
  63.   pinMode(leds[1], OUTPUT);
  64.  
  65.   pinMode(A0, INPUT);
  66.  
  67.   pinMode(Firepin, INPUT);
  68. }
  69.  
  70. void setupWifi() {
  71.  
  72.  
  73.  
  74.   WiFi.begin(wifiName, wifiPass);
  75.  
  76.  
  77.  
  78.   Serial.println("Hey i'm connecting...");
  79.  
  80.  
  81.  
  82.   while (WiFi.status() != WL_CONNECTED) {
  83.  
  84.  
  85.  
  86.     Serial.println(".");
  87.  
  88.     delay(500);
  89.  
  90.   }
  91.  
  92.  
  93.  
  94.   Serial.println();
  95.  
  96.   Serial.println("I 'm connected and my IP address: ");
  97.  
  98.   Serial.println(WiFi.localIP());
  99.  
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. void setup() {
  109.  
  110.   // put your setup code here, to run once:
  111.  
  112.   Serial.begin(9600);
  113.  
  114.   setupWifi();
  115.  
  116.   setupFirebase();
  117.  
  118.   setupPinsMode();
  119.  
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. void getData() {
  131.  
  132.   String path1 = chipId + "/status";
  133.   String path2 = "/noti/fire";
  134.  
  135.   FirebaseObject object1 = Firebase.get(path1);
  136.  
  137.  
  138.  
  139.   int led1 = object1.getInt("001");
  140.  
  141.   int led2 = object1.getInt("002");
  142.  
  143. //  Serial.println();
  144. //
  145. //  Serial.println("Led 1: ");
  146. //
  147. //  Serial.println(led1);
  148. //
  149. //  Serial.println();
  150. //
  151. //  Serial.println("Led 2: ");
  152. //
  153. //  Serial.println(led2);
  154.  
  155. // write output high or low to turn on or off led
  156.  
  157.   led1 = change(led1);
  158.  
  159.   if(led1 == 1) on = true;
  160.  
  161.   int light = analogRead(A0);
  162.  
  163.   if(on==false && light<800){
  164.  
  165.     change(led1);
  166.  
  167.   }
  168.  
  169.   digitalWrite(leds[0], led1);
  170.  
  171.   digitalWrite(leds[1], change(led2));
  172.  
  173.  
  174.  
  175.  
  176.  
  177.   FirebaseObject object2 = Firebase.get(path2);
  178.  
  179.  
  180.   int Fire = object2.getInt("fire");
  181.  
  182. //  Serial.print("Done by Munif Fire = ");
  183. //  Serial.println(Fire);  
  184.  
  185.   Serial.println("FUNCTION");
  186.  
  187.   if(!digitalRead(Firepin)){
  188.     Serial.println("GOT FIRE BEFORE");
  189.   }
  190.  
  191.   if(Fire==0 && !digitalRead(Firepin)){
  192.     Serial.println("GOT FIRE");
  193. //    delay(1000);
  194.     //Firebase.setInt("fire", 1);
  195.     mu.setInt(path2,1);
  196.   }
  197.  
  198.  
  199.  
  200. }
  201.  
  202.  
  203. void loop() {
  204.  
  205.   getData();
  206.  
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement