Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TrickSumo/1e7364d8945a69de0df6c1e9920b8d90 to your computer and use it in GitHub Desktop.
Save TrickSumo/1e7364d8945a69de0df6c1e9920b8d90 to your computer and use it in GitHub Desktop.
/*
Created by:- Rishi Tiwari
Website:- TrickSumo.com
Video Tutorial:- https://youtu.be/nLzC0-VaqDs
Libraries used:-
https://github.com/mobizt/Firebase-ESP8266/
*/
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#define FIREBASE_HOST "test.firebaseio.com" //Your Firebase Project URL goes here without "http:" , "\" and "/"
#define FIREBASE_AUTH "83Z6iVjTlxjfhjsgjhwerhwqweZxrTXiy0C9" //Your Firebase Database Secret goes here
#define WIFI_SSID "Wifiname-here" //your WiFi SSID for which yout NodeMCU connects
#define WIFI_PASSWORD "Wifipassword-here" //Password of your wifi network
// Declare the Firebase Data object in the global scope
FirebaseData firebaseData;
// Declare global variable to store value
String val= "example";
void setup() {
Serial.begin(115200); // Select the same baud rate if you want to see the datas on Serial Monitor
Serial.println("Serial communication started\n\n");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP Address is : ");
Serial.println(WiFi.localIP()); //print local IP address
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
Firebase.reconnectWiFi(true);
delay(1000);
}
void loop() {
// Firebase Error Handling And Reading Data From Specified Path ************************************************
if (Firebase.getString(firebaseData, "/data")) { // On successful Read operation, function returns 1
Serial.println(firebaseData.dataType());
val = firebaseData.stringData();
Serial.println(val);
Serial.println("\n Change value at firebase console to see changes here.");
delay(1000);
} else {
Serial.println(firebaseData.errorReason());
}
}
/* NOTE:
* To read value, command is ===> Firebase.getInt(firebaseData, "path"); variable = firebaseData.intData();
*
* Example ===> Firebase.setInt(firebaseData, "/data", val); val = firebaseData.intData();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment