Connect Hardware to Software using Kotlin,Firebase and Nodejs
During my sophomore year, a senior of mine approached me with an issue of connecting hardware(i.e. Arduino) to software by using simple,existing libraries and framework. This would receive data from hardware, store in a database so that either a mobile app or website could fetch and display it, all of it in real-time meaning less latency and more efficiency. So, this post is basically the solution of the above issue, by using
- Kotlin for Android App Development.
- Firebase as our Real-Time Database and
- Node-js for creating RESTful API Development.
So lets begin by first sketching out our architecture upon which our system shall be created.
Note:-I shall not cover the hardware part because that is not our main focus
According to our architecture, if we take an example of an simple sensor whose output needs to be processed real-time in an Mobile App then these are the following steps:-
- First through an hosted Node-js RESTful API, Arduino(or any other hardware with a Wi-Fi module) sends the required data to Firebase real-time database which is then stored.
- Now as we know how easy it really is to connect android to Firebase!!,we can leverage this for displaying or processing the data inside the mobile app.
So now lets create a simple heartbeat display mobile app by following the above architecture norms, also adding features such as,displays the heartbeat(in beats per minute), animation and graph plotting in real-time.
The Java version of the mobile app is already made(below is the rep.)
Lets move a step ahead and make the same android app in KOTLIN!!
First we shall cover the API part. I am assuming you know how to create a new project in Firebase and find the config. keys for the Web. If you dont know I request you first have a clear look of how Firebase works. I am sure you shall find suitable article in Medium.
Moving on, after finding them the following Nodejs code(server.js) for RESTful API:-
remember to host this to any cloud or web hosting service like heroku or digital ocean etc(I would recommend Heroku) so that it can be accessible.
Now its time to make our hands dirty with KOTLIN!!
I shall not explain why is kotlin good blah blah blah… we already have tons of article for that rather after gaining some basic insight lets just code it.
- First comes the view:-
2. My personal favourite(being a lazy programmar) the data class (makes getter-setter so small)
3. MainActivity.kt last but not the least(crux of the app)
Conclusion
we have succeeded in implementing our focused part of model by creating
- RESTful API integerated with cloud database
- Android App using Kotlin for displaying the data.
I hope this article was useful. Please like, share, leave a response regarding anything about this project.
P.S:-This was my first medium article.Hope i haven’t disappoint you.I am a self-learned,passionate programmer who wants to create stuff which have never been heard,seen or thought of. You can see my other projects at https://github.com/S2606, LinkedIn:- https://www.linkedin.com/in/shagun-khemka-b55843118/