Uploading the serially received data through a peripheral to Firebase using Odinub

What is Firebase?

Firebase from Google offers two types of cloud-based client-accessible database solutions for mobile apps that support realtime data syncing — Realtime Database and Cloud Firestore. FireBase Real-Time DB is JSON based NO SQL DB, meant for mobile apps, regional, and used typically to store and sync data between users/devices in realtime / extremely low latency. While the Realtime Database is just a giant JSON tree, Cloud Firestore is a little more structured. All your data consists of documents (which are key-value stores) and collections (which are collections of documents).

Cloud Firestore will be able to scale better than the Realtime Database. It's important to note that your queries scale to the size of your result set, not your data set.

 

Step 0:

Set up the WiFi for Odinub board. To know how, click here.

Step 1:

The first step here is to create a firebase console by which is shown here .

Also run the following command to install all the necessary firebase libraries:

pip install --upgrade firebase-admin

Also you'll need to connect your peripheral device serially to the Odinub board for this program to run and to know how, click here. Here, you can connect your peripheral device instead of another Odinub!

Step 2:

You’ll need to download the JSON file of the database to give the access to write in the database. '.JSON'

 file works as the administrative key which has all the necessary details to update firebase.

 From Project settings select Users and Permissions and select service accounts and generate the JSON file by pressing the generate New Private Key. The file will be downloaded into your PC.

 

Step 3:

Store the .JSON file in Odinub and placing the file in the same directory where the code is or give the path to the file where it is in the code. For this I have uploaded the file on github.io and wrote the command to fetch and store it on the Odinub. Here the link will be the link for your repository in which the file is been uploaded.

git clone <your link for the file>

 

Step 4:

Create a .py file with certain filename with the command:

sudo nano <filename>.py

 

Step 5:

Creating the collection in the firebase :

To create the collection when you have the cloud firestore then go to database and tap on the Start Collection and give the collection name test and leave the document ID to autogenerate and delete the field details if they are present and you will find the test collection generated with a random document name when you will click on the save.

 

Step 6:

Writing the code to upload the data onto the database. Diving into the code we can see the following line in the code:

 test_ref=db.collection(test).document().set(data)

This command uploads the data received into the test collection in the database and creates a random document name and stores the value into the field with server timestamp which keeps the record of what time the data was uploaded to the database. Here test is the name of the collection which is to be created first and value is the field of the document in which the value entered is going to be stored.

The data fed here to Odinub is through serial communication and the data is read by the command:

data = ser.read(400)    // Here 400 is the number of data bytes which will be received at a time.

 

Step 7:

Run the script with the following command:

python <filename>.py

 

Hence, we've got the serial data cloud connected.

 

Code :
Code Title :
Code Language :
Python
0 Commenting Overall Comment