18 #include "addons/RTDBHelper.h"
19 #include "addons/TokenHelper.h"
21 void FireLogger::print_error()
23 Serial.printf(
"Error:\ncode: %d\nmsg: ", fbdo_.errorCode());
24 Serial.printf(
"HTTP code: %d\n", fbdo_.httpCode());
26 "Firebase http connected: %s\n", fbdo_.httpConnected() ?
"true" :
"false");
27 Serial.println(fbdo_.errorReason());
37 const char * fire_url,
const char * fire_token,
const char * email,
40 while (WiFi.status() != WL_CONNECTED) {
41 Serial.println(
"WiFi not connected ...");
44 Serial.print(
"WiFi connected at IP: ");
45 Serial.println(WiFi.localIP());
46 Serial.println(
"Signing up to Firebase");
48 config_.database_url = fire_url;
49 config_.api_key = fire_token;
50 auth_.user.email = email;
51 auth_.user.password = pass;
53 fbdo_.setResponseSize(4096);
56 config_.token_status_callback =
59 config_.max_token_generation_retry = 5;
61 Firebase.begin(&config_, &auth_);
63 Serial.println(
"Getting User ID");
64 while ((auth_.token.uid) ==
"") {
68 Serial.println(
"Got User ID");
69 path_prefix_ += auth_.token.uid.c_str();
73 MB_String FireLogger::full_path(
const char * path)
75 MB_String temp = path_prefix_.c_str();
81 if (!Firebase.RTDB.setInt(&fbdo_, full_path(path), value)) {
88 if (!Firebase.RTDB.setDouble(&fbdo_, full_path(path), value)) {
95 if (!Firebase.RTDB.setString(&fbdo_, full_path(path), value)) {
102 if (!Firebase.RTDB.setBool(&fbdo_, full_path(path), value)) {
109 if (!Firebase.RTDB.pushInt(&fbdo_, full_path(path), timestamp)) {
118 if (Firebase.isTokenExpired()) {
119 Firebase.refreshToken(&config_);
120 Serial.println(
"Refreshed token");
bool is_connected()
Get http server connection status.
void begin(const char *fire_url, const char *fire_token, const char *email, const char *pass)
initialise and authorise system to use Firebase RTDB (real time database) make sure wifi is initialis...
void set_float(const char *path, double value)
Set a float value.
bool is_ready()
Check if authenticated.
void set_int(const char *path, int64_t value)
Set an integer value.
void set_bool(const char *path, bool value)
Set a bool value.
bool is_keep_alive()
Get TCP keepalive status.
bool check_and_refresh_token()
refresh token if expired
void set_string(const char *path, const char *value)
Set a string value.
void push_time(const char *path, time_t timestamp)
Push a timestamp into a list to a relative path, useful to log times like when initialisation was com...