paint-brush
Connect Hardware to Software using Kotlin + Firebase + Nodejsby@shagun.khemka60
580 reads
580 reads

Connect Hardware to Software using Kotlin + Firebase + Nodejs

by Shagun KhemkaMay 29th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

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 <a href="https://hackernoon.com/tagged/framework" target="_blank">framework</a>. This would receive data from hardware, store in a <a href="https://hackernoon.com/tagged/database" target="_blank">database</a> 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

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Connect Hardware to Software using  Kotlin + Firebase + Nodejs
Shagun Khemka HackerNoon profile picture

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

  1. Kotlin for Android App Development.
  2. Firebase as our Real-Time Database and
  3. 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

Architecture for our System

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:-

  1. 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.
  2. 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.)


S2606/HeartBeat_HeartBeat - 💚 An Android app which on giving value of Beats per Minute(BPM) would show hearbeating animation as per…_github.com

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.

  1. 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)

We did it!!

Conclusion

we have succeeded in implementing our focused part of model by creating

  1. RESTful API integerated with cloud database
  2. 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/