mobizt / Firebase-ESP32

[DEPRECATED]🔥 Firebase RTDB Arduino Library for ESP32. The complete, fast, secured and reliable Firebase Arduino client library that supports CRUD (create, read, update, delete) and Stream operations.
MIT License
415 stars 118 forks source link

Setting the data only once in the database. #17

Closed Ultra-Instinct-05 closed 5 years ago

Ultra-Instinct-05 commented 5 years ago

Assume I have the following setup :

//This example shows how to read, store and update database using get, set, push and update functions.
//Required HTTPClientESP32Ex library to be installed  https://github.com/mobizt/HTTPClientESP32Ex

#include <WiFi.h>
#include "FirebaseESP32.h"

#define FIREBASE_HOST "YOUR_FIREBASE_PROJECT.firebaseio.com" //Do not include https:// in FIREBASE_HOST
#define FIREBASE_AUTH "YOUR_FIREBASE_DATABASE_SECRET"
#define WIFI_SSID "YOUR_WIFI_AP"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"

//Define Firebase Data object
FirebaseData firebaseData;

void setup()
{

  Serial.begin(115200);
  Serial.println();
  Serial.println();

  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();

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);

  //Quit Firebase and release all resources
  Firebase.end(firebaseData);
}

void loop()
{
  if (Firebase.pushInt(firebaseData, "/test/append", 0)) {
    Serial.println("Success");
  } else {
    Serial.println(firebaseData.errorReason());
  }
}

I am also running a MQTT server on the same ESP32 device and hence the MQTT has to publish a message on the push of a button. Is it possible for me to add the data to the database only once for every push of a button rather than continuously populate the database ?

mobizt commented 5 years ago

Depending on how you use it. The library connect to Firebase through REST API. Withh REST API, client makes http connection with POST, PUT, GET, PATCH and DELETE request to firebase server as response (data at defined node or requested URI) received then it closed connection except for stream that keep the connection alive.

Continuousely make http connection to server is not make sense.