So this Thursday turned out to be a quite a productive day thanks to the unexpected invitation to the IBM Analytics workshop sponsored by my company. Mr. Rajesh M Jeyapaul and Mani Madhukar from IBM India conducted well composed sessions on IBM Watson IoT platform and Analytics platform. The session consisted of two parts, where the 1st part focused on creating your own IoT application using the IBM Watson IoT Platform while the 2nd part was about analyzing data with Data Science Experience (DSX). In this article I’ll be writing about how to get your hands dirty with Watson IoT platform to create your own IoT application and store the data into IBM Cloud.
XaaS consists of several cloud computing models in which IBM Cloud combines the PaaS (Platform as a Service) and IaaS (Infrastructure as a Service) models through a catalog of cloud services to assist in rapid implementation of a wide variety of business applications. With IBM Cloud in the picture, you are relieved off the concerns of making your own heavy investments to run and test your app. From development sandboxes to distributed production environments, IBM Cloud offers all kinds of services, containers and tools you might need. So whether its deployment, security or expansion, none if it is of your concern now!
In this tutorial, let me get you started with the Internet of Things Platform Starter boilerplate which is one of several boiler plates, available in the IBM Cloud dashboard.
1. The Dashboard of Possibilities
Load the IBM Cloud dashboard and create yourself a free account. Once you login to the dashboard, click on the Catalog menu item at the top. You might get the “Lite” filter applied on the search box, which indicates the boiler plates that could be tried for free with no restrictions on the period of usage. Remove the filter to witness the wide variety of projects that could be created without breaking a sweat to setup the environment. From bare metal servers to block chain services, possibilities are countless! Clicking on the boiler plate would provide you with a brief description which is pretty much self explanatory. Once you are done exploring, click on Internet of Things Platform Starter to create our project. This would create you a sample NodeJS application which could be used to collect and store data in the cloud.
Here’s a sneak peek into the architectural diagram in concern.
Credits: Kashyap Ravichandran and Rajesh K Jeyapaul
2. Setting up The Project
Enter a name for your project in the App Name text box and choose a region to deploy your application in. Let me specify the name as mayooran-iot-test. and region to be US South.
NOTE: App Name has to be UNIQUE!
Once you fill these two in, rest of the text box values would be generated for you. So now your form should look something like this.
As you scroll down you could see the technologies involved with this boiler plate. We will be presented with platform consisting of Node JS SDK, Watson IoT Platform (MQ Broker) and Cloudant NoSQL for database. Of course we have chosen the Lite plan here, which is the free plan that lets you play around with the projects and services. Without further ado, click on the Create button. Now you will be redirected to your project page where you could see the state of your environment as shown below.
Once everything is set to go, you would see the state change to started/awake! (Give it some time folks, takes a couple of minutes!) Now visit the dashboard home page and you should your project listed. Below is how mine looks.
Under Cloud Foundry Services, click on the Internet of Things Platform under Service Offering column(mayooran-iot-test-iotf-service in my case). Now you’ll be presented with the Watson IoT platform Service page as shown below. Click on Launch to kick things off!
3. Creating a Device And Fetching Data
Upon clicking Launch on the above image, you’ll be landing on the page shown below.
Click on the highlighted Devices icon to create a new device and connect it to the platform. On this Devices page, click on Device Types from the menu and click on +Add Device Type button as shown below.
On the device type creation form, leave the Type as Device. Enter a Name for the device and a Description if you like and click Next. Just to be sure here’s what I have now.
On the Device Information form you get now, you can leave the information empty and click Done. Upon successful addition you should now see the page shown below. Click on Register Devices.
On the device creation form, specify a Device ID and click Next.
Again you may leave the Device Information form empty as shown below and click Next.
On the Device Security form, specify an Authentication Token which would be used when establishing connection from the device and click Next.
click Done from the device information page as shown below.
You’ll now be directed to the Device Drilldown page where you can check the Device Credentials, Connection Information, Recent Events etc. Make a note of the credentials, as you will need this when connecting your device to the cloud.
4. Generating Data From Your Mobile Device
Now let us use the mobile app Lyfas to generate the pulse data which will be storing in IBM Cloud. If you are not in possession of an Android mobile, use the IoT Sensor Simulator to generate your data. Android users, follow the below steps to capture pulse data from your mobile and stream.
Step I : Open the installed Lyfas application. Enter a unique ID when prompted for (Your mobile number would do).
Step II: Click on the menu, and select Settings.
Step III: Under Blumix Settings specify the credentials you had noted down when we were setting up the device earlier, and click Save. Some other options are using an API key or using a MQTT broker. Below is how it would look with respect to the settings I had specified.
Step IV: Now in order to capture your pulse data, click on Start Pulse from the drop down as shown below.
Step V: Then hold your finger on the flash light to capture your pulse data. Perform this as gentle as possible, to avoid skin burns. Now you should see the data being captured and a graph drawn on the screen.
Step VI: Now click on Stream toggle to start streaming the captured pulse data. This will ensure that the captured data is pushed to the IBM Watson IoT Cloud.
NOTE: If you are unable to see the streaming data, there could be a TLS authentication issue. In order to fix this temporarily, you can set the Security Level to TLS Optional. This could be set by clicking on the Settings icon in the dashboard, and selecting TLS Optional from the drop down menu for Security Level.
Now you if you go back to the IBM Watson IoT platform dashboard and select the device, you could see the Recent Events menu. Under this, you could find the pulse sensor data that was streamed from your mobile device!
If you click on the State tab, you could find the most recent data that was transmitted.
5. Node-RED In Action
Now that we’ve got the data into the cloud, we could play around with the node-red run time we have been provided. Let’s now go back to your bluemix dashboard, and click on the Node-RED url as shown below.
When the page loads, click on Next as shown below.
On the second window, you can disable the security settings (As this a simple demo) as shown below and click Next.
Now click on Finish on the final window to launch the node-red page. Then click go to your Node-RED flow editor as shown below.
Node-RED allows a visual programming approach to build IoT applications using a simple flow based approach. If you are interested in learning the basics of Node-RED, the documentation here provides you with every information you need.
On the flow editor, double click on IBM Iot App In to configure the device from which we will be gathering the input. Fill in the form with the Device Type and Device Id as shown below. You may leave the rest of the details with the default values. and click Done. Now Click the Deploy button at the top of the editor to complete deployment of the flow.
Now when you start the cam pulse again and start streaming data from your mobile app, you will see the live data appearing on the debug tab as shown below.
Now let us store this data in the cloudant database instance we were provided with. Scroll down on the list of nodes available at the left side of the editor and choose cloudant out node from the storage category as shown below.
Drag and drop this node on to the flow editor, and double click on it to start configuring. Service will be automatically loaded for you hence you just need to specify the Database as shown below.
Click on Done and then click Deploy.
Now go back to your dashboard and click on the Cloudant NoSQL DB instance as shown below.
On the Service Details page, click on Launch.
Now you could see the database instance created as below. Publish some data again and you could see the data flow into mydb instance.
Click on the mydb instance, to view the data that has been stored.
Well that’s it folks! You’ve stored your sensor data in a cloudant database instance through a Node-RED editor with minimal connection configurations and did you even bother installing anything or setting up any software? Well that’s what IBM Cloud brings to the picture. All you ever did connect the mobile app that publishes sensor data and just created a flow consisting of two nodes to get into the cloudant database.
I hope that would’ve given you a teaser to the main movie called IBM Cloud and its endless possibilities. Once you have figured out these steps, it shouldn’t take you more than 10-15 minutes! So I’ll wrap up the capabilities of IBM Watson IoT platform and in the next tutorial let’s see how we can use the analytic capabilities of IBM Watson. I’ll leave you here with a teaser for that! 🙂