You can read this and other amazing tutorials on ElectroPeak's official website
In this tutorial, you will learn how to upload and download data to/from a Firebase database with Arduino UNO and ESP8266 module.
Storing data (like sensors data) to a database that can be accessed from anywhere by the internet may be very useful. Firebase makes storing and retrieving data easy.
Firebase is a mobile and web application development platform developed by Firebase, Inc. in 2011, then acquired by Google in 2014. As of October 2018, the Firebase platform has 18 products which are used by 1.5 million apps.
Firebase provides multiple services as following:
First, you should create an account in Firebase. It’s quite easy to create an account; Go to “firebase.google.com”, click on Console, sign in by your Google account, and thenmake a new project. After creating a new project, add a name and enable the test mode. You can add some value manually in the realtime database part. You can get JSON form of your data by adding “.json” at the end of the database URL. Watch the following video for more information:
You can read or transfer data from your database by Arduino and ESP8266. You need a Host name and an Auth key of your firebase project. Then, you should add the Firebase Arduino library and upload the code. If it’s the first time you are using an Arduino board, just follow these steps:
/* #include <ESP8266WiFi.h"> #include <<span class="TextRun Highlight BCX0 SCXW174472232" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="SpellingError BCX0 SCXW174472232">FirebaseArduino.h></span></span> // Set these to run example. #define FIREBASE_HOST "example.firebaseio.com" #define FIREBASE_AUTH "token_or_secret" #define WIFI_SSID "SSID" #define WIFI_PASSWORD "PASSWORD" void setup() { Serial.begin(9600); // connect to wifi. 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); } int n = 0; void loop() { // set value Firebase.setFloat("number", 42.0); // handle error if (Firebase.failed()) { Serial.print("setting /number failed:"); Serial.println(Firebase.error()); return; } delay(1000); // update value Firebase.setFloat("number", 43.0); // handle error if (Firebase.failed()) { Serial.print("setting /number failed:"); Serial.println(Firebase.error()); return; } delay(1000); // get value Serial.print("number: "); Serial.println(Firebase.getFloat("number")); delay(1000); // remove value Firebase.remove("number"); delay(1000); // set string value Firebase.setString("message", "hello world"); // handle error if (Firebase.failed()) { Serial.print("setting /message failed:"); Serial.println(Firebase.error()); return; } delay(1000); // set bool value Firebase.setBool("truth", false); // handle error if (Firebase.failed()) { Serial.print("setting /truth failed:"); Serial.println(Firebase.error()); return; } delay(1000); // append a new value to /logs String name = Firebase.pushInt("logs", n++); // handle error if (Firebase.failed()) { Serial.print("pushing /logs failed:"); Serial.println(Firebase.error()); return; } Serial.print("pushed: /logs/"); Serial.println(name); delay(1000); }
You can read this and other amazing tutorials on ElectroPeak's official website
In this tutorial, you will learn how to upload and download data to/from a Firebase database with Arduino UNO and ESP8266 module.
Storing data (like sensors data) to a database that can be accessed from anywhere by the internet may be very useful. Firebase makes storing and retrieving data easy.
Firebase is a mobile and web application development platform developed by Firebase, Inc. in 2011, then acquired by Google in 2014. As of October 2018, the Firebase platform has 18 products which are used by 1.5 million apps.
Firebase provides multiple services as following:
First, you should create an account in Firebase. It’s quite easy to create an account; Go to “firebase.google.com”, click on Console, sign in by your Google account, and thenmake a new project. After creating a new project, add a name and enable the test mode. You can add some value manually in the realtime database part. You can get JSON form of your data by adding “.json” at the end of the database URL. Watch the following video for more information:
You can read or transfer data from your database by Arduino and ESP8266. You need a Host name and an Auth key of your firebase project. Then, you should add the Firebase Arduino library and upload the code. If it’s the first time you are using an Arduino board, just follow these steps:
/*
#include <ESP8266WiFi.h">
#include <<span class="TextRun Highlight BCX0 SCXW174472232" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="SpellingError BCX0 SCXW174472232">FirebaseArduino.h></span></span>
// Set these to run example.
#define FIREBASE_HOST "example.firebaseio.com"
#define FIREBASE_AUTH "token_or_secret"
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASSWORD"
void setup() {
Serial.begin(9600);
// connect to wifi.
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);
}
int n = 0;
void loop() {
// set value
Firebase.setFloat("number", 42.0);
// handle error
if (Firebase.failed()) {
Serial.print("setting /number failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
// update value
Firebase.setFloat("number", 43.0);
// handle error
if (Firebase.failed()) {
Serial.print("setting /number failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
// get value
Serial.print("number: ");
Serial.println(Firebase.getFloat("number"));
delay(1000);
// remove value
Firebase.remove("number");
delay(1000);
// set string value
Firebase.setString("message", "hello world");
// handle error
if (Firebase.failed()) {
Serial.print("setting /message failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
// set bool value
Firebase.setBool("truth", false);
// handle error
if (Firebase.failed()) {
Serial.print("setting /truth failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
// append a new value to /logs
String name = Firebase.pushInt("logs", n++);
// handle error
if (Firebase.failed()) {
Serial.print("pushing /logs failed:");
Serial.println(Firebase.error());
return;
}
Serial.print("pushed: /logs/");
Serial.println(name);
delay(1000);
}