Last active
October 28, 2023 10:46
-
-
Save TrickSumo/ae215a3b81e3e07a62e9689a9d8795a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
int val=0; | |
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.getInt(firebaseData, "/data")) { // On successful Read operation, function returns 1 | |
if (firebaseData.dataType() == "int") { // print read data if it is integer | |
val = firebaseData.intData(); | |
Serial.println(val); | |
Serial.println("\n Change value at firebase console to see changes here."); | |
delay(10000); | |
} | |
} 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
Hello, I need to get the tag of the node from the user using the Serial monitor in my project. But in the Firebase.getString() function, if I get the tag as a string input and concatenate it with the bucket address string and then input it, it does not retrieve the node's data. However, if I manually input the full address as a string, it is able to retrieve the data. For example,
If the user wants to access the data in the node with the tag "test", which is stored in the "users" bucket, the serial input is given as the string 'test' and it's stored in the variable 'x'. if I write: Firebase.getString(firebaseData, "/users/"+x), it returns 0. But if I write: Firebase.getString(firebaseData, "/users/test"), this returns 1.
What can I do to fix this?