No doubt, MIT app inventor is one of the easiest ways to develop apps for project or hobby. If you want to develop a simple IOT based project, you certainly need a real-time database. Though there are many players in the game but google firebase is best among all. So here is a tutorial on How to use firebase with MIT app inventor or How to integrate firebase with MIT app inventor 2.
- 1 How to use firebase with MIT app inventor 2.
What Is Google Firebase And What Is Google Firebase Used For?
Firebase is primarily used for app development, cloud messaging, real-time database, storage, hosting, social authorization, and analytics.
Firebase is a platform offered by Google which can be used as backend storage. In simple words, we can say that firebase is a cloud-based database. It provides one of the most stable and fastest real-time databases.
Here, in this post, we are going to use Google firebase as a real-time database. First of all, we will see how to integrate firebase with MIT app inventor 2. After that, we will get deep into how to use the app inventor to read data from firebase. We will also see, MIT app inventor logic to update the database using an app.
How to use firebase with MIT app inventor 2.
Integrating firebase with app inventor is straightforward and it can be done in 3 simple steps.
1. Create real-time database
- Navigate to Google Firebase and login using your google account. It will redirect you to Google firebase console.
- Click on new project, enter a project name and cloud firestore location, then hit create project button.
- Search for Develop option in the left panel, then expand Develop and select Database. It will open the firebase database catalog. Scroll down to select real-time database and click on create database button.
- Keep Security rules for Real-time Database in locked mode and enable it.
Now your database is enabled and online. Its time to find out secret database details (URL + KEY) so that you can access it remotely.
Open your database and copy Real-time database URL. Paste the link to firebase database on the notepad.
Click on Project Overview option on the left panel and select project settings. Navigate to Service accounts >> Database secrets >> Secret. Copy the database authentication key and save in a safe location.
3. Integrate firebase with MIT app inventor
- First of all, go to app inventor, click on create apps and login using valid credentials.
- After that, create a new project and give it any desired name.
- Find the “Experimental” option (located in the left palette window) and expand it. Drag and drop “FirebaseDB” in the workspace (viewer window).
- Left click on FirebaseDB1 (at bottom of viewer window) to see properties of the database. In the properties window, paste database URL and database secret key (copied in step 2).
- That’ it, now you are ready to use google firebase with MIT app inventor. Now, let’s dig a little bit deeper in how to read/write data from/to firebase using app inventor.
How To Write Data To Firebase Using MIT App Inventor?
As we say, the best way to learn something is to do it (Do it Lean it), let’s create a simple app which can write data to firebase. At this point, I am assuming that you had already integrated firebase with app inventor. Now we need to add some other components.
- Drag and drop a TextBox and a Button to the workspace. Click on the button and give it a name (let it be “Write Data”).
- After that, click on BLOCKS option located at the top right corner of Windows. This is workspace where we will write our logic. Create logic as shown below.
- Then click on build and save apk file to your PC, transfer file to smartphone and install on it.
Run the app, enter something in the text field and click the button. Your data would be saved to firebase. You can view saved data by visiting Google firebase console.
How To Read Data From Firebase Using MIT App Inventor?
- Drag a label and second button (let it be Read Data).
- Add code blocks as shown below. Save it and run on any android device or android emulator.
After that, go to console and edit value manually or write any value using app. Then press “read data” button and it will fetch and show new data in label.
In this way you can update or fetch data from firebase. You can use it for developing app or any IOT based project. So what are you waiting for? Go and expand your wings of creativity!
Still have any doubt? Check out this awesome video by Tech Mania. And Tech Mania, if you are reading this, A BIG THANKS for making the helpful video 😉
For further reading, you can also check out a demonstration for app using firebase.
Hope you find this tutorial useful. Please feel free for queries. And Best Of Luck for upcoming IOT adventures.