lab - building an internet of things applicationfiles.meetup.com/15337342/lab - iot [v2].pdflab :...

19
Lab - Building an Internet of Things Application Hands-On Lab

Upload: others

Post on 03-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab - Building an Internet of Things Application Hands-On Lab

Page 2: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Table of contents

1. Creating a Bluemix Application .................................................................................................................. 3

2. Create and add an Internet of Things Service ........................................................................................... 4

2.Wire the connected device’s data flow with IBM Node-RED ............................................................. 10

Page 3: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 3 of 19

Lab : Building an Internet of Things Application

Lab Objectives: We will take a web application that simulates the android heart monitoring application and connect it to the

cloud environment on IBM BlueMix. As part of this lab you will:

1. Build your Internet of Things application

2.Make the connection from the mobile application simulator so that it can push the ECG data to the IoT foundation service

3.Visually wire the devices and data path using Node Red

4.Setup Cloudant NoSQL database as a landing zone for the ECG data

1. Creating a Bluemix Application In this section you'll create an Bluemix application Service instance that will be used throughout the rest of the labs

1. In your browser go to the Bluemix URL http://bluemix.net and login if necessary

2.

Make sure you're in the Dashboard tab (if not click on the Dashboard link at the to

p of the page to

take you there)

3. Scroll down to the Applications section and click on CREATE AN APP

4. For the template choose Web

5. As a starter we will choose Browse Boilerplates and click Browse Boilerplates

Page 4: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 4 of 19

6.We will select the boiler plate Internet Of the Things

7.Choose a name and click create

Your application should restart, wait for a few minutes.

2. Create and add an Internet of Things Service This application will now have some other services added to it.

In this section you will start to bind and configure some services to your IoT application. We will start with adding and creating a Internet of Things service.

1.From your Internet of Things Foundation application page click on the Add a Service button

Page 5: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 5 of 19

2. This will bring up the catalog of services. Scroll to the bottom and select the Internet of Things service

icon. This service provides a simple but powerful application access to connected devices and data.

3. The Internet of Things service screen will appear and as you did for the boilerplate application complete the information in the dialog on the right side of the screen. Once again you need only complete the service name filed but add your initials or company name to make the service name unique

Page 6: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 6 of 19

4. Click on the Create button when done BlueMix will ask you to confirm that the application will restaged (restarted), click on the Yes button in the pop up dialog to confirm and wait a short while for BlueMix to restart your IoT application. Once this is complete you will notice that you have your new service listed and your App Health should be running.

5. The next step is to configure the Internet of Things service you just created and initialize it with the

necessary information of the device we wish to connect. To begin click on the Internet of Things

service and then on the Launch dashboard button that appears on the next screen.

Page 7: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 7 of 19

6. Click Devices, now your browser should now be showing the following page

Currently, you have no devices connected or registered with the service so that is what we will do now.

7.Click on the Add Device link on the left side and in the following screen complete the information to

name and identify your S5 device simulator

A.Select Create a device type from the Device Type drop down selection.

B.Add in a name of your choice

C.Add a device id of your choice

D.Click on the Continue button

NOTE: Please copy data created in this section by copying and pasting the info to a file. This info is very

important for the next section when we configure the BDA Heart Monitor application simulator

Page 8: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 8 of 19

Now you should see a screen very similar to the one below

.

8.AT THIS POINT IT IS VERY IMPORTANT that you write down, or copy and paste into a text editor, the

details highlighted above. When you have done this click on the Done button and your device connection

will be created

9.You have now successfully created the connection for your S5 device. The remainder of this section of concentrates on running the web app that emulates the S5 by sending out the same information as the BDA Heart Monitor application. You will run the simulator with the connection information that we have just defined so that the two services become connected and can communicate.

10.Open your browser and go to the URL http://ibm.biz/bdaecgsim

11.The BDA Heart Monitor mobile application simulator will launch - we will now configure the BDA Heart Monitor simulator with the connection information defined in the IoT service creation stages above.

Page 9: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 9 of 19

12.Click on the button labeled Settings

13.You will now go through each of the options and add the information defined during the IoT service connection creation steps above. Hopefully you noted them down or have them in a text editor! The first step is that you fill in all the values

14. For this step you will be able to cut and paste from data you saved earlier in this lab

15. Click on Save to save the values entered into the dialog

16. Next click on the Connect button and look at the status messages – you should have connected

your instance of the simulator successfully to the IBM IoT Foundation

That completes this section of the exercise. To recap you now have a mobile android device configured to run an application consuming streaming ECG data from a heart monitoring device which, itself, is connected to an Internet of Things application running in an IBM BlueMix cloud environment The next stage is to configure what we do with the date once it arrives in the cloud. For this exercise you will configure the IoT BlueMix application to receive the ECG and push it into a Cloudant NoSQL database which

Page 10: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 10 of 19

2.Wire the connected device’s data flow with IBM Node-RED At present we have a device simulator which can connect to an IoT application but we now need to switch our attention back to the IBM BlueMix environment and create the functionality to process the ECG data. To drive this you will wire together devices and services visually using the IBM Node-RED application. IBM Node-RED provides a browser-based UI for creating flows of events and deploying them to its light-weight runtime. With built in node.js, it can be run at the edge of the network or in the cloud. The node package manager (npm) ecosystem can be used to easily extend the palette of nodes available, enabling connections to new devices and services. Node-RED has been developed as an open-source project on GitHub, under the Apache 2 license.

1.Begin by returning to your application dashboard in IBM BlueMix and click on the link next to the Routes label as shown below. This will open a new tab taking you to the IBM Node-RED application.

2.Click on the button at the bottom of the screen as highlighted below and the Node-RED visual environment will open.

Page 11: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 11 of 19

3.The left side of the screen shows you a list of all the different services, devices and processes that you can use to wire your IoT application together. You will create a flow receiving data from the connect S5 device and push that data into a Cloudant NoSQL database.

Page 12: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 12 of 19

First, clear the canvas by selecting all nodes and press the delete key on your keyboard. This will clear your canvas.

5.Now you can begin to wire your device and services together. Drag onto the canvas an ibmiot node from the input section on the left side.

6.Double click the node and complete the configuration as shown below. This tells node red the information it requires about your device and where the data will be streaming from. Note:.Make sure the values of Device Type and Device Id are the same values you used when you created the device in the IoT Foundation initially and when you connected using the simulator.

Page 13: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 13 of 19

7.Next, scroll down on the left side to the storage nodes and ensure that you select the correct Cloudant node as shown below. The one you need is the last one in the storage section which is used to store the ECG data as it comes into your IoT application.

Page 14: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 14 of 19

8.Double click on the Cloudant node and configure it as shown below. Note that the Cloudant instance, created by the IoT boilerplate application in BlueMix, is populated automatically in the Service drop down box. You need only click on the drop down box and select the service. Click OK when completed.

9. The next node is a simple one and that is to add a debug node from the output section. This

simply allows you to visualize the contents of the incoming message data from your connected

device. Select the debug node from the output section and drag it onto your canvas. Note that there

is no configuration of the debug node necessary

Page 15: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 15 of 19

10 Wire all of the nodes together as shown below and you are nearly complete. Do this by clicking

and holding on the connector element of each node and dragging the line to the corresponding

connector element on the other node.

15,The final stage here is to deploy your Node-Red application to your BlueMix application. Do this by clicking on the red Deploy button on the top right of the browser window.

Page 16: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 16 of 19

16.Finally you will test your connected device to ensure that it is communicating and sending data to your newly created IoT application.

17.In Node-RED select the debug tab on the right side so that we can see a live feed of the ECG message data coming from your connected device.

18.Return now to your BDA Heart Monitor simulator app, and click Run simulation. The simulator will generate 30 heart beats once per second or so and send it to the IoT Foundation MQTT broker which will route it to your app. After 30 beats the simulator will automatically disconnect .

Page 17: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 17 of 19

19.Switch to the Node-RED interface in the browser and you should see the ECG message data as a live feed within the debug tab.

If you do not see the data feed then please recheck that you have entered the Settings data correctly into IoT input node . The Run simulator button will not become active until you’ve successfully connected to the IBM IoT Foundation MQTT broker .so if no data arrives in your Node Red flow it’s most likely the input node, After checking values connect the simulator and try again . If you still do not see the live message feed in Node-RED then ask your friendly instructor.

Page 18: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 18 of 19

20 .You can check that the data is being pushed into the Cloudant NoSQL database which we are using as our landing zone. To do this return to your BlueMix dashboard for the IoT application and click on the Cloudant tile. Note: the Cloudant database was created by default when you created the IoT application using the boilerplate at the beginning of this exercise. You specified the name of the Cloudant database during the Node-RED steps and this database is automatically created at runtime if it doesn’t already exist

21. Click Launch

Page 19: Lab - Building an Internet of Things Applicationfiles.meetup.com/15337342/Lab - IOT [v2].pdfLab : Building an Internet of Things Application Page 6 of 19 4. Click on the Create button

Lab : Building an Internet of Things Application

Page 19 of 19

22. Notice that your ecg database has a size and a number of docs. These docs are the JSON

messages sent by the BDA Heart Monitor application simulator, arriving through your Node-RED application paths into your Cloudant landing zone database.

22. Click on the name of the database to see and be able to query the documents stored. Congratulations, this completes Lab. Congratulations, this completes Lab! You have now created an Internet of Things application capturing ECG streaming data