Replies: 2 comments 2 replies
-
There is no StreamData in Firebase ESP Client library but it defined in FrebaseESP8266 and FirebaseESP32 libraries. This doc stated the changes to make when migrate from the old libraries. |
Beta Was this translation helpful? Give feedback.
1 reply
-
This is example for stream with callback. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!!
Thank you so much about your library. It has been very useful to me.
I have been using it to program an ESP32 using Arduino IDE in order to set and get some data in Firebase RTDB. Thay way it works great. :)
However, my issue comes when I try using "Stream" functions in order to subscribe to data changes at specific node in Firebase RTDB with a callback function. Arduino IDE can't compile and pops me the following errors
It looks like the methods where not defined in the class or i am not directing the methods correctly. the library is good installed because as I mentioned before it works for setInt and getInt methods.
I took as basis one of the examples codes and i called Firebase.SetStreamCallback and Firebase.beginStream functions. I also declared the void streamCallback(StreamData data) function at the end.
I appreciate a lot your support.
The general code is:
/**
*/
/** This example will show how to authenticate as a user with Email and password.
*
*/
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <Firebase_ESP_Client.h>
//Provide the token generation process info.
#include <addons/TokenHelper.h>
//Provide the RTDB payload printing info and other helper functions.
#include <addons/RTDBHelper.h>
/* 1. Define the WiFi credentials */
#define WIFI_SSID "WIFI"
#define WIFI_PASSWORD "PASS"
/** 2. Define the API key
*
/
#define API_KEY "********************************"
/* 3. Define the user Email and password that already registerd or added in your project /
#define USER_EMAIL "******@gmail.com"
#define USER_PASSWORD "58555555"
/* 4. If work with RTDB, define the RTDB URL /
#define DATABASE_URL "**************************" //.firebaseio.com or ..firebasedatabase.app
/** 5. Define the database secret (optional)
*/
#define DATABASE_SECRET "DATABASE_SECRET"
/* 6. Define the Firebase Data object */
FirebaseData fbdo;
/* 7. Define the FirebaseAuth data for authentication data */
FirebaseAuth auth;
/* 8. Define the FirebaseConfig data for config data */
FirebaseConfig config;
unsigned long dataMillis = 0;
int count = 0;
void setup()
{
{
//Could not begin stream connection, then print out the error detail
Serial.println(fbdo.errorReason());
}
}
void loop()
{
//Firebase.ready works for authentication management and should be called repeatedly in the loop.
}
void streamCallback(StreamData data)
{
//Print out all information
Serial.println("Stream Data...");
Serial.println(data.streamPath());
Serial.println(data.dataPath());
Serial.println(data.dataType());
//Print out the value
//Stream data can be many types which can be determined from function dataType
if (data.dataTypeEnum() == fb_esp_rtdb_data_type_integer)
Serial.println(data.to());
else if (data.dataTypeEnum() == fb_esp_rtdb_data_type_float)
Serial.println(data.to(), 5);
else if (data.dataTypeEnum() == fb_esp_rtdb_data_type_double)
printf("%.9lf\n", data.to());
else if (data.dataTypeEnum() == fb_esp_rtdb_data_type_boolean)
Serial.println(data.to()? "true" : "false");
else if (data.dataTypeEnum() == fb_esp_rtdb_data_type_string)
Serial.println(data.to());
else if (data.dataTypeEnum() == fb_esp_rtdb_data_type_json)
{
FirebaseJson *json = data.to<FirebaseJson *>();
Serial.println(json->raw());
}
else if (data.dataTypeEnum() == fb_esp_rtdb_data_type_array)
{
FirebaseJsonArray *arr = data.to<FirebaseJsonArray *>();
Serial.println(arr->raw());
}
}
//Global function that notifies when stream connection lost
//The library will resume the stream connection automatically
void streamTimeoutCallback(bool timeout)
{
if(timeout){
//Stream timeout occurred
Serial.println("Stream timeout, resume streaming...");
}
}
Beta Was this translation helpful? Give feedback.
All reactions