I'm using Firebase Arduino Client Library for ESP8266 and ESP32 v.2.3.7 and the ESP board manager v.3.0.1
Can I ask you if you can help me putting this code (I use an ESP01) into this one:
Thx in advance
#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 "TIM-29846851"
#define WIFI_PASSWORD "***"
/* 2. Define the API Key */
#define API_KEY "***"
/* 3. Define the RTDB URL */
#define DATABASE_URL "***" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
/* 4. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL "***"
#define USER_PASSWORD "***"
//Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
int count = 0;
String values;
void setup()
{
Serial.begin(9600);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
//Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
//Serial.print(".");
delay(300);
}
/*.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);*/
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign the user sign in credentials */
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
//Or use legacy authenticate method
//config.database_url = DATABASE_URL;
//config.signer.tokens.legacy_token = "<database secret>";
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
timeClient.begin();
}
void loop()
{
if (Firebase.ready() && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0))
{
bool Sr = false;
while (Serial.available())
{
//get sensor data from serial put in sensor_data
values = Serial.readString();
Sr = true;
}
delay(1000);
if (Sr == true)
{
//values=sensor_data;
//get comma indexes from values variable
int fristCommaIndex = values.indexOf(',');
int secondCommaIndex = values.indexOf(',', fristCommaIndex + 1);
int thirdCommaIndex = values.indexOf(',', secondCommaIndex + 1);
int fourthCommaIndex = values.indexOf(',', thirdCommaIndex + 1);
int fifthCommaIndex = values.indexOf(',', fourthCommaIndex + 1);
Firebase.RTDB.setString(&fbdo, "/test/real/temp", values.substring(0, fristCommaIndex));
Firebase.RTDB.setString(&fbdo, "/test/real/hum", values.substring(fristCommaIndex + 1, secondCommaIndex));
Firebase.RTDB.setString(&fbdo, "/test/real/pres", values.substring(secondCommaIndex + 1, thirdCommaIndex));
Firebase.RTDB.setString(&fbdo, "/test/real/alt", values.substring(thirdCommaIndex + 1, fourthCommaIndex));
Firebase.RTDB.setString(&fbdo, "/test/real/lum", values.substring(fourthCommaIndex + 1));
Firebase.RTDB.setTimestamp(&fbdo, "/test/real/timestamp");
delay(10);
if (count == 31)
{
FirebaseJson json;
json.add("temp", values.substring(0, fristCommaIndex));
json.add("hum", values.substring(fristCommaIndex + 1, secondCommaIndex));
json.add("pres", values.substring(secondCommaIndex + 1, thirdCommaIndex));
json.add("alt", values.substring(thirdCommaIndex + 1, fourthCommaIndex));
json.add("lum", values.substring(fourthCommaIndex + 1));
// Space to provide EPOCH TIME
json.add("timestamp", epochTime);
Firebase.RTDB.pushJSON(&fbdo, "/test/data", &json);
Firebase.RTDB.updateNode(&fbdo, String("/test/data/" + fbdo.pushName()).c_str(), &json);
count = 0;
}
count++;
}
}
}