Esp8266 Firebase Connection

by Tygo-bear in Circuits > Remote Control

66182 Views, 12 Favorites, 0 Comments

Esp8266 Firebase Connection

download.jpg
esp8266 Firebase connection

To start with this project, You need the following components:

  • esp8266(NodeMcu v3 Lua)
  • google account (firebase)

You can buy a esp8266 from here:

Setting Up Arduino IDE, Install Esp8266 Board:

Knipsel.PNG
Kni2psel.PNG
Kni5psel.PNG
Kn14ipsel.PNG

Install esp8266 Board:

Open Arduino IDE > File > Preferences > additional Boards Manager URLs > "http://arduino.esp8266.com/stable/package_esp8266c... > OK

Tools > Board: > Boards Manager > esp8266 > install

Setting Up Arduino IDE, Install Arduino Json Library:

How to install ArduinoJson

Install Arduino json library:

Install version 5.13.1

Watch install video HERE

Setting Up Arduino IDE, ​Install Firebase Library:

wxcwxcw.PNG
Knsdfsdfipsel.PNG

Install Firebase library:

Download latest stable build HERE > unzip in "Documents\Arduino\libraries"

NOTE, There is a bug in "v0.3 Bi-directional streaming support" > update fingerprint CLICK HERE FOR INFO

Firebase, Create Project:

sfhkjgfd.PNG
bhsdhjkfghsgdsh.PNG

Create Firebase Project:

Go To "https://console.firebase.google.com"

Firebase, Project Rules:

fhhgjsgkjdbsf.PNG

Project rules:

Database(Realtime Database) > rules

{
/* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */ "rules": { ".read": true, ".write": true } }

Firebase, Realtime Database Data:

jkgjsdtrz.PNG

Realtime Database data:

Database(Realtime Database) > Data

Add: "LED1" > " "0" "

Code:

#include <ESP8266WiFi.h>

#include <FirebaseArduino.h>

#define WIFI_SSID "SSID" #define WIFI_PASSWORD "WIFI PASSWORD" #define FIREBASE_HOST "?????????????.firebaseio.com" #define FIREBASE_AUTH "AUTH KEY"

int LED1 = 4;

void setup() { Serial.begin(115200);

pinMode(LED1, OUTPUT);

delay(2000); Serial.println('\n'); wifiConnect();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

delay(10); }

void loop() { Serial.print(Firebase.getString("LED1") + "\n");

analogWrite(LED1, Firebase.getString("LED1").toInt()); delay(10);

if(WiFi.status() != WL_CONNECTED) { wifiConnect(); } delay(10);

}

void wifiConnect() { WiFi.begin(WIFI_SSID, WIFI_PASSWORD); // Connect to the network Serial.print("Connecting to "); Serial.print(WIFI_SSID); Serial.println(" ...");

int teller = 0; while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect delay(1000); Serial.print(++teller); Serial.print(' '); }

Serial.println('\n'); Serial.println("Connection established!"); Serial.print("IP address:\t"); Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer }

Code, Personal Info:

sdgsjfsts.PNG
hutzufgef.PNG

personal info:

SSID > name of your wifi network

WIFI PASSWORD > password of your wifi network

FIREBASE HOST > something like "?????????????.firebaseio.com". You can find it in the "Data" tab of your Realtime Database.

AUTH KEY > Project settings > Service accounts > Database secrets

Esp8266 Drivers:

bgyusqfgdjbskdgs.PNG

Download:

Click HERE > unzip and install

Test the Code:

dufidhkhgd.PNG

Upload code:

use esp8266 module in board manager > click "ESP-12E module".

Open serial monitor and set it to "115200".

And you should get the same data as in your database.