So im making some code for this but, the serial monitor only show the result is 0 ... Did i do something wrong ?
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS D2
#define SENSOR D1
#include <Arduino.h>
#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"
// Insert your network credentials
#define WIFI_SSID "Redmi"
#define WIFI_PASSWORD "12345678"
// Insert Firebase project API Key
#define API_KEY "AIzaSyCjT64d_OhuRVTLyXbdU-N7By1-jtQiPiM"
// Insert RTDB URLefine the RTDB URL */
#define DATABASE_URL "https://sensoresp-1fcec-default-rtdb.firebaseio.com/"
//Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
//unsigned long sendDataPrevMillis = 0;
//int count = 0;
bool signupOK = false;
void setup(){
pinMode(SENSOR, INPUT_PULLUP);
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;
/* Sign up */
if (Firebase.signUp(&config, &auth, "", "")){
Serial.println("ok");
signupOK = true;
}
else{
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
}
void loop(){
long currentMillis = 0 ;
long previousMillis = 0 ;
int interval = 1000 ;
boolean ledState = LOW ;
float calibrationFactor = 4.5 ;
volatile byte pulseCount = 0 ;
byte pulse1Sec = 0 ;
float flowRate = 0 ;
float flowMilliLitres = 0 ;
float flowLitres = 0 ;
float totalLitres = 0 ;
float totalMilliLitres = 0 ;
// Parameter Sensor Suhu DS18B20.
float tempC = 0 ;
if (Firebase.ready() && signupOK ) {
if (Firebase.RTDB.setFloat(&fbdo, "sensor/debit" , flowMilliLitres)){
Serial.print ("debit :");
Serial.println (flowMilliLitres);
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
if (Firebase.RTDB.setFloat(&fbdo, "sensor/total" , totalMilliLitres)){
Serial.print ("total :");
Serial.println (totalMilliLitres);
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
if (Firebase.RTDB.setFloat(&fbdo, "sensor/suhu" , tempC)){
Serial.print ("suhu :");
Serial.println (tempC);
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
}
Serial.println("______________________________");
}