Esp8266 Firebase Connection

64K1222

Intro: 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:

STEP 1: Setting Up Arduino IDE, Install Esp8266 Board:

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

STEP 2: Setting Up Arduino IDE, Install Arduino Json Library:


Install Arduino json library:

Install version 5.13.1

Watch install video HERE

STEP 3: Setting Up Arduino IDE, ​Install Firebase Library:

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

STEP 4: Firebase, Create Project:

Create Firebase Project:

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

STEP 5: Firebase, Project Rules:

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 } }

STEP 6: Firebase, Realtime Database Data:

Realtime Database data:

Database(Realtime Database) > Data

Add: "LED1" > " "0" "

STEP 7: 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 }

STEP 8: Code, Personal Info:

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

STEP 9: Esp8266 Drivers:

Download:

Click HERE > unzip and install

STEP 10: Test the Code:

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.

12 Comments

can anyone help me

Arduino: 1.8.19 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\Firebase.cpp: In member function 'int FirebaseRequest::sendRequest(const string&, const string&, char*, const string&, const string&)':
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\Firebase.cpp:76:1: error: no return statement in function returning non-void [-Werror=return-type]
76 | }
| ^
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\Firebase.cpp: In member function 'void FirebaseStream::startStreaming(const string&, const string&, const string&)':
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\Firebase.cpp:89:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
89 | analyzeError("STREAM", status, path_with_auth);
| ^~~~~~~~
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseArduino.cpp: In member function 'String FirebaseArduino::push(const String&, const ArduinoJson::JsonVariant&)':
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseArduino.cpp:65:54: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
65 | int status = req_.get()->sendRequest(host_, auth_, "POST", path.c_str(), buf);
| ^~~~~~
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseArduino.cpp: In member function 'void FirebaseArduino::set(const String&, const ArduinoJson::JsonVariant&)':
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseArduino.cpp:94:41: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
94 | req_.get()->sendRequest(host_, auth_, "PUT", path.c_str(), buf);
| ^~~~~
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseArduino.cpp: In member function 'void FirebaseArduino::getRequest(const String&)':
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseArduino.cpp:101:41: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
101 | req_.get()->sendRequest(host_, auth_, "GET", path.c_str());
| ^~~~~
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseArduino.cpp: In member function 'virtual void FirebaseArduino::remove(const String&)':
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseArduino.cpp:147:41: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
147 | req_.get()->sendRequest(host_, auth_, "DELETE", path.c_str());
| ^~~~~~~~
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp: In member function 'virtual void FirebaseHttpClientEsp8266::begin(const string&)':
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp:47:50: error: no matching function for call to 'begin(const char*, const char [60])'
47 | http_.begin(url.c_str(), kFirebaseFingerprint);
| ^
In file included from C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp:9:
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:166:10: note: candidate: 'bool HTTPClient::begin(String, uint16_t, String)' (near match)
166 | bool begin(String host, uint16_t port, String uri = "/") __attribute__ ((error("obsolete API, use ::begin(WiFiClient, host, port, uri)")));
| ^~~~~
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:166:10: note: conversion of argument 2 would be ill-formed:
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp:47:30: error: invalid conversion from 'const char*' to 'uint16_t' {aka 'short unsigned int'} [-fpermissive]
47 | http_.begin(url.c_str(), kFirebaseFingerprint);
| ^~~~~~~~~~~~~~~~~~~~
| |
| const char*
In file included from C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp:9:
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:167:10: note: candidate: 'bool HTTPClient::begin(String, const uint8_t*)' (near match)
167 | bool begin(String url, const uint8_t httpsFingerprint[20]) __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
| ^~~~~
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:167:10: note: conversion of argument 2 would be ill-formed:
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp:47:30: error: invalid conversion from 'const char*' to 'const uint8_t*' {aka 'const unsigned char*'} [-fpermissive]
47 | http_.begin(url.c_str(), kFirebaseFingerprint);
| ^~~~~~~~~~~~~~~~~~~~
| |
| const char*
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp: In member function 'virtual void FirebaseHttpClientEsp8266::begin(const string&, const string&)':
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp:51:60: error: invalid conversion from 'const char*' to 'const uint8_t*' {aka 'const unsigned char*'} [-fpermissive]
51 | http_.begin(host.c_str(), kFirebasePort, path.c_str(), kFirebaseFingerprint);
| ^~~~~~~~~~~~~~~~~~~~
| |
| const char*
In file included from C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\firebase-arduino-0.3\src\FirebaseHttpClient_Esp8266.cpp:9:
C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:168:70: note: initializing argument 4 of 'bool HTTPClient::begin(String, uint16_t, String, const uint8_t*)'
168 | bool begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20]) __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
cc1plus.exe: some warnings being treated as errors
Multiple libraries were found for "ESP8266HTTPClient.h"
Used: C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\ESP8266HTTPClient
Not used: C:\Users\ERSHITHVARAN\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266HTTPClient
Multiple libraries were found for "ESP8266WiFi.h"
Used: C:\Users\ERSHITHVARAN\Documents\Arduino\libraries\ESP8266WiFi
Not used: C:\Users\ERSHITHVARAN\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266WiFi
exit status 1
Error compiling for board NodeMCU 0.9 (ESP-12 Module).
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Hello sir. May I know how to store data from arduino to firebase under certain tag value? For example under tag 1 in firebase there will be several data eg:temp, humidity. And under tag 2 there will be also several data and so on.
add your tag before values. Ex: "tag_1/value_1", "tag_1/value_2"
sir i am geting error, when i was verify the code

Arduino: 1.8.10 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
In file included from C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/Firebase.h:30:0,
from C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/FirebaseArduino.h:22,
from C:\Users\Mahidhar B\Desktop\firebaseexample\firebaseexample.ino:3:
C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/FirebaseObject.h:109:11: error: StaticJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
std::shared_ptr<StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>> buffer_;
^
In file included from C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/FirebaseArduino.h:22:0,
from C:\Users\Mahidhar B\Desktop\firebaseexample\firebaseexample.ino:3:
C:\Users\Mahidhar B\Documents\Arduino\libraries\firebase-arduino-0.3\src/Firebase.h:86:11: error: StaticJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
std::shared_ptr<StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>> buffer_;
^
Multiple libraries were found for "ESP8266WiFi.h"
Used: C:\Users\Mahidhar
Multiple libraries were found for "FirebaseArduino.h"
Used: C:\Users\Mahidhar
Multiple libraries were found for "ArduinoJson.h"
Used: C:\Users\Mahidhar
Multiple libraries were found for "ESP8266HTTPClient.h"
Used: C:\Users\Mahidhar
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Try changing the line
int LED1 = 4;
into
int LED1 = D2;
And connect the LED to D2 after uploading the code.
open the arduino ide...without connecting the esp8266 go to tools-ports...note the ports available there...then connect your esp8266 repeat the same procedure...u should see a new port appearing in the ports section...select that port and upload the code...
If this doesn't work u may have a faulty esp8266
open the arduino ide...without connecting the esp8266 go to tools-ports...note the ports available there...then connect your esp8266 repeat the same procedure...u should see a new port appearing in the ports section...select that port and upload the code.
Sir, I am getting this error

esptool.py v2.6
2.6
esptool.py v2.6
Serial port COM8
Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
File "C:\Users\lax63\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py", line 25, in <module>
esptool.main(fakeargs)
File "C:/Users/lax63/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 2653, in main
esp.connect(args.before)
File "C:/Users/lax63/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 468, in connect
raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
_
please help me.

before uploading the code to the esp8266...connect it with the computer...select the appropriate COM port and open the serial monitor set the serial monitor's baud rate to 74800..And hold the Flash button on your esp8266 holding the flash button press the reset button on the esp8266 itself...u should see some lines ending with(1,6) or something similar to this when u press reset button holding the flash button...aftr this step immediately upload your code...it will be uploaded...
you have a problem in esp8266 it's not connect to pc try to check the port