Firebase Integrate With ESP8266

26,564

12

17

Introduction: Firebase Integrate With ESP8266

About: Embedded lover.

Make such
application in which LED can be control from mobile or website from any remote location where internet connectivity is available.

Requirement:

1 ) ESP8266-E12 WiFi module as shown in picture. You can get start and setup it with help of this post.

2) Download and install firebase-arduino-master library in Arduino IDE.

3) Need gmail account for create Firebase project.

Step 1: Create Project on Firebase.

Go to firebase console and create new project

https://console.firebase.google.com/?pli=1

Step 2: Add Host Name to Arduino Sketch

Click on Database now you will see the host name show in image

Copy that host name and past in Arduino code given below at line
#define FIREBASE_HOST "fir-app-example.firebaseio.com"

Step 3: Add Database Secrete Key to Arduino Sketch

Go to Setting>Project Setting>SERVICE ACCOUNTS>DATABASE Secretes.
Copy "Database Secrets" Shown in above image.

Copy and paste Database Secrets at the line in code
#define FIREBASE_AUTH "examplesd2asdasdasdasd2asd3asd2asd2as32das3d2as2da3"

Step 4: Add Router Name and Password

Change line with your WiFi router name and password

#define WIFI_SSID "Wifi Router Name"
#define WIFI_PASSWORD "Router Password"

Step 5: Download Following Code in Arduino

#include
#include

// Set these to run example.

#define FIREBASE_HOST "fir-app-example.firebaseio.com"

#define FIREBASE_AUTH "examplesd2asdasdasdasd2asd3asd2asd2as32das3d2as2da3"

#define WIFI_SSID "Wifi Router Name"

#define WIFI_PASSWORD "Router Password"

#define LED 2

void setup() {

pinMode(LED,OUTPUT);

digitalWrite(LED,0);

Serial.begin(9600);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("connecting");

while (WiFi.status() != WL_CONNECTED) {

Serial.print(".");

delay(500);

}

Serial.println();

Serial.print("connected: ");

Serial.println(WiFi.localIP());

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

Firebase.setInt("LEDStatus",0);

}

void loop() {

if(Firebase.getInt("LEDStatus"))

{

digitalWrite(LED,HIGH);

}

else

{

digitalWrite(LED,LOW);

}

if (Firebase.failed()) // Check for errors {

Serial.print("setting /number failed:");

Serial.println(Firebase.error());

return;

}

delay(1000);

}

Step 6: Restart ESP8266

After reseting ESP8266check serial terminal whether the ESP is get connected with your router and got IP adress.
Goto https://console.firebase.google.com/project/fir-app-9adb8/database/data you can now see the new variable created in database.

Step 7: Change Value of LEDStatus From Database

Double click "LEDStatus" and edit it to 1. instantly (its depends on your internet connection) LED on ESP 8266 module get Turn off.

Step 8: You Can Create Your Own App for Android

If you have knowledge of Android you can create App for control LED from mobile. You need to read Firebase documentation and integration methods.

I created my android app for controlling LED from mobile. As Firebase can be assess from world wide so you have end to end IoT application.

Share

    Recommendations

    • Metalworking Contest

      Metalworking Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Water Contest

      Water Contest

    17 Discussions

    i want to upload the image from arduino SD to firebase storage..

    can any one help me..?

    Hi,

    When I add #include <FirebaseArduino.h> lib then error comes

    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    I follow all above steps.

    1 reply

    yeah bro! same problem fa me ... say me the solution if u found

    0
    None
    AbdulK82

    Question 5 months ago

    i am not getting continue valued using analog A1,2,3,4 PINS do you have any solution

    Check your Firebase AUTH and Firebase HOST. It should be correct to connect to your Firebase Database with no doubt.

    Did you follow the instructions?

    I'm facing the same problem!
    how to solve it. my device is connected properly to wifi.

    it shows setting / number failed error

    pls help me

    Can i use the same procedure with ESP 01 ?Please reply fast

    It shows constructor error

    how can I change with manual switch operation with switch and firebase too

    Hi, good work,

    I have one Wemos D1 Mini Arduino device (with embedded ESP8266 module).

    I want to write to the dataset Firebase that I have taken from the humidity meter.

    I did everything that was said [1] , but there is no change in Firebase.

    I can not read or write data.

    Firebase.set Firebase.get functions not working

    because the library I use on my arduino device supports the http protocol. How can I change the protocol of the database to http?

    My database URL :
    https://arduino-b3aea.firebaseio.com/

    Arduino forum issue I have detected this problem there. [2]

    [1]https://www.instructables.com/id/Firebase-Integrate-With-ESP8266/

    [2]https://forum.arduino.cc/index.php?topic=513379.0

    As per your Steps I followed upto Step 4 . In the Step 5 , I
    just copy the code and paste it in new Sketch File and also I include the
    Firebase library . When I started to compile means it leaves ERROR in the
    Program .Please solve this problem ........

    Following Error was coming in my
    Program

    Arduino: 1.8.3 (Windows 10),
    Board: "Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 512K (64K
    SPIFFS), ck, Disabled, None"

    In file included from
    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:5:0,

    from
    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/DatabaseProtocol.h:5,

    from
    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/SerialTransceiver.h:4,

    from C:\Users\*\Documents\Arduino\sketch_jun20a\sketch_jun20a.ino:7:

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:13:19:
    error: expected ')' before '*' token

    Command(Firebase* fbase) :
    fbase_(fbase) {}

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:20:3:
    error: 'Firebase' does not name a type

    Firebase& fbase() {

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:25:3:
    error: 'Firebase' does not name a type

    Firebase* fbase_;

    ^

    In file included from
    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/DatabaseProtocol.h:5:0,

    from
    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/SerialTransceiver.h:4,

    from
    C:\Users\*\Documents\Arduino\sketch_jun20a\sketch_jun20a.ino:7:

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:14:22:
    error: expected ')' before '*' token

    GetCommand(Firebase* fbase) :
    Command(fbase) {}

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:21:22:
    error: expected ')' before '*' token

    SetCommand(Firebase* fbase) :
    Command(fbase) {}

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:28:25:
    error: expected ')' before '*' token

    RemoveCommand(Firebase* fbase) :
    Command(fbase) {}

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:35:23:
    error: expected ')' before '*' token

    PushCommand(Firebase* fbase) :
    Command(fbase) {}

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:47:27:
    error: type/value mismatch at argument 1 in template parameter list for
    'template<class _Tp, class _Dp> class std::unique_ptr'

    std::unique_ptr<Firebase>
    firebase();

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:47:27:
    error: expected a type, got 'Firebase'

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:47:27:
    error: template argument 2 is invalid

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:50:27:
    error: type/value mismatch at argument 1 in template parameter list for
    'template<class _Tp, class _Dp> class std::unique_ptr'

    std::unique_ptr<Firebase>
    new_firebase_;

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:50:27:
    error: expected a type, got 'Firebase'

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:50:27:
    error: template argument 2 is invalid

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:
    In constructor 'firebase::modem::BeginCommand::BeginCommand()':

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:42:35:
    error: no matching function for call to
    'firebase::modem::Command::Command(std::nullptr_t)'

    BeginCommand() : Command(nullptr)
    {}

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:42:35:
    note: candidates are:

    In file included from C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:5:0,

    from C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/DatabaseProtocol.h:5,

    from C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/SerialTransceiver.h:4,

    from C:\Users\*\Documents\Arduino\sketch_jun20a\sketch_jun20a.ino:7:

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:11:7:
    note: constexpr firebase::modem::Command::Command()

    class Command {

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:11:7:
    note: candidate expects 0 arguments, 1 provided

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:11:7:
    note: constexpr firebase::modem::Command::Command(const
    firebase::modem::Command&)

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:11:7:
    note: no known conversion for argument 1 from 'std::nullptr_t' to 'const
    firebase::modem::Command&'

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:11:7:
    note: constexpr
    firebase::modem::Command::Command(firebase::modem::Command&&)

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/command.h:11:7:
    note: no known conversion for argument 1 from 'std::nullptr_t' to
    'firebase::modem::Command&&'

    In file included from C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/DatabaseProtocol.h:5:0,

    from C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/SerialTransceiver.h:4,

    from C:\Users\*\Documents\Arduino\sketch_jun20a\sketch_jun20a.ino:7:

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:
    At global scope:

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/commands.h:55:25:
    error: expected ')' before '*' token

    StreamCommand(Firebase* fbase) :
    Command(fbase) {}

    ^

    In file included from C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/SerialTransceiver.h:4:0,

    from C:\Users\*\Documents\Arduino\sketch_jun20a\sketch_jun20a.ino:7:

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/DatabaseProtocol.h:16:62:
    error: 'Firebase' is not a type

    std::unique_ptr<Command>
    CreateCommand(const String& text, Firebase* fbase);

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/DatabaseProtocol.h:18:27:
    error: type/value mismatch at argument 1 in template parameter list for
    'template<class _Tp, class _Dp> class std::unique_ptr'

    std::unique_ptr<Firebase>
    fbase_;

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/DatabaseProtocol.h:18:27:
    error: expected a type, got 'Firebase'

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/modem/db/DatabaseProtocol.h:18:27:
    error: template argument 2 is invalid

    In file included from C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/thing/FireThing.h:6:0,

    from C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/Thing.h:1,

    from C:\Users\*\Documents\Arduino\sketch_jun20a\sketch_jun20a.ino:8:

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/thing/Transcriber.h:50:27:
    error: type/value mismatch at argument 1 in template parameter list for
    'template<class _Tp, class _Dp> class std::unique_ptr'

    std::unique_ptr<Firebase>
    fbase_;

    ^

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/thing/Transcriber.h:50:27:
    error: expected a type, got 'Firebase'

    C:\Users\*\Documents\Arduino\libraries\firebase-arduino-master\src/thing/Transcriber.h:50:27:
    error: template argument 2 is invalid

    sketch_jun20a:83: error: expected
    constructor, destructor, or type conversion before '(' token

    delay(1000);

    ^

    sketch_jun20a:85: error: expected
    declaration before '}' token

    }

    ^

    exit status 1

    expected constructor, destructor,
    or type conversion before '(' token

    This report would have more
    information with

    "Show verbose output during
    compilation"

    option enabled in File -> Preferences.

    After adding the zip library in my arduino IDE i cannot find the following code given in the step 5..

    Looks like there's an error with the way the pointer declaration is made in the argument Firebase* at command.h help will be appreciated since I'm not C++ developer. Thanks!

    Compilation error at command.h file at Firebase* any ideas why and how to solve? Thank you!