Firebase Integrate With ESP8266
Intro: Firebase Integrate With ESP8266
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
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.
36 Comments
hyu 8 months ago
#include <FirebaseArduino.h>
#define WIFI_SSID "h6taran"
#define WIFI_PASSWORD "85463943402l"
#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
}
error messege 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.
othmanmirizi3 4 years ago
FaizanM5 4 years ago
Antutu 4 years ago
Firebase fingerprint has changed. Actual is B6 F5 80 C8 B1 DA 61 C1 07 9D 80 42 D8 A9 1F AF 9F C8 96 7D (updated to apr-2019). You have to edit the FirebaseHTTPClient.h file and include it in the sketch. Also include FirebaseObject.h and Arduino_JSON.h
Cheers <3
ironman43 4 years ago
Thanks Bro
paynedeath 4 years ago
wilzzonb 4 years ago
Jun KeatL 5 years ago
Remember to include AndroidJson.h library. I get stuck for the whole day just because i did not include this library. For more detail please read this link in detail
https://github.com/firebase/firebase-arduino
Antutu 4 years ago
MohanK117 5 years ago
ismayilov1995 5 years ago
when I used
#include <FirebaseArduino.h>
this library I got this error:
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
MohammedA575 5 years ago
ArnabPaikaray 5 years ago
Download FirebaseArduino library from https://github.com/FirebaseExtended/firebase-arduino.git
mearyc 5 years ago
the two #include is empty
and can i use esp8266-01 in this example ??
XiaomyR 5 years ago
how to change that code
parman josan 6 years ago
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.
MohammedA575 5 years ago
ismayilov1995 5 years ago
I have same problem.
D.SUNDEEP 6 years ago
yeah bro! same problem fa me ... say me the solution if u found
TamilT3 6 years ago