Skip to content

Instantly share code, notes, and snippets.

@li2hub
Last active December 15, 2018 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li2hub/2a91d1eb739cffc358b21e457cba5142 to your computer and use it in GitHub Desktop.
Save li2hub/2a91d1eb739cffc358b21e457cba5142 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include<FirebaseArduino.h>
const int Ledpin = D0;
#define FIREBASE_HOST "xxxxxxxxxxxxxxxxxx.firebaseio.com" //Your Firebase Project URL goes here without "http:" , "\" and "/"
#define FIREBASE_AUTH "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" //Your Firebase Database Secret goes here
#define WIFI_SSID "xxxxxxxxxx" //your WiFi SSID for which yout NodeMCU connects
#define WIFI_PASSWORD "xxxxxxxxx"//Password of your wifi network
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); //baud rate ,if you want to see the process in the serial monitor ,same baud rate should be set.
pinMode(Ledpin,OUTPUT);
WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status()!=WL_CONNECTED){
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected:");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH);
Firebase.setString("S","0");//the variable in which is used in our Firebase and MIT App Inventor
}
void firebasereconnect()
{
Serial.println("Trying to reconnect");
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
int l;
void loop() {
if (Firebase.failed()) {
Serial.print("setting number failed:");
Serial.println(Firebase.error());
firebasereconnect();
return;
}
l=Firebase.getString("S").toInt();//The value read from the firebase is read in the form of String and is converted into Integer
if(l==1){
digitalWrite(Ledpin,HIGH);
Serial.println("lightOFF");
}
else if(l==0){
digitalWrite(Ledpin,LOW);
Serial.println("lightON");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment