Guest User

Untitled

a guest
Jan 24th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #include <FirebaseArduino.h>
  2. #include <DHT.h>
  3. #define DHTPIN 2
  4. #define DHTTYPE DHT11
  5. #include <SoftwareSerial.h>
  6. SoftwareSerial ESP8266(10,11);
  7. #define DEBUG true
  8. #define TRIGGER_PIN 4
  9. #define ECHO_PIN 3
  10.  
  11. DHT dht(DHTPIN, DHTTYPE, 11);
  12. void setup() {
  13.  
  14. Serial.begin(115200);
  15. ESP8266.begin(9600);
  16. dht.begin();
  17. pinMode(TRIGGER_PIN, OUTPUT);
  18. pinMode(ECHO_PIN, INPUT);
  19. ESP8266.println("AT+RST");
  20. delay(2000);
  21. Serial.println("Connecting to Wifi");
  22. while(check_connection==0)
  23. {
  24. Serial.print(".");
  25. ESP8266.print("AT+CWJAP="c902b6","262459105"rn");
  26. //ESP8266.print("AT+CWJAP="FAKE_WIFI","bartender"rn");
  27.  
  28. ESP8266.setTimeout(5000);
  29. if(ESP8266.find("WIFI CONNECTEDrn")==1)
  30. {
  31. Serial.println("WIFI CONNECTED");
  32. break;
  33. }
  34. times_check++;
  35. if(times_check>3)
  36. {
  37. times_check=0;
  38. Serial.println("Trying to Reconnect..");
  39. }
  40. }
  41.  
  42. Firebase.begin("thesis1-69.firebaseio.com",
  43. "AIzaSyCNZM0KCYczftfCKtsie2l1WBFnlFLGwNo");
  44. }
  45. bool incuID = 0;
  46.  
  47. void loop() {
  48. int hum = dht.readHumidity();
  49.  
  50. int temp = dht.readTemperature();
  51. digitalWrite(TRIGGER_PIN, LOW);
  52. delayMicroseconds(2);
  53. digitalWrite(TRIGGER_PIN, HIGH);
  54. delayMicroseconds(10);
  55. digitalWrite(TRIGGER_PIN, LOW);
  56. duration = pulseIn(ECHO_PIN,HIGH);
  57. distance = duration*0.034/2;
  58.  
  59. String name = Firebase.push("data", 0);
  60. Serial.print("pushed: /logs/");
  61. delay(1000);
  62.  
  63. Serial.println(name);
  64.  
  65. if (Firebase.failed()) {
  66. Serial.print("setting /number failed:");
  67. Serial.println(Firebase.error());
  68. return;
  69. }
  70.  
  71. if (!incuID) {
  72. Firebase.set("data/" + name + "/Distance", 0);
  73. delay(1000);
  74. Firebase.set("data/" + name + "/Temperature", 0);
  75. delay(1000);
  76. Firebase.set("data/" + name + "/Humidity", 0);
  77. delay(1000);
  78.  
  79.  
  80. incuID = true;
  81. if (Firebase.failed()) {
  82. Serial.print("setting /number failed:");
  83. Serial.println(Firebase.error());
  84. return;
  85. }
  86.  
  87. } else {
  88. Firebase.set("data/" + name + "/distance", distance);
  89. Serial.println(distance);
  90. delay(1000);
  91. Firebase.set("data/" + name + "/temp", temp);
  92. Serial.println(t);
  93. delay(1000);
  94. Firebase.set("data/" + name + "/hum", hum);
  95. Serial.println(h);
  96. delay(1000);
  97.  
  98. if (Firebase.failed()) {
  99. Serial.print("setting /number failed:");
  100. Serial.println(Firebase.error());
  101. return;
  102. }
  103. }
Add Comment
Please, Sign In to add comment