fbpx

ESP8266-Google Firebase

Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. The Firebase Real-time Database uses data synchronization every time data changes, any connected device receives that update within milliseconds.Firebase helps IoT devices to store and read the data in firebase.

For esp8266 we have firebase library to handle the firebase real-time database.Add the following firebase library to Arduino IDE Firebase Arduino library-https://github.com/FirebaseExtended/firebase-arduino.

Firebase Setup

  • Signup firebase with google account.
  • After login Click on go to console menu option :-

In Firebase dashboard add a new project.

Enter the Project name and keep the remaining options as default and accept the terms to create the project

Time to create a realtime database to read and write value in firebase using ESP8266.

In order to allow the esp8266 to communicate with firebase, we need to set security permission rules for firebase.

To establish communication between esp8266 to firebase, Get the Host ID and Secret token of firebase poject.
Get the Firebase HOST ID.

Get the Firebase Secrate Token.

It time to create a field in firebase to hold the data:

  • Enter a field name and value for the field and save it

Firebase real-time database which holds the ESP data, ESP value can be read or write from esp8266.

Please make sure in firebase rules read and write set as true to allow device to access the firebase realtime database.

Code to Set and Get the value from ESP8266.

Program

#include "FirebaseArduino.h"
#include<ESP8266WiFi.h>
#define FIREBASE_HOST "esp8266-7b70e.firebaseio.com"
#define FIREBASE_AUTH "Vq9RZVcEF7nLDMiYLhk7vDI8X6sEWLKXHfmJEax1"
#define wifi "GSK"
#define password "12345678"
void setup()
{
Serial.begin(115200);
delay(10);
WiFi.begin(wifi,password);
Serial.print("connecting to");
Serial.println(wifi);
while (WiFi.status()!=WL_CONNECTED)
{
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
/* To Get Value from Firebase */
void loop()
{
int a=Firebase.getString("ESP");
Serial.println("ESP:");
Serial.print(a);
delay(5000);
}


/* To Set Value to Firebase */
void loop()
{
Firebase.SetString("ESP","1"); 
delay(5000);
} 

Leave a Reply

Your email address will not be published. Required fields are marked *