Guest User

Untitled

a guest
Jul 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <ESP8266WiFi.h> //wifi library
  2. #define WIFI_SSID "SSID" //replace SSID with your wifi username
  3. #define WIFI_PASSWORD "PWD" //replace PWD with your wifi password
  4. #define WIFI_LED D5 //connect a led to any of the gpio pins of the board and replace pin_number with it eg. D4
  5.  
  6. #define FIREBASE_HOST "xxxxxxxxxxx.firebaseio.com" //link of api
  7. #define FIREBASE_AUTH "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" //database secret
  8.  
  9. void setup() {
  10. Serial.begin(9600);
  11. pinMode(WIFI_LED,OUTPUT); //define pinmodes
  12. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  13. //connect to wifi
  14. while (WiFi.status() != WL_CONNECTED) { //wait till connected to WiFi
  15. delay(100);
  16. digitalWrite(WIFI_LED,LOW); //Blink the light till connected to WiFi
  17. delay(100);
  18. digitalWrite(WIFI_LED,HIGH);
  19. Serial.print("."); }
  20.  
  21. Serial.println("");
  22. Serial.println("WiFi connected");
  23. digitalWrite(WIFI_LED,HIGH);
  24. Serial.println("IP address: ");
  25. Serial.println(WiFi.localIP());
  26.  
  27. Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); //connect to Database
  28. delay(1000);
  29. }
  30.  
  31. void loop() {
  32. String firebaseResult = firebaseGet();
  33. delay(100);
  34. if (firebaseResult=="ON"){
  35. //code to happen if the status is ON
  36. }else{
  37. //code to happen if the status is OFF
  38. }
  39. }
Add Comment
Please, Sign In to add comment