Skip to content

Instantly share code, notes, and snippets.

@jibin2706
Created April 7, 2019 18:02
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 jibin2706/832a0c5ad9e6639a3582cbf0a4b39f26 to your computer and use it in GitHub Desktop.
Save jibin2706/832a0c5ad9e6639a3582cbf0a4b39f26 to your computer and use it in GitHub Desktop.
Sample code for using Firebase database with NodeMCU
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Firebase
#define FIREBASE_HOST "yourfirebasedatabase.firebaseio.com"
#define FIREBASE_AUTH "*****"
// Wifi
#define WIFI_SSID "your_wifi_ssid"
#define WIFI_PASSWORD "your_wifi_password"
const int led = D1;
void setup()
{
Serial.begin(115200);
pinMode(led, OUTPUT);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.println("connecting...");
while (WiFi.status() != WL_CONNECTED)
{
Serial.println(".");
delay(3000);
}
Serial.println(WiFi.localIP());
// Setting up connection to firebase
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop()
{
bool isLedOn = Firebase.getBool("/led");
if (isLedOn) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment