IOT with Firebase is trending now days, as it also known as Server less IOT and many of businesses selling their IOT products with backend as Firebase database. It’s really a good choice as using firebase no need to manage database, authentication, push notifications, you get all under one cloud. Firebase use backend of Google Cloud : Google cloud computing services (GCP).

Problem Statement : 
I am a firebase geek from last 3 years and as per my personal experience IOT with Firebase is one of the best solution that we can ever think, but from last couple of months there is fingerprint issue, with our current FIREBASE ESP8266 library. Due to which we need to change the fingerprint again and again and it’s very annoying as you need to rewrite the code again to ESP8266/NodeMcu and if we don’t rewrite the code to device and we are going to facing ESP8266 Firebase database connection problems.
Solution : 
After analyzing this fingerprint issue, i checked lot of fixes in the repository, but looks like all the issues regarding Firebase ESP8266 library are still open, So it’s time to find a new alternative for firebase library and here i got a very good working library which includes lot of new stuff like steaming, multi-path stream callbacks and also solves our major concern for firebase fingerprint change issue due to which there is no need to rewrite the code to ESP8266 and our firebase database connection problem with ESP8266 resolves. 
New Library Intro and Features:

Firebase Realtime Database Arduino Library for ESP8266

Google’s Firebase Realtime Database Arduino Library for ESP8266 v 2.9.1

This library supports ESP8266 MCU from Espressif. The following are platforms in which libraries are also available.

Tested Devices

  • Wemos D1 Mini
  • NodeMCU
  • ESP-12F
  • LinkNode

Features

  • Supports Read (get), Store (set), Append (push), Patch (update) and Delete Data

  • Supports Primitive data types: Integer, Float, Double, Boolean, String and JSON.

  • Supports BLOB and File Stream Data.

  • Support Read and Write Database Rules.

  • Supports ETag, Priority, Data Limits, Timestamp, Filtering, etc.

  • Supports Stream Event Callbacks

  • Supports Multiple paths Stream (under the same parent node)

  • Supports Data Backup and Restore.

  • Supports Firebase Cloud Messaging.

  • Supports SD and flash memory’s CA certificate file (for Core SDK v2.5.x).

  • Built-in easiest and non-recursive JSON parser and builder.

Setup Guide : 
If you like videos like this consider donating $1, or simply turn off AdBlocker. Either helps me to continue making tutorials.


Code below follows the video to help :

Transcript / Cheat Sheet
  1. Setup Realtime Database Configuration
  2. Install Firebase ESP8266 library.
  3. Navigate to Basic example 
  4. Replace the firebase configs are directed in above video
  5. Burn the code to ESP8266
  6. Analyze the real-time values in Firebase changed by ESP8266.
  7. Enjoy
CODE : 
Code below is explained in above video and used for controlling nodemcu GPIO pins using firebase database/console.

#include <ESP8266WiFi.h>
#include "FirebaseESP8266.h"
#define FIREBASE_HOST "fir-----.firebaseio.com"  //Change to your Firebase RTDB project ID e.g. Your_Project_ID.firebaseio.com
#define FIREBASE_AUTH "emSxQPgquE--------OpiGE7mwbVT2" //Change to your Firebase RTDB secret password
#define WIFI_SSID "k***in"
#define WIFI_PASSWORD "1****1321"
//Define Firebase Data objects
FirebaseData firebaseData1;
FirebaseData firebaseData2;
const int ledPin = 4; //GPIO4 or D2 for LED
const int swPin = 5;  //GPIO5 or D1 for Switch
bool swState = false;
String path = "/Nodes";
String nodeID = "Node2";      //This is this node ID to receive control
String otherNodeID = "Node1"; //This is other node ID to control
void setup()
{
    Serial.begin(115200);
    pinMode(ledPin, OUTPUT);
    pinMode(swPin, INPUT);
    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);
    if (!Firebase.beginStream(firebaseData1, path + "/" + nodeID))
    {
        Serial.println("Could not begin stream");
        Serial.println("REASON: " + firebaseData1.errorReason());
        Serial.println();
    }
}
void loop()
{
    if (!Firebase.readStream(firebaseData1))
    {
        Serial.println();
        Serial.println("Can't read stream data");
        Serial.println("REASON: " + firebaseData1.errorReason());
        Serial.println();
    }
    if (firebaseData1.streamTimeout())
    {
        Serial.println();
        Serial.println("Stream timeout, resume streaming...");
        Serial.println();
    }
    if (firebaseData1.streamAvailable())
    {
        if (firebaseData1.dataType() == "boolean")
        {
            if (firebaseData1.boolData())
                Serial.println("Set " + nodeID + " to High");
            else
                Serial.println("Set " + nodeID + " to Low");
            digitalWrite(ledPin, firebaseData1.boolData());
        }
    }
    if (digitalRead(swPin) != swState)
    {
        bool _swState = swState;
        swState = digitalRead(swPin);
        if (Firebase.setBool(firebaseData2, path + "/" + otherNodeID, swState))
        {
            if (swState)
                Serial.println("Set " + otherNodeID + " to High");
            else
                Serial.println("Set " + otherNodeID + " to Low");
        }
        else
        {
            swState = _swState;
            Serial.println("Could not set " + otherNodeID);
        }
    }
}

Categorized in: