Closed epna closed 4 months ago
You have to read the library documentation thoroughly to understand the library concept and usage.
You must remove all delay functions from your code because this is async client library.
Read the documentation is a must.
You can use only one FirebaseApp
and ServiceAuth
for both Messaging
and Realtime Database
to reduce the code complexity.
The FirebaseApp
is the authentication task handler which can be used globally for all Firebase services apps
if those apps support the authentication that provides by FirebaseApp
.
You can use only one FirebaseApp
and ServiceAuth
for both Messaging
and Realtime Database
to reduce the code complexity.
The FirebaseApp
is the authentication task handler which can be used globally for all Firebase services apps
if those apps support the authentication that provide by FirebaseApp
.
Only NTP configTime
waiting delay can be used. Other delays in your code must be removed.
hi,
if i build a sketch of messaging, it works fine if i buidl a sketch of databse (get data); il works fine if i merge the two sketch get data doesn't work
please help Thanks
include
include
include "password.h"
include
void authHandlerBDD(); void authHandlerMess(); void timeStatusCB(uint32_t &ts); void printResult(AsyncResult &aResult); void printError(int code, const String &msg); DefaultNetwork network; // initilize with boolean parameter to enable/disable network reconnection // ServiceAuth is required for Cloud Messaging. ServiceAuth sa_auth(timeStatusCB, FIREBASE_CLIENT_EMAIL, FIREBASE_PROJECT_ID, PRIVATE_KEY, 3000 / expire period in seconds (<= 3600) /); UserAuth user_auth(API_KEY, USER_EMAIL, USER_PASSWORD); FirebaseApp appMess, appBDD;
include
WiFiClientSecure ssl_client;
using AsyncClient = AsyncClientClass; AsyncClient aClient1(ssl_client, getNetwork(network)),aClient2(ssl_client, getNetwork(network)); Messaging messaging; RealtimeDatabase Database; AsyncResult aResult_no_callback_Mess,aResult_no_callback_BDD ; bool taskCompleted = false;
void setup() { Serial.begin(115200); WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}
void loop() { authHandlerMess(); authHandlerBDD(); appMess.loop(); appBDD.loop(); messaging.loop(); Database.loop();
}
void authHandlerMess() { // Blocking authentication handler with timeout unsigned long ms = millis(); while (appMess.isInitialized() && !appMess.ready() && millis() - ms < 120 * 1000) { // This JWT token process required for ServiceAuth and CustomAuth authentications JWT.loop(appMess.getAuth()); printResult(aResult_no_callback_Mess); } }
void authHandlerBDD() { // Blocking authentication handler with timeout unsigned long ms = millis(); while (appBDD.isInitialized() && !appBDD.ready() && millis() - ms < 120 * 1000) { // This JWT token process required for ServiceAuth and CustomAuth authentications JWT.loop(appBDD.getAuth()); printResult(aResult_no_callback_BDD); } }
void timeStatusCB(uint32_t &ts) {
if defined(ESP8266) || defined(ESP32) || defined(CORE_ARDUINO_PICO)
elif __has_include() || __has_include()
endif
}
void printResult(AsyncResult &aResult) { if (aResult.isEvent()) { Firebase.printf("Event task: %s, msg: %s, code: %d\n", aResult.uid().c_str(), aResult.appEvent().message().c_str(), aResult.appEvent().code()); }
}
void printError(int code, const String &msg) { Firebase.printf("Error, msg: %s, code: %d\n", msg.c_str(), code); } void getData2() { Serial.println("Synchronous Get2... "); Database.get(aClient2, "/test/int", aResult_no_callback_BDD); delay(500); } void getData() { Serial.println("Synchronous Get... "); Serial.print("Get int... "); int v1 = Database.get(aClient2, "/test/int");
if (aClient2.lastError().code() == 0)
Serial.println(v1);
else
printError(aClient2.lastError().code(), aClient2.lastError().message());
}