Uploaded by lin ray

SAIOT2X-ExercisesGuide-book

advertisement
V11.3
cover
Front cover
Course Exercises Guide
IoT Cloud Developer 2020
Course code SAIOT ERC 2.0
Islam Abd Alla
Karim E El-Bawab
Karen Medhat Fahmy
Mohamed Abdel Hafeez
Norhan Khaled
May 2020 edition
Notices
This information was developed for products and services offered in the US.
IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative
for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not
intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or
service that does not infringe any IBM intellectual property right may be used instead. However, it is the user's responsibility to evaluate
and verify the operation of any non-IBM product, program, or service.
IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this
document does not grant you any license to these patents. You can send license inquiries, in writing, to:
IBM Director of Licensing
IBM Corporation
North Castle Drive, MD-NC119
Armonk, NY 10504-1785
United States of America
INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some jurisdictions do not allow disclaimer
of express or implied warranties in certain transactions, therefore, this statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein;
these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s)
and/or the program(s) described in this publication at any time without notice.
Any references in this information to non-IBM websites are provided for convenience only and do not in any manner serve as an
endorsement of those websites. The materials at those websites are not part of the materials for this IBM product and use of those
websites is at your own risk.
IBM may use or distribute any of the information you provide in any way it believes appropriate without incurring any obligation to you.
Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other
publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other
claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those
products.
This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible,
the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to
actual people or business enterprises is entirely coincidental.
Trademarks
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many
jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM
trademarks is available on the web at “Copyright and trademark information” at www.ibm.com/legal/copytrade.shtml.
© Copyright International Business Machines Corporation 2019, 2020.
This document may not be reproduced in whole or in part without the prior written permission of IBM.
US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
V11.3
Contents
TOC
Contents
Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Exercises description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi
Exercise 1. Designing an IoT Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
Part 1: Choosing IoT devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Part 2: Specifying the IoT devices network topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Part 3: Explaining how data is managed and used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Part 4: Identifying the types of analytics that can be applied on the collected data to deliver better
business value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1-2
1-2
1-2
1-2
Exercise 2. Creating your first IoT application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
Part 1:
Part 2:
Part 3:
Part 4:
Part 5:
Part 6:
Setting up your IBM Cloud account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Logging in to IBM Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
Creating and deploying a Node-RED application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Creating the IBM Watson IoT service and connecting it to the Node-RED application . . . 2-17
Accessing the Node-RED editor for the first time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
Checking the memory allocated to your application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Exercise 3. Creating an application to monitor room temperature and humidity . . . . . . . . . . . . 3-1
Part 1: Configuring devices on Watson IoT Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Part 2: Connecting the device to the simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
Exercise 4. Extending IoT application functions by using Node-RED . . . . . . . . . . . . . . . . . . . . . 4-1
Part 1: Creating a Watson Assistant service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Part 2: Creating the conversation flow in the Watson Assistant service . . . . . . . . . . . . . . . . . . . . . 4-6
Part 3: Configuring your device to be used in Node-RED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23
Part 4: Creating a Text to Speech service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25
Part 5: Connecting Watson Assistant to the Node-RED application . . . . . . . . . . . . . . . . . . . . . . . 4-27
Part 6: Integrating your IoT device, Watson Assistant, and Text to Speech service in your Node-RED
flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Exercise 5. Monitoring server CPU usage and reporting statistics . . . . . . . . . . . . . . . . . . . . . . . 5-1
Part 1: Preparing the environment on your local workstation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Part 2: Setting up a simple CPU usage monitor flow on Node-RED . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Part 3: Configuring devices on Watson IoT Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
Part 4: Configuring Node-RED on IBM Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22
Part 5: Connecting the Node-RED application on cloud and the Node-RED application on a local
workstation through Watson IoT Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-28
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device
(optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1
Part 1: Setting up the Raspberry Pi device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Part 2: Installing and configuring Node.js and Node-RED on the Raspberry Pi device . . . . . . . . . . 5-4
Part 3: Setting up a simple CPU usage monitor flow on Node-RED . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Part 4: Configuring devices on Watson IoT Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12
Part 5: Configuring Node-RED on IBM Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21
Part 6: Connecting the Node-RED application on cloud and the Node-RED application on the Raspberry
Pi device through Watson IoT Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
iii
V11.3
Contents
TOC
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition . . . . . . . . . . . . . . 6-1
Part 1:
Part 2:
Part 3:
Part 4:
Part 5:
Part 6:
Opening a Node-RED application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
Creating a Node-RED flow to capture and store images . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5
Creating a Watson Visual Recognition service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13
Classifying people and storing images in a Cloudant database . . . . . . . . . . . . . . . . . . . . . 6-16
Viewing a report of the classified images in the Cloudant DB dashboard . . . . . . . . . . . . . 6-32
(Optional) Classifying people with Visual Recognition in Watson Studio . . . . . . . . . . . . . . 6-33
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial . . . . . . . . . . . . . . . . . . 7-1
Part 1:
Part 2:
Part 3:
Part 4:
Part 5:
Part 6:
Creating a Watson IoT Platform application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
Adding a car as a device to Watson IoT Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
Creating a Node-RED flow to simulate car telematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
Configuring the Cloudant Geospatial index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16
Building a Node-RED flow to handle geofencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22
Cleaning up the environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-28
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
iv
V11.3
Trademarks
TMK
Trademarks
The reader should recognize that the following terms, which appear in the content of this training
document, are official trademarks of IBM or other companies:
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business
Machines Corp., registered in many jurisdictions worldwide.
The following are trademarks of International Business Machines Corporation, registered in many
jurisdictions worldwide:
Cloudant®
IBM Watson IoT™
Watson IoT™
FileNet®
IBM Watson®
Watson™
IBM Cloud™
Power®
Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.
Windows is a trademark of Microsoft Corporation in the United States, other countries, or both.
Other product and service names might be trademarks of IBM or other companies.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
v
V11.3
Exercises description
pref
Exercises description
This course includes the following exercises:
• Exercise 1. Designing an IoT solution
In this exercise, students design an IoT solution by specifying IoT components that are
necessary to build a facility management system. Students discover how Watson IoT Platform
can help transform traditional facility management systems.
• Exercise 2. Creating your first IoT application
This exercise shows how you can set up an environment on IBM Cloud to deploy your first IoT
application by using some of the services that are provided by IBM Cloud.
• Exercise 3. Creating an application to monitor room temperature and humidity
In this exercise, you create an IoT system by using IBM Watson IoT Platform. The purpose of
the system is to monitor the temperature and humidity of a facility and optimize the use of air
conditioning. You use the Watson IoT Platform device simulator to simulate the devices that
send temperature and humidity values through the internet to Watson IoT Platform. Finally, you
visualize the data that is sent by the devices in real time by using the dashboard.
• Exercise 4. Extending IoT application functions by using Node-RED
In this exercise, you connect a Node-RED flow to the Watson Assistant and Watson Text to
Speech services. You also connect the flow to the temperature sensor on Internet of Things
Platform. You create a Watson Assistant service that is used in natural disasters to seek help.
You create the flow for victims to request help. Through Node-RED, you connect Watson
Assistant to an IoT device to measure temperature to send an input to the assistant when the
temperature reaches a predefined value. The response from the assistant is converted to
speech by the Text to Speech service.
• Exercise 5. Monitoring server CPU usage and reporting statistics
In this exercise, you implement an IoT use case about monitoring server CPU usage in a server
room. You use your local workstation as a server by installing Node-RED on your PC or
notebook. Your system reports CPU usage to a cloud application through the Watson IoT
Platform.
• Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi
device (optional exercise)
In this exercise, you implement an IoT use case about monitoring server CPU usage in a server
room. You use a Raspberry Pi device as a server by installing Node-RED on it. Your system
reports CPU usage to a cloud application through the Watson IoT Platform. The Raspberry Pi
device provides the opportunity to extend the capabilities of your monitoring system by
measuring the room temperature, humidity, and other conditions by connecting the Raspberry
Pi device with the corresponding sensor.
• Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
In this exercise, you learn about the Watson Visual Recognition service, and how to integrate it
with IoT applications by using Node-RED.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
vi
V11.3
Exercises description
pref
• Exercise 7. Creating your first IoT application
In this exercise, you learn about geofencing, which is one of the common use cases of IoT. This
exercise demonstrates how to configure geofencing in IBM Cloudant, and how to build a
Node-RED flow that detects when a car reaches certain points.
In the exercise instructions, you can check off the line before each step as you complete it to track
your progress.
Most exercises include required sections, which should always be completed. It might be
necessary to complete these sections before you can start later exercises. If you have sufficient
time and want an extra challenge, some exercises might also include optional sections that you can
complete.
Information
Students in this course use an IBM Cloud Lite account to perform the exercises. This account will
never expire, therefore students can continue working on the optional exercises after the class.
Hint
Before performing the exercises, check the status of the services in the IBM Cloud Status page at
https://cloud.ibm.com/status?selected=status.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
vii
V11.2
Exercise 1. Designing an IoT Solution
EXempty
Exercise 1. Designing an IoT Solution
Estimated time
01:00
Overview
In this exercise, students design a complete Internet of Things (IoT) solution by using IBM Watson
IoT Platform.
Objectives
After completing this exercise, you should be able to:
• Select the IoT sensors that best match the IoT overall solution.
• Identify the best possible ways to connect an IoT device to Watson IoT Platform.
• Explain how the data that is sent from an IoT device can be managed and used by Watson IoT
Platform.
Introduction
In this exercise, students must design (specify) the IoT components that are necessary to build a
facility management system. Students discover how Watson IoT Platform can help transform
traditional facility management systems.
Requirements
Only paper and pen.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
1-1
V11.2
Exercise 1. Designing an IoT Solution
EXempty
Exercise instructions
In this exercise, you complete the following tasks:
__ 1.
Choose the IoT devices that you need to build the facility management system.
__ 2.
Specify the IoT devices network topology.
__ 3.
Explain how the data is managed and used.
__ 4.
Identify the type of analytics that can be applied on the collected data to deliver better
business value.
Part 1: Choosing IoT devices
Answer to the following questions help you choose the IoT device that you use in your solution:
__ 1.
What is the overall expected value that your solution provides?
__ 2.
What are the constraints that might affect the device choice? For example, are there any
power consumption constraints? Are there networking issues like unavailability of wireless
signals?
__ 3.
How frequently must the device send the data to the platform to provide effective
measurements for proper functioning?
Part 2: Specifying the IoT devices network topology
In this part, specify how the devices are connected to the internet:
__ 1.
Are you going to connect the device directly to the platform by using, for example, a mobile
network? Or do you need to connect devices to a gateway so that devices can be
connected to the platform?
__ 2.
What communication protocols are you planning to use, for example, Bluetooth Low Energy
or WiFi?
Part 3: Explaining how data is managed and used
In this part, describe how data is stored and updated:
__ 1.
How is the data stored in the platform and how frequently is it updated?
Part 4: Identifying the types of analytics that can be applied on the
collected data to deliver better business value
In this part, identify the types of analytics that can be applied on the collected data. Consider applying Streaming Analytics, predictive analytics, or any other type of analytics that you think it can
deliver business value from your solution.
__ 1.
How can you use the collected data to deliver better business value?
End of exercise
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
1-2
V11.2
Exercise 1. Designing an IoT Solution
EXempty
Exercise review and wrap-up
This exercise provided a closer look at designing the main components that are required for an IoT
solution. You discovered how AI APIs can help transform traditional IT solutions.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
1-3
V11.2
Exercise 2. Creating your first IoT application
EXempty
Exercise 2. Creating your first IoT
application
Estimated time
01:00
Overview
This exercise shows how you can set up an environment on IBM Cloud to deploy your first IoT
application by using some of the services that are provided by IBM Cloud.
Objectives
After completing this exercise, you should be able to:
• Set up an IBM Cloud Lite account.
• Log in to IBM Cloud from a browser.
• Describe the IoT related services in the IBM Cloud catalog.
• Deploy Watson IoT service and connect it with a Node-RED application.
• Set up Node-RED configurations to start developing on the Node-RED flow editor.
Introduction
With IBM Cloud, you can develop an IoT application easily by focusing on the development of the
business case rather than worrying about the infrastructure and the deployment process. This
exercise shows how to create your IBM Cloud Lite account and how to use the services that are
provided in IBM Cloud to create and deploy your IoT applications.
Requirements
This exercise requires access to the internet and the IBM Cloud console from your workstation by
using a modern web browser with the latest version.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-1
V11.2
Exercise 2. Creating your first IoT application
EXempty
Exercise instructions
In this exercise, you complete the following tasks:
__ 1.
Set up your IBM Cloud account.
__ 2.
Log in to IBM Cloud.
__ 3.
Create and deploy a Node-RED application.
__ 4.
Create the IBM Watson IoT service and connect it to the Node-RED application.
__ 5.
Access the Node-RED editor for the first time.
__ 6.
Check the memory that is allocated to your application.
Part 1: Setting up your IBM Cloud account
In this part, you register for an IBM Cloud Lite account by providing your email address. Your email
address acts as your user name for IBM Cloud, and you must provide your first and last name,
demographic data, and a valid password. Then, you receive a verification email to confirm that your
email account is valid and active.
Attention
If you already have a valid account, you can skip Part 1 of this exercise and go to Part 2.
Complete the following steps:
__ 1.
Open the IBM Cloud console by going to https://cloud.ibm.com in a web browser. The
window that is shown in the following figure opens.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-2
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 2.
Click Create an IBM Cloud account. A window with a form opens, as shown in the
following figure.
__ 3.
Complete the form by typing your personal information. You must use a valid email address
for this course because IBM Cloud sends you an email to verify your account.
__ 4.
Click Create Account. You receive a message similar to the one that is shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-3
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 5.
Check your email at the account that you used to sign up for IBM Cloud. You receive an
email similar to the one that is shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-4
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 6.
Click Confirm Account. You are redirected to a page that confirms that you activated your
IBM Cloud account successfully, as shown in the following figure.
__ 7.
Close this browser or browser tab.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-5
V11.2
Exercise 2. Creating your first IoT application
EXempty
Note
There is a Log in button in the success page of the registration. However, it is better to close this
page and to log in normally by using the direct link of IBM Cloud to get the experience of the normal
login scenario.
Part 2: Logging in to IBM Cloud
To log in to IBM Cloud, complete the following steps:
__ 1.
Open the IBM Cloud dashboard (https://cloud.ibm.com) in a web browser.
__ 2.
On the IBM Cloud home page, keep IBMid selected and enter your registered email in the
first field. Then, enter your password. Note that your IBMid is the email that you used to
register for IBM Cloud.
Note
If your company uses the single-sign on service, you provide only your IBMid and then you are
redirected to the single-sign on page to log in with your company credentials.
__ 3.
Click Log in. You are redirected to a page that shows you information about IBM Cloud
privacy policies, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-6
V11.2
Exercise 2. Creating your first IoT application
EXempty
Note
The IBM Cloud privacy policies page opens only in the first login after your registration. After it is
accepted, it does not appear again.
Troubleshooting
Sometimes in the first login after the registration, the IBM Cloud privacy policies page does not
appear, and instead the following figure appears. In that case, refresh your browser and you are
redirected to your dashboard.
__ 4.
Read the information that is shown in the following figure and then click Proceed.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-7
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 5.
You are redirected to the IBM Cloud dashboard page, as shown in the following figure.
Part 3: Creating and deploying a Node-RED application
The IBM Cloud catalog lists components and services that help you build your application on the
cloud. In this part, you create a Node-RED starter kit application and then deploy it on the cloud.
You use Node-RED to build useful IoT applications with IBM Watson IoT services.
To create the Node-RED application starter kit, complete the following steps:
__ 1.
On the IBM Cloud dashboard, click Create resource in the upper right, as shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-8
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 2.
In the search field type Node-RED.
__ 3.
Select Node-RED App as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-9
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 4.
Select the Create tab.
__ 5.
Keep the default values and click Create.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-10
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 6.
Wait until the application is created.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-11
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 7.
Click Deploy your app to start the deployment of the Node-RED application.
__ 8.
Select the deployment target IBM Cloud Foundry.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-12
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 9.
As part of the deployment process, you must create an API key. Click New + as shown in
the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-13
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 10. Click OK in the window that opens to create the API key.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-14
V11.2
Exercise 2. Creating your first IoT application
EXempty
Note
If you want to use the API key that is generated with a new service in the future, check the box next
to Save this key in a secret store for reuse. For this exercise, it is not required to store the key.
Important
The API key is important to manage and track the access to the application. In this case, the API
key allows anyone who has the key to have full access to the application by default, but this access
can be modified. For more information about API keys in IBM Cloud, see
https://cloud.ibm.com/docs/iam?topic=iam-manapikey
__ 11. Increase Memory allocation per instance from 128 MB to 256 MB by moving the slider to
the left as shown in the following figure.
Attention
For a Lite account, the available memory that can be allocated to all the applications is 256 MB.
Above this limit, applications fail to deploy.
__ 12. Keep the default values for the other fields. Take note of the selected region to deploy the
app in as it is required later to connect to the Watson IoT service.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-15
V11.2
Exercise 2. Creating your first IoT application
EXempty
Note
There are two regions in the form. The first region refers to the region where the Node-RED
application is deployed in; you must take note of this region. The second region refers to the region
in which the toolchain service is created when your application is created to help you deploy your
application easily.
__ 13. Click Create in the upper right.
__ 14. Click the Navigation Menu (burger icon) on the upper left and then select Resource List.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-16
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 15. The application takes some time to deploy. After the application is deployed and started
successfully, you can see your application under the Cloud Foundry apps section with
status Started as shown in the following figure. At first, the list might be empty, but it will
show up after a few minutes.
Note
Notice the following items when you create a Node-RED application:
• A Cloudant service is required to store the Node-RED data.
• A Continuous Delivery service is created to deploy the application through a CI/CD pipeline.
• A Git repository is created. You can check the source code of the Node-RED application from
the repository link. You can also modify the source code and redeploy if it is required.
Part 4: Creating the IBM Watson IoT service and connecting it to the
Node-RED application
IBM Watson IoT Platform is a fully managed, cloud-hosted service that makes it simple to derive
value from Internet of Things (IoT) devices. It has built-in web dashboards that you can use to
monitor your IoT data and analyze it in real time.
In this part, you create the Internet of Things Platform service. Then, you restage and connect the
service with the Node-RED application that is already deployed.
__ 1.
Open the IBM Cloud catalog page from the top menu and type Internet of Things in the
search field.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-17
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 2.
Select Internet of Things Platform.
__ 3.
Keep the default values and click Create.
__ 4.
After the Watson IoT service is created, you can see the Manage page as shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-18
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 5.
To connect the Watson IoT service with the Node-RED application that was deployed
previously complete the following steps:
__ a.
Click Connections in the left navigation menu.
__ b.
Click Create connection +.
__ c.
Select your Node-RED application.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-19
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ d.
Connect to the Node-RED application by clicking Next.
__ e.
In the window that opens, click Create.
__ f.
Wait until you are prompted to restage the app and then click Restage.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-20
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 6.
Open the Node-RED application from the Resource List.
__ 7.
Wait for the application to restart. The app status is either This app is awake (as shown in
the following figure) or Running.
Note
The running status for applications in a Lite account is indicated by This app is awake as shown in
the figure. The application will be stopped after 10 days of inactivity.
For Pay-As-You-Go and Subscription accounts, the application running status is indicated by
Running as shown in the following figure.
Part 5: Accessing the Node-RED editor for the first time
In this part, you set the credentials for your Node-RED application and access the Node-RED
editor.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-21
V11.2
Exercise 2. Creating your first IoT application
EXempty
Complete the following steps:
__ 1.
From the Node-RED application Overview page, click Visit App URL next to the
application name and status to open the application.
__ 2.
In the “Welcome to your new Node-RED instance on IBM Cloud” window of the wizard, click
Next, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-22
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 3.
For this exercise, there is no need to secure your Node-RED editor. However, you can do so
by providing a username and password. Select the option Not recommended. Allow
anyone to access the editor and make changes and select the box Tick this box to
confirm you want your editor to be insecure. Then, click Next, as shown in the following
figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-23
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 4.
In the next page, click Next and then Finish.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-24
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 5.
You are redirected to the Node-RED welcome window, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-25
V11.2
Exercise 2. Creating your first IoT application
EXempty
__ 6.
Click Go to your Node-RED flow editor. You are redirected to the Node-RED flow editor,
as shown in the following figure.
Your Node-RED flow editor is ready now. You can explore your dashboard. Close the web
browser or tab.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-26
V11.2
Exercise 2. Creating your first IoT application
EXempty
Part 6: Checking the memory allocated to your application
In this part, you view the amount of memory that is allocated to your application. Complete the
following steps:
__ 1.
Open IBM Cloud dashboard (https://cloud.ibm.com) in a web browser.
__ 2.
Expand Cloud Foundry apps under the Resource summary, as shown in the following
figure.
__ 3.
Open your application under Cloud Foundry apps, as shown in the following figure.
__ 4.
On the application overview page, you can check the resources that are allocated to your
application. There is one instance and 256 MB of memory that is allocated to your as shown
in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-27
V11.2
Exercise 2. Creating your first IoT application
EXempty
Note
Depending on your account type, you might be allotted a different amount of RAM or other
resources in IBM Cloud. Your window might differ from the example.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-28
V11.2
Exercise 2. Creating your first IoT application
EXempty
Exercise review and wrap-up
In this exercise, you registered for an IBM Cloud Lite account. You explored the IBM Cloud
dashboard and catalog by signing in with your new account. Then, you created your first IoT
application by creating a Node-RED application and a Watson IoT Platform service. Then, you
connected the service to the Node-RED application.
After you created the application, you learned how to access the Node-RED flow editor. Finally,
you explored the application dashboard.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
2-29
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
Exercise 3. Creating an application to
monitor room temperature
and humidity
Estimated time
00:45
Overview
In this exercise, you create an IoT system by using IBM Watson IoT Platform. The purpose of the
system is to monitor the temperature and humidity of a facility and optimize the use of air
conditioning. You use the Watson IoT Platform device simulator to simulate the devices that send
temperature and humidity values through the internet to Watson IoT Platform. Finally, you visualize
the data that is sent by the devices in real time by using the dashboard.
Objectives
After completing this exercise, you should be able to:
• Add a device to Watson IoT Platform and retrieve the credentials.
• Use the Watson IoT Platform simulator to monitor temperature and humidity.
• Chart the data on Watson IoT Platform.
Introduction
Watson IoT Platform provides the building blocks for any IoT system, device registry, authentication
and authorization for devices and applications, and data visualization.
You can have an end to end functioning system without writing a single line of code for the back
end. In this solution, you are concerned only with device connectivity.
Prerequisites
Complete exercise Creating your first IoT application.
Requirements
You must have an active IBM Cloud account.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-1
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
Exercise instructions
In this exercise, you complete the following tasks:
__ 1.
Configure devices on Watson IoT Platform.
__ 2.
Connect the device to the simulator.
Part 1: Configuring devices on Watson IoT Platform
This part shows how to access Watson IoT Platform over IBM Cloud, add a device and configure it,
and generate an API key and authentication token that are required to link real devices or external
simulators to IBM Watson IoT Platform.
Complete the following steps:
__ 1.
Log in to IBM Cloud . From the Navigation Menu (hamburger button), select Resource List
as shown in the following figure.
__ 2.
Expand the Services section and double-click the Internet of Things Platform service.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-2
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 3.
Click Launch to get started with Watson IoT Platform.
__ 4.
The Browse Devices window opens, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-3
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 5.
Select the Device Types tab and click Add Device Type in the upper right, as shown in the
following figure.
__ 6.
Specify the device type, name, and description as follows:
Type: Select Device.
Name: Enter RoomSensors
Description: This device monitors room temperature and humidity
Click Next.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-4
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
Note
In this step, you create the device type, which is not the device itself. The device type name is used
to identify the device type uniquely. For example, in a home automation system, a building can have
multiple air-conditioners that send the same data points, temperature, and humidity. In this case,
you define Device Type as air-conditioner and have multiple devices of this type, for example, 1st
Floor air-conditioner and 2nd Floor air-conditioner. In this exercise, the device type name is
RoomSensors.
Information
In certain situations, if the device cannot directly connect to the internet, it is aggregated first
through a gateway. A gateway device can be built to retrieve and send data to applications in your
Watson IoT Platform by using the MQTT or HTTP messaging protocol. In this exercise, you use the
default device type (you do not need a gateway).
__ 7.
It is optional to add more information about the device type, such as Serial Number, Model,
Hardware Version, and more. Click Finish as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-5
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 8.
Click Register Devices to register a device of type RoomSensors.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-6
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
Note
The default way to add a device is to click Devices from the left navigation bar and then click Add
Device + as shown in the following figure.
__ 9.
Select the device type that you previously created and enter a unique device ID as follows:
- Device Type: RoomSensors
- Device ID: TempreatureAndHumidity1
Click Next.
__ 10. At the Device Information window, use the default values and click Next.
Optional
Optionally, you can modify the default device information and enter more information about the
device for identification purposes.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-7
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 11. At the Security window, use the default option (Auto-generated authentication token) and
click Next.
Optional
Optionally, you can provide your own authentication token for this device. Do not use this option for
this exercise.
__ 12. At the Summary window, click Finish.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-8
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 13. A window with the device credentials opens, as shown in the following figure.
Important
You must save the authentication token because after the window that is shown in the following
figure closes, you cannot access the authentication token again. If you lose the authentication
token, you must reregister the device to generate a new authentication token.
__ 14. Copy the Authentication Token that is show in the credentials page, and save it in a safe
place for later use.
__ 15. Click the back arrow on the upper left to return to the Watson IoT Platform dashboard.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-9
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
Part 2:
Connecting the device to the simulator
To test Watson IoT Platform, you can use a simulated device that acts like a real device. This
simulator generates programmed and customized values for temperature and humidity, then it
sends them through the internet to Watson IoT Platform. However, the device must be configured to
authenticate itself to Watson IoT Platform.
Complete the following steps:
__ 1.
Get the Organization ID of your IBM Watson IoT Platform instance from the upper right of
the window, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-10
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 2.
Access the Watson IoT Sensor Simulator by opening a new tab in the browser and entering
the URL http://watson-iot-sensor-simulator.mybluemix.net/. A dialog box opens, as shown
in the following figure. Complete it as follows:
- Organization ID: Your organization ID from step 1
- Device Type: RoomSensors
- Device ID: TempreatureAndHumidity1
- Device Token: The Authentication Token from Part 1
Click Save changes.
__ 3.
The simulator sends its data to the device that was created in Part 1, as shown in the
following figures. To check the temperature, the humidity, and the object temperature
values, go between the pages by swiping left and right.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-11
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-12
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 4.
To view the status and the data that is collected, go to the IBM Watson IoT Platform Boards
menu that can be accessed from the upper-right icon, as shown in the following figure.
__ 5.
Click Usage Overview, which includes three cards, to see the status and the data of your
simulated device.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-13
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
Note
There is a board that is called Risk and Security Overview, which is provided by default after you
create the service from IBM Cloud. Usage Overview is created automatically after the device and
the device type creation.
__ 6.
In the Usage Overview page, click + Add New Card, as shown in the following figure.
__ 7.
There are different types of cards for data visualization, usage, risk management, and more
as shown in the following figure. Click Line chart.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-14
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 8.
Select the device that you want to monitor by clicking the radio button to its left. In this case,
it is TempreatureAndHumidity1. Click Next, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-15
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 9.
Click + Connect new data set.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-16
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 10. Complete the form as follows:
- Event: iotsensor
- Property: temperature
- Name: temperature
- Type: Number
- Unit: C
- Min: 0
- Max: 100
Click Next.
__ 11. In Create Line chart Card, select XL for better visualization, and click Next.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-17
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 12. In the next window, accept the defaults and click Submit.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-18
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 13. Go back to the simulated device (Watson IoT Sensor Simulator) and keep changing the
temperature values by using the up and down arrows, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-19
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
__ 14. Monitor the line chart in IBM Watson IoT Platform under the Usage Overview card to
validate the changes in the values, as shown in the following figure. As shown in the
following chart, changes in the temperature up and down using the arrows are reflected in
the chart
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-20
V11.2
Exercise 3. Creating an application to monitor room temperature and humidity
EXempty
Exercise review and wrap-up
Now, you can identify the difference between device type and device and how to configure both.
Also, you can connect a device to Watson IoT Platform and visualize the data in real time with a
pre-built UI dashboard.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
3-21
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Exercise 4. Extending IoT application
functions by using
Node-RED
Estimated time
1:30 hour
Overview
In this exercise, you connect a Node-RED flow to the Watson Assistant and Watson Text to Speech
services. You also connect the flow to a temperature sensor on Internet of Things Platform.
Objectives
After completing this exercise, you should be able to:
• Connect your Watson Assistant service to a Node-RED application.
• Configure the Watson Assistant node in a Node-RED flow.
• Deploy the Node-RED flow and send user input to the assistant through the node-RED flow.
• Create a Watson Text to Speech Service and configure it to be used in the Node-RED flow.
• Create and configure a device to measure the temperature in Internet of Things Platform.
• Connect the device to Watson Assistant through the Node-Red flow to send an input to the
assistant when the temperature rises.
Introduction
In this exercise, you create a Watson Assistant service that is used in natural disasters to seek
help. You create the flow for victims to request help. Through Node-RED, you connect Watson
Assistant to an IoT device to measure temperature to send an input to the assistant when the
temperature reaches a predefined value. The response from the assistant is converted to speech
by the Text to Speech service. The flow is shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-1
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Prerequisites
Complete exercise Creating your first IoT application.
Requirements
IBM Cloud Lite account.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-2
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Exercise instructions
In this exercise, you complete the following tasks:
__ 1.
Create a Watson Assistant service.
__ 2.
Create a Watson conversation flow in the Watson Assistant service.
__ 3.
Configure your device to be used in the Node-RED application
__ 4.
Create a Text to Speech service
__ 5.
Connect Watson Assistant to Node-RED application
__ 6.
Integrate your IoT device, Watson Assistant, and Text to Speech service in Node-Red
Part 1: Creating a Watson Assistant service
In this part, you create a Watson Assistant service on your IBM Cloud account.
Complete the following steps:
__ 1.
Log in to your IBM Cloud account.
__ 2.
Click Catalog, as shown in the following figure.
__ 3.
In the search field, type Watson Assistant as shown in the following figure to find the
Watson Assistant service.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-3
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 4.
Click Watson Assistant.
__ 5.
The Watson Assistant service home page opens. Click Create as shown in the following
figure to create the Watson Assistant service instance.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-4
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Note
If you receive a warning notification and you are not able to create the service as shown in the
following figure, go to your dashboard by clicking the Navigation Menu to the left of IBM Cloud,
then click Resource List and then click Services. Delete any other Watson Assistant service that is
running.
__ 6.
After a few seconds, the service is created as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-5
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 7.
The landing page for the Watson Assistant service opens as shown in the following figure.
Click Launch Watson Assistant to start building your chatbot.
__ 8.
The Assistants page is displayed. You can create your assistant from this page.
Part 2: Creating the conversation flow in the Watson Assistant service
In this part, you create the conversation flow in the Watson Assistant service that you created in
Part 1. The conversation flow represents people who are asking for help in a natural disaster area.
To create the conversation flow in Watson Assistant, complete the steps in the following sections.
Creating a dialog skill
In this section, you create your first dialog, which is a container for all the artifacts that define a
conversation flow.
__ 1.
Click Create assistant as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-6
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 2.
Type Savior (or any name of your choice) as the name of the assistant and click Create
assistant.
__ 3.
Now that the assistant is created, you can add a dialog skill to it. Click Add dialog skill as
shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-7
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 4.
Select the Create skill tab, enter the name Savior, and click Create dialog skill as shown
in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-8
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 5.
The dialog skill is created as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-9
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 6.
You need the dialog workspace ID (also known as Skill ID) to connect your dialog with your
Node-RED application. To get the workspace ID (Skill ID), click the icon to open and close
the list of options (three dots) as shown in the following figure and then select View API
Details.
The details that are shown in this screen might look different for every user. The Legacy v1
Workspace URL contains the Workspace ID as highlighted in square in the following example:
The workspace ID (skill ID) in this example is d8e70408-87a6-4e24-b363-fae3a4b77169. Take
note of your workspace ID, as you use it later in this exercise. Save it in a text editor.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-10
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 7.
Click X to close the windows.
Creating intents and entities
In this part, you create intents and entities that are needed to validate the user’s input.
__ 1.
Click the dialog that you created (Savior in this example) to open it as shown in the following
figure.
__ 2.
Click Create intent. Type crisis in the Intent name field and then click Create intent as
shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-11
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Information
One of the components that you need to create for your dialog is intents. An intent is a collection of
user’s statements that have the same meaning. By creating intents, you train your assistant to
understand the variety of ways users express a goal. The intent is a word that is preceded by the
pound (#) sign.
__ 3.
For each intent, you can type user examples as shown in the following figure. The examples
are sample sentences or questions that the user might ask or type in the assistant and can
be recognized in a particular intent.
Type we are in the middle of a flood as a user example so it can be identified as a #crisis
intent by the assistant. Then, click Add example.
__ 4.
Repeat the steps and add the following examples for the #crisis intent, as shown in the
following figure:
- we are in the middle of a hurricane
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-12
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
- we are in the middle of a tornado
- we are in the middle of a volcano
- we are in the middle of an earthquake
__ 5.
Click the back arrow on the upper left next to the intent’s name to go back to the intents
page. You can see the intents that you created, and you can create more intents by clicking
Create intent as shown in the following figure.
__ 6.
Click the Entities tab to show the My entities page. From here, you can create entities.
Click Create entity to create entities in your dialog.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-13
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Information
Entities are like nouns or keywords. By entering your business terms in entities, your assistant can
provide targeted responses to queries. Entities represent nouns (the object of, or the context for
that action represented by intents). Entities are preceded by the “at” sign (@).
__ 7.
Enter the entity name to match the category of values that it can detect in a user’s input as
shown in the following figure. Type crisis_type and click Create entity.
__ 8.
After the entity is created, enter the following values:
- Value: earthquake
- Synonyms: Active faults
Click + to add another synonym, Aftershocks, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-14
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Note
Adding synonyms for entity is optional. You can add synonyms for all entity’s values, some of them,
or none.
__ 9.
Click Add value after you finish adding synonyms.
__ 10. Enter different values for the entity @crisis_type as shown in the following figure. For
example, add the following values and click Add Value after you enter each value:
- Floods
- Hurricane
- Tornado
- Volcano
Whenever the user’s input includes one of these keywords, it is categorized under the
@crisis_type entity.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-15
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 11. Click the back arrow on the upper left next to the entity’s name to go back to the entities
page, where you can see the entities that you created. You can create more entities by
clicking Create entity.
Creating a dialog
In this part, you create the dialog that matches intents (what users say) to responses (what the
bot responds).
__ 1.
Now it is the time to create the dialog. Click the Dialog tab. Initially, you have the following
nodes:
- Welcome, which has the following welcome message for the user when the chat starts:
Hello. How can I help you?
- Anything else, which handles any user’s input that is not recognized by the other nodes
in the dialog. Through this node the chatbot replies with:
○ I didn't understand. You can try rephrasing.
○ Can you reword your statement? I'm not understanding.
○ I didn't get your meaning.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-16
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
The user now has a chance to reenter an input that can be understood by the
chatbot.
__ 2.
Click the Node options (three dots) in the Welcome node and select Add node below as
shown in the following figure.
Information
In the node configuration, you specify the intent or entity to be recognized in the user’s input. The
assistant identifies the intents and entities in the user’s input and tries to match the user’s input with
one of the examples entered previously. Based on this categorization, the assistant responds
according to this node’s configuration.
__ 3.
Enter the node name Determine crisis and the intent to be recognized by this node.
__ 4.
To enter the intent under If assistant recognizes click Enter Condition. From the list of
intents, select #crisis.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-17
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 5.
You can add another condition by clicking + next to #crisis.
Select the “or” condition to add from the entities the @crisis_type entity to this node.
__ 6.
Add a response to be returned to the user when the assistant recognizes the #crisis intent
or the @crisis_type entity in the user’s input. For example, we know your location now
and the help is on its way.
The following figure shows the Determine crisis node configuration in this example.
__ 7.
You can add another node by clicking the Node options icon (three dots) in the Determine
crisis node and selecting click Add node below as shown in the following figure. You do
not need to add more nodes for this example. Click X to close the page.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-18
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 8.
Now you have completed your dialog as shown in the following figure.
__ 9.
Click Try it on the upper right to open the Try it out pane and test your dialog.
__ 10. The Try it out pane displays the message in the Welcome node as shown in the following
figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-19
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 11. In the pane, you can enter user’s input, for example, there is a volcano as shown in the
following figure. Press Enter after you enter text.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-20
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 12. The assistant was able to recognize your input as #crisis and replies with the response that
is configured in the Determine crisis node. Notice the dialog reply we know your location
now and the help is on its way.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-21
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 13. Access your IBM Cloud Dashboard by clicking the avatar icon for your account. Then, select
IBM Cloud Dashboard as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-22
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Part 3: Configuring your device to be used in Node-RED
In this part, you connect a device to Watson IoT Platform by using the Quick start feature. With
Quick start, you can set up a configuration for a single device to send data to Watson IoT Platform.
You can visualize the data in your browser.
In this part, you open the simulated sensor, copy its unique ID to configure the IBM IoT input node
in the Node-RED flow.
__ 1.
Open the temperature sensor simulator page in a new browser tab by following the link
https://quickstart.internetofthings.ibmcloud.com/iotsensor/ as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-23
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 2.
Copy the sensor ID in the upper right, as shown in the following figure.
Important
The sensor ID is a unique and random value that changes every time you refresh the page, so
make sure that you do not close the dialog box until your finish this exercise.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-24
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Part 4: Creating a Text to Speech service
In this part, you create a Text to Speech service that you use to convert the response from the
Watson Assistant to speech.
__ 1.
Open the IBM Cloud catalog and type Text to Speech in the search field. Find the Text to
Speech service as shown in the following figure and select it.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-25
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 2.
In the Text to Speech service page, accept the default values and click Create as shown in
the following figure.
Your Text to Speech service page opens with the Getting started tab selected as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-26
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 3.
Select Service credentials as shown in the following figure
__ 4.
Copy the service credentials by clicking the Copy to clipboard icon. You need the apikey
and url to connect the Text to Speech service to the Node-RED flow.
Part 5: Connecting Watson Assistant to the Node-RED application
In this part, you connect the Watson Assistant service that you created in Part 2 to your Node-RED
application. Then, you test this connection by entering a user input to the assistant through the
Node-RED flow and getting a response.
Complete the following steps:
__ 1.
From the IBM Cloud Navigation Menu, select Resource List as shown in the following
figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-27
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 2.
In the Resource list page, expand Cloud Foundry apps and open your Node-RED
application as shown in the following figure.
Your application page opens.
__ 3.
Select Connections and click Create connection as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-28
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 4.
The list of the available services that can be connected to your application is displayed as
shown in the following figure. Click Connect to connect your Watson Assistant to the
Node-RED flow.
__ 5.
In the window that opens click Connect as shown in the following figure.
It takes a moment to save the connection as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-29
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 6.
In the Restage app prompt, click Restage as shown in the following figure.
__ 7.
It takes 1 - 2 minutes to restage the app. Then, the assistant is connected to the application
as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-30
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 8.
Click Visit APP URL to open your Node-RED application and access the Node-RED editor.
__ 9.
The Node-RED page opens. Click Go to your Node-RED flow editor.
__ 10. Drag the inject and debug nodes from the left pane to the canvas. The node names
change to timestamp and msg.payload on the canvas.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-31
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 11. Enter assistant in the search field to find the assistant node as shown in the following
figure. Drag this node to the canvas.
__ 12. Double-click the inject node (timestamp). Change the payload field type to string, and enter
the text There is a volcano as shown in the following figure. Click Done.
__ 13. Double-click the assistant node to configure it with the Workspace ID that you got in Part 3.
Add the Workspace ID to the node configuration as shown in the following figure. Click
Done.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-32
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 14. Connect the nodes by dragging the square box from one node to the other as shown in the
following figure. Then, click Deploy.
__ 15. After successful deployment, click inject, the square on the left of the There is a volcano
node. Monitor the debug view on the right pane for the output.
__ 16. Expand the output in the debug pane. You can see the input text “There is a volcano”
injected from the input node. This input text is categorized as the entity crisis_type in the
Determine Crisis node in the dialog. The assistant responds with the output text we know
your location now and the help is on its way.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-33
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Part 6: Integrating your IoT device, Watson Assistant, and Text to Speech
service in your Node-RED flow
In this part, you connect the Watson Assistant flow that you created earlier to the Watson Text to
Speech Service. The assistant response is converted to speech and the user can hear it in the
browser.
You also connect the device that you created with Quick start to input the temperature to the flow
and see the results.
Complete the following steps:
__ 1.
Click the hamburger icon on the upper right and select Manage palette as shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-34
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 2.
Select the Install tab and type play-audio in the search field. Install the node in the list
node-red-contrib-play-audio as shown in the following figure.
__ 3.
Confirm the installation by clicking Install as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-35
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 4.
A confirmation message is displayed to indicate that the play audio node is added to the list
of nodes as shown in the following figure.
__ 5.
Install the IBM IoT platform node by typing ibmiot and installing
node-red-contrib-scx-ibmiotapp.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-36
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 6.
In the window that is displayed, click Install as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-37
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 7.
Click Close.
__ 8.
From the hamburger menu, select Import.
__ 9.
Copy the JSON flow from
https://raw.githubusercontent.com/IBM-SkillsAcademy/IoTCloudDeveloper2020/master/tem
pSensorFlow.json and paste it as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-38
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 10. Click Import.
Your flow looks similar to the flowing figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-39
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 11. Double-click the IBM IoT node and enter the device ID from the Quick start device.
__ 12. Click Done.
__ 13. Double-click the assistant node and enter the workspace ID that you saved earlier.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-40
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 14. Click Done.
__ 15. Double-click the text to speech node and enter the following configuration
API Key: <the value that you copied in Part 4>
Service Endpoint: < the url that you copied in Part 4>
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-41
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 16. Click Done.
__ 17. Go to the IoT Sensor (Quick Start) tab and raise the temperature above 30 as shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-42
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
__ 18. Go back to your Node-RED flow to hear the Watson Assistant reply we know your location
now and the help is on its way. Find the output in the debug pane as shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-43
V11.2
Exercise 4. Extending IoT application functions by using Node-RED
EXempty
Exercise review and wrap-up
In this exercise, you connected Watson Assistant to a Node-RED application to send user input and
receive a response back from the assistant.
You created a Watson Text to Speech Service to hear the assistant’s reply in your browser.
You created a device in your IoT platform to measure the temperature and connected it to the
simulator and to your Watson Assistant through the Node-RED flow to send input to the assistant
when the temperature reaches a high value. You hear the assistant’s response through the Text to
Speech service.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
4-44
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Exercise 5. Monitoring server CPU
usage and reporting
statistics
Estimated time
01:30
Overview
In this exercise, you implement an IoT use case about monitoring server CPU usage in a server
room. You use your local workstation as a server by installing Node-RED on your PC or notebook.
Your system reports CPU usage to a cloud application through the Watson IoT Platform.
Objectives
After completing this exercise, you should be able to:
• Set up Node-RED on a local workstation.
• Configure new devices on Watson IoT Platform.
• Connect a Node-RED application that is running locally to a cloud application (in this exercise,
you use Node-RED on IBM Cloud to represent the cloud application).
Introduction
In large server rooms, you monitor CPU to track CPU performance regressions or improvements
when you run a specific piece of code. You also use monitoring to investigate performance
problems and solve them quickly to minimize the impact on your servers.
In this exercise, you simulate a server that is installed in a server room by using your PC. You
monitor the CPU usage, which is a dynamic variable that changes frequently, through Watson IoT
Platform.
Prerequisites
Complete exercise Creating your first IoT application.
Requirements
This exercise requires access to the internet and the latest version of a modern web browser such
as Chrome, Firefox, and Safari.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-1
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Exercise instructions
In this exercise, you complete the following tasks:
__ 1.
Prepare the environment on your local workstation.
__ 2.
Set up a simple CPU usage monitor flow on Node-RED.
__ 3.
Configure devices on Watson IoT Platform.
__ 4.
Connect the Node-RED application on cloud and the Node-RED application on a local
workstation through Watson IoT Platform.
Part 1: Preparing the environment on your local workstation
In this part, you install the prerequisites and prepare the environment that is needed to run this lab
by completing the following steps:
__ 1.
Install Node.js on your workstation from https://nodejs.org/en/download/.
__ 2.
To make sure that node.js is installed on your computer, run the following command in a
command line:
node --version
The output shows the version:
v10.15.1
__ 3.
To check whether npm is installed successfully, run the following command:
npm --version
The output shows the version:
6.4.1
Note
npm is the package manager for JavaScript. You need it to download the JavaScript packages that
are required for this exercise.
__ 4.
Install Node-RED on your workstation by running the following command. The output is
shown in the following figure.
npm install -g --unsafe-perm node-red
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-2
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-3
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Note
If you get the error “Permission denied“, you must run as administrator. For Windows OS, right-click
Command Prompt and choose Run as administrator, as shown in the following figure.
For Mac OS, run the following command in your terminal:
sudo chown -R $USER /usr/local/lib/node_modules
__ 5.
To start Node-RED, run the following command:
node-red
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-4
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Here is the output:
7 Mar 21:31:19 - [info]
Welcome to Node-RED
===================
7 Mar 21:31:19 - [info] Node-RED version: v1.0.4
7 Mar 21:31:19 - [info] Node.js version: v10.15.1
7 Mar 21:31:19 - [info] Windows_NT 10.0.18362 x64 LE
7 Mar 21:31:20 - [info] Loading palette nodes
7 Mar 21:31:22 - [info] Settings file :
\Users\KarenFahmy\.node-red\settings.js
7 Mar 21:31:22 - [info] Context store : 'default' [module=memory]
7 Mar 21:31:22 - [info] User directory : \Users\KarenFahmy\.node-red
7 Mar 21:31:22 - [warn] Projects disabled :
editorTheme.projects.enabled=false
7 Mar 21:31:22 - [info] Flows file
:
\Users\KarenFahmy\.node-red\flows_DESKTOP-DFAFHCD.json
7 Mar 21:31:22 - [info] Server now running at http://127.0.0.1:1880/
7 Mar 21:31:22 - [warn]
--------------------------------------------------------------------Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
• --------------------------------------------------------------------7 Mar 21:31:22 - [info] Starting flows
7 Mar 21:31:22 - [info] Started flows
7 Mar 21:31:22 - [info] Server now running at http://127.0.0.1:1880/
__ 6.
On your browser, go to http://127.0.0.1:1880/. You are redirected to the Node-RED flow
editor, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-5
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Part 2: Setting up a simple CPU usage monitor flow on Node-RED
In this part, you build the server simulator on Node-RED that is installed on your computer by
completing the following steps:
__ 1.
Click the hamburger menu icon in the upper right as shown in the following figure.
__ 2.
Select Manage Palette to install the CPU package and the Watson IoT package, as shown
in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-6
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 3.
Select the Install tab and search for “node-red-contrib-cpu”. Click Install, as shown in the
following figure.
__ 4.
At the Installing ‘node-red-contrib-cpu’ prompt, click Install. Wait for the package to install.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-7
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 5.
Install IBM Watson IoT node by searching for “ibm-watson-iot” and clicking Install, as
shown in the following figure.
__ 6.
At the Installing ‘node-red-contrib-ibm-watson-iot’ prompt, click Install. Wait for the package
to install.
__ 7.
A message that lists the nodes added to the palette is displayed, as shown in the figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-8
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
You can close the User Settings window.
Troubleshooting
If you encounter errors during installation, go to your computer, press Ctrl + c to close Node-RED,
and then run the following command:
cd .node-red
Then, install the package that failed to install by running the following command:
npm install node-red-contrib-ibm-watson-iot
Start Node-RED again by running the following command:
node-red
__ 8.
Drag the following nodes to the flow editor canvas:
- inject
- cpu
- debug
You can search for the node by entering their name in the “filter nodes” field.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-9
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Note
The node names change when they are dropped on the flow canvas as follows:
• The inject node changes to timestamp.
• The cpu node changes to CPU usage.
• The Debug node changes to msg.payload.
__ 9.
Wire the CPU usage monitor simulator flow by wiring the nodes together, as shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-10
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 10. Double-click the CPU usage node. The node configuration page opens. Change the CPU
usage node configuration, as shown in the following figure, and then click Done.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-11
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Note
The selected option (Send a message for overall usage) is used for this exercise, but you can
investigate different options.
__ 11. Click Deploy
to save the changes and deploy the flow.
__ 12. Click inject (timestamp on the canvas) to inject a pulse to activate the CPU usage and
check the result on the debug tab, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-12
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Part 3: Configuring devices on Watson IoT Platform
In this part, you configure the CPU usage monitor simulator on Watson IoT Platform to manage the
server by completing the following steps:
__ 1.
In IBM Cloud, select Resource List from the Navigation Menu (hamburger icon) as shown
in the following figure.
__ 2.
Expand the services section. Then, click the Internet of Things Platform service.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-13
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 3.
Click Launch to get started with Watson IoT Platform, as shown in the following figure.
The Browse Devices page opens, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-14
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 4.
Click Devices on the left bar and then select the Device Types tab to add the device type.
Then, click Add Device Type.
__ 5.
Enter ‘CPUMonitor’ as the device name, a description, and then click Next.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-15
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 6.
(Optional) Enter more information about the device type for identification purposes as
shown in the following figure.
__ 7.
Click Finish.
__ 8.
Click Register Devices to register the CPU usage monitor device.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-16
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 9.
Add the device’s unique Device ID and click Next, as shown in the following figure.
__ 10. Device Information is selected. Here you can modify the device information. You can click
Add Metadata to add metadata to define custom attributes for your devices. If you do not
want to make any changes, click Next as shown in the figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-17
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 11. For authentication, you can optionally enter an Authentication Token. If you do not enter
one, it is generated automatically, which is the default option. Allow the service to generate
an authentication token for you. The token is returned to you at the end of the device
registration process. Click Next as shown in the following figure.
__ 12. You are redirected to a summary window. Review all the details that you entered. If they are
all correct, click Finish as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-18
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 13. Copy the values for organization ID, device type, and authentication token in a notepad on
your computer. You use these values later in the exercise. After you close this window, you
will not be able to get the value of the authentication token again.
Attention
Authentication tokens are unrecoverable. If you misplace this token, you will need to reregister the
device to generate a new authentication token.
__ 14. To add an application, click Apps. In the next window, click Generate API Key.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-19
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 15. In the next window, click Next, as shown in the following figure.
__ 16. Click the Role pull-down menu and then select Standard Application to add permissions
to this application. The application has access for this role.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-20
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 17. Click Generate Key.
__ 18. You are redirected to the generated details, where you see the API key and authentication
token, as shown in the following figure. Click the copy to clipboard icon to copy the API
key and the authentication token and paste the information in a text editor on your
computer.
Important
Make a note of the generated authentication token. Lost authentication tokens cannot be
recovered. If you lose the token, you must reregister the API to generate a new token. You will not
have access to this information again after you close the window.
__ 19. Click Close.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-21
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Part 4: Configuring Node-RED on IBM Cloud
In this part, you configure Node-RED on IBM Cloud so that Node-RED acts as a cloud application
that receives readings from the CPU usage monitor simulator.
Complete the following steps:
__ 1.
In IBM Cloud, select Resource List from the Navigation Menu (hamburger icon) in the
upper left as shown in the following figure.
__ 2.
Expand Cloud Foundry apps section, then clock on your Node-RED application.
__ 3.
Click Visit App URL next to your application’s name as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-22
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 4.
The Node-RED on IBM Cloud page opens. Click Go to your Node-RED flow editor as
shown in the following figure.
Your Node-RED application environment opens as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-23
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Note
This is the flow that you created in exercise Extending IoT application functions by using
Node-RED. The flow should be in your flow editor as you did not clean up the environment at the
end of the exercise.
__ 5.
Click the + icon to add a new flow editor.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-24
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 6.
Configure the cloud application flow to receive readings from the server. Drag the ibmiot in
node from the input section to the canvas. You can find the node by entering its name in the
filter field on the top.
Note
If you did not find the ibmiot node in the palette on the left, use Manage Palette on the right to install
the ibmiot node node-red-contrib-scx-ibmiotapp, as shown in the following figures.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-25
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 7.
Double-click the node to change its configuration. Change the Authentication field to API
key.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-26
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 8.
Click the API Key field, select Add new ibmiot, and click the edit icon (pencil).
__ 9.
Enter the API Key and Authentication Token that was generated in Part 3, and click Add.
__ 10. Click Done to exit the configuration.
__ 11. Click Deploy to save the changes and deploy the flow. The node is now connected by
Watson IoT Platform.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-27
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Part 5: Connecting the Node-RED application on cloud and the Node-RED
application on a local workstation through Watson IoT Platform
In this part, you integrate the Node-RED application on your local computer with the Node-RED
application on cloud to monitor reading changes from the cloud application.
Complete the following steps:
__ 1.
Return to the flow you created on your local workstation in Part 2. From the output section,
drag the Watson IoT output node to the canvas, as shown in the figure. You can find the
node by searching for it in the search filter on the upper right corner of the page.
__ 2.
Double-click the IBM IoT Device node and configure it to connect the registered device to
the cloud application. Select Registered, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-28
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 3.
Click the pen icon to edit the Credentials field. In the window that opens, enter the details for
the device that you registered in Part 3, as shown in the following figure. Then, click Update
(or Add).
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-29
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-30
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Note
The value of the Organization field will be different for your organization. If you did not take note of
your organization when you registered the device, you can find its value from your Watson IoT
Platform URL or below your email ID on the upper right as shown in the following figure.
__ 4.
Click Done.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-31
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
The node name on the canvas changes to event, as shown in the figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-32
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 5.
Wire the components together, as shown in the following figure.
__ 6.
Click Deploy
connected.
to deploy the flow. The Watson IoT node (event node) is
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-33
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 7.
Return to your Node-RED flow on IBM Cloud. Add the debug node from the output section
by dragging it into the canvas. The node is named msg.payload. Wire the nodes, as shown
in the following figure.
__ 8.
Click Deploy to deploy the flow.
__ 9.
On the Node-RED flow on your local computer, click the inject node (timestamp on the
canvas) to inject a message into the flow to start the CPU usage monitoring system.
Observe the value on the debug tab, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-34
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
__ 10. On Node-RED application on IBM Cloud, observe the debug tab. Expand the object field if
needed.
You see that the value that you got from the local computer is transferred to the Node-RED
application on IBM Cloud through Watson IoT Platform.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-35
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics
EXempty
Exercise review and wrap-up
In this exercise, you installed and configured Node-RED in your local workstation. You installed the
packages that provided the nodes require to build a flow for a CPU usage monitor simulator.
You chose and configured the nodes and tested the CPU usage monitor on your local PC.
Next, you set up Watson IoT Platform on IBM Cloud. You configured the CPU usage monitor device
and generated an API key to enable the connectivity of the simulator that is running on your local
workstation to Watson IoT Platform on IBM Cloud.
Next, you created a Node-RED application on IBM Cloud, which represents a generic cloud
application that receives CPU usage reading from the CPU usage monitor simulator on the server.
Finally, you connected the Node-RED CPU usage monitor simulator application that is running on
the local workstation to the Node-RED application on IBM Cloud through Watson IoT Platform.
At the end of the exercise, you closed Node-RED on your local PC and cleaned up the environment
on IBM Cloud.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-36
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Exercise 5. Monitoring server CPU
usage and reporting
statistics by using a
Raspberry Pi device
(optional)
Estimated time
01:30
Overview
In this exercise, you implement an IoT use case about monitoring server CPU usage in a server
room. You use a Raspberry Pi device as a server by installing Node-RED on it. Your system reports
CPU usage to a cloud application through the Watson IoT Platform. The Raspberry Pi device
provides the opportunity to extend the capabilities of your monitoring system by measuring the
room temperature, humidity, and other conditions by connecting the Raspberry Pi device with the
corresponding sensor.
Objectives
After completing this exercise, you should be able to:
• Run Node-RED on a Raspberry Pi device.
• Configure new devices on Watson IoT Platform.
• Connect a Node-RED application that is running on a Raspberry Pi device to a cloud
application. (In this exercise, you use Node-RED on IBM Cloud to represent the cloud
application).
Introduction
In large server rooms, you monitor CPUs to track CPU performance regressions or improvements
when you run a specific piece of code. You also use monitoring to investigate performance
problems and solve them quickly to minimize the impact on your servers.
In this exercise, you simulate a server that is installed in a server room by using a Raspberry Pi
device. You monitor the CPU usage, which is a dynamic variable that changes frequently, through
Watson IoT Platform.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-1
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Prerequisites
Complete exercise “Creating your first IoT application”.
Requirements
• Access to the internet and the latest version of a modern web browser, such as Chrome,
Firefox, or Safari.
• Any Raspberry Pi device that can support Raspbian Jessie.
• Raspberry Pi equipment that includes the following items:
• SD card (Micro with adapter)
• Ethernet cable
• Power cable
• HDMI cable
• Monitor
• Keyboard
• Mouse
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-2
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Exercise instructions
In this exercise, you complete the following tasks:
__ 1.
Set up the Raspberry Pi device.
__ 2.
Install and configure Node.js and Node-RED on the Raspberry Pi device.
__ 3.
Set up a simple CPU usage monitor flow on Node-RED.
__ 4.
Configure devices on Watson IoT Platform.
__ 5.
Connect the Node-RED application on cloud and the Node-RED application on the
Raspberry Pi device through Watson IoT Platform.
Part 1: Setting up the Raspberry Pi device
In this part, you set up the Raspberry Pi device by connecting it to the internet and installing the
Raspbian operating system by using the Raspberry Pi Imager.
Information
You can follow these same steps in this part with full details in the Raspberry Pi official
documentation:
https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up
Complete the following steps:
__ 1.
Set up the SD card to install Raspbian on the Raspberry Pi device:
__ a.
Download the latest version of the Raspberry Pi Imager that suits your operating system
from the following link:
https://www.raspberrypi.org/downloads/
__ b.
Open the installer and follow the instructions in the wizard to install and run the
Raspberry Pi Imager.
__ c.
Insert the SD card into your workstation (if there is no slot in your workstation for the SD
card, use a USB adapter to insert it).
__ d.
Open the Raspberry Pi Imager and select the OS that you want to install in your
Raspberry Pi device (for this exercise, it is better to select the recommended option).
__ e.
Select the inserted SD card.
__ f.
Select Write, and then wait for the writing operation to complete. Then, eject the SD
card.
__ 2.
Connect the Raspberry Pi device to the monitor, keyboard, and mouse.
__ 3.
Connect the Raspberry Pi device to the internet by using an Ethernet cable (skip this step if
you are going to use the wireless connectivity).
__ 4.
Insert the SD card that you set up with Raspbian into the microSD card slot of the
Raspberry Pi device.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-3
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 5.
To start the Raspberry Pi device, connect the USB power. The red LED on the Raspberry Pi
device light up, and you see that raspberries appear in the upper left corner of your screen.
__ 6.
If this is the first time that you start your Raspberry Pi device with an SD card containing
NOOBS, you see the NOOBS installer. This software helps you install the Raspbian
operating system.
__ 7.
After the installation is done, you can access the Raspbian Desktop.
Part 2: Installing and configuring Node.js and Node-RED on the Raspberry
Pi device
After setting up of the operating system, install and configure Node.js and Node-RED on the
Raspberry Pi device if they are not already installed and configured by completing the following
steps.
Important
To check the official reference for Node-RED setup on the Raspberry Pi device, see
https://nodered.org/docs/getting-started/raspberrypi.
__ 1. Open the terminal in Raspbian, and then run the following command:
bash <(curl -sL
https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-node
js-and-nodered)
Note
The command runs a script to install Node.js, npm and Node-RED onto a Raspberry Pi device or to
upgrade to latest version if it is already available.
__ 1.
To make sure that Node.js is installed successfully, run the following command in a
command line:
node --version
The output shows the version:
v10.15.1
__ 2.
To check whether npm is installed successfully, run the following command:
npm --version
The output shows the version:
6.4.1
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-4
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Note
npm is the package manager for JavaScript. You need it to download the JavaScript packages that
are required for this exercise.
__ 3.
To start Node-RED, run the following command:
node-red-start
Here is the output:
7 Mar 21:31:19 - [info]
Welcome to Node-RED
===================
7 Mar 21:31:19 - [info] Node-RED version: v1.0.4
7 Mar 21:31:19 - [info] Node.js version: v10.15.1
7 Mar 21:31:19 - [info] Windows_NT 10.0.18362 x64 LE
7 Mar 21:31:20 - [info] Loading palette nodes
7 Mar 21:31:22 - [info] Settings file :
\Users\KarenFahmy\.node-red\settings.js
7 Mar 21:31:22 - [info] Context store : 'default' [module=memory]
7 Mar 21:31:22 - [info] User directory : \Users\KarenFahmy\.node-red
7 Mar 21:31:22 - [warn] Projects disabled :
editorTheme.projects.enabled=false
7 Mar 21:31:22 - [info] Flows file
:
\Users\KarenFahmy\.node-red\flows_DESKTOP-DFAFHCD.json
7 Mar 21:31:22 - [info] Server now running at http://127.0.0.1:1880/
7 Mar 21:31:22 - [warn]
--------------------------------------------------------------------Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
• --------------------------------------------------------------------7 Mar 21:31:22 - [info] Starting flows
7 Mar 21:31:22 - [info] Started flows
7 Mar 21:31:22 - [info] Server now running at http://127.0.0.1:1880/
__ 4.
On your browser, go to http://127.0.0.1:1880/. You are redirected to the Node-RED flow
editor, as shown in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-5
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Part 3: Setting up a simple CPU usage monitor flow on Node-RED
In this part, you build the server simulator on Node-RED that is installed on the Raspberry Pi device
by completing the following steps:
__ 1.
In the upper right, click the hamburger menu icon, as shown in the following figure.
__ 2.
Select Manage Palette to install the CPU package and the Watson IoT package, as shown
in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-6
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 3.
Select the Install tab and search for “node-red-contrib-cpu”. Click Install, as shown in the
following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-7
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 4.
At the Installing ‘node-red-contrib-cpu’ prompt, click Install. Wait for the package to install.
__ 5.
Install the IBM Watson IoT node by searching for “ibm-watson-iot” and clicking Install, as
shown in the following figure.
__ 6.
At the Installing ‘node-red-contrib-ibm-watson-iot’ prompt, click Install. Wait for the package
to install.
__ 7.
A message that lists the nodes added to the palette appears, as shown in the figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-8
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
You can close the User Settings window.
Troubleshooting
If you encounter errors during installation, go to the terminal, and run the command node-red-stop
to close Node-RED, and then run the following command:
cd .node-red
8. npm install node-red-contrib-ibm-watson-iot
__ 9.
Drag the following nodes to the flow editor canvas:
- inject
- cpu
- debug
- You can search for the node by entering its name into the “filter nodes” field.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-9
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Note
The node names change when they are dragged on to the flow canvas as follows:
• The inject node changes to timestamp.
• The cpu node changes to CPU usage.
• The Debug node changes to msg.payload.
__ 10. Wire the CPU usage monitor simulator flow by wiring the nodes together, as shown in the
following figure.
__ 11. Double-click the CPU usage node. The node configuration page opens. Change the CPU
usage node configuration, as shown in the following figure, and then click Done.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-10
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Note
The selected option (Send a message for overall usage) is used for this exercise, but you can
investigate different options.
__ 12. Click Deploy
to save the changes and deploy the flow.
__ 13. Click inject (timestamp on the canvas) to inject a pulse to activate the CPU usage and
check the result on the debug tab, as shown in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-11
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Part 4: Configuring devices on Watson IoT Platform
In this part, you configure the CPU usage monitor simulator on Watson IoT Platform to manage the
server by completing the following steps:
__ 1.
In your IBM Cloud, click the hamburger icon in the upper left corner and select Resource
List, as shown in the following figure.
__ 2.
Expand the services section and click the Internet of Things Platform service.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-12
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 3.
Click Launch to get started with Watson IoT Platform, as shown in the following figure.
The Browse Devices page opens, as shown in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-13
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 4.
Click Devices on the left bar and select the Device Types tab to add the device type. Then,
click Add Device type.
__ 5.
Enter ‘CPUMonitor’ as the device name and a description, and then click Next.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-14
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 6.
Enter more information about the device type for identification purposes, as shown in the
following figure. Click Finish.
__ 7.
Click Register Devices to register the CPU usage monitor device that you created in
Part 2.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-15
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 8.
Add the device’s unique Device ID and click Next, as shown in the following figure.
__ 9.
Select Device Information. Here you can modify the device information. You can click Add
Metadata to add metadata to define custom attributes for your devices. If you do not want to
make any changes, click Next, as shown in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-16
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 10. For authentication, you can optionally enter an authentication token. If you do not enter one,
it is generated automatically, which is the default option. Allow the service to generate an
authentication token for you. The token is returned to you at the end of the device
registration process. Click Next, as shown in the following figure.
__ 11. You are redirected to a summary window. Review all the details that you entered. If they are
all correct, click Finish, as shown in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-17
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 12. Copy the values for organization ID, device type, and authentication token in a notepad on
your computer. You use these values later in the exercise. After you close this window, you
cannot get the value of the authentication token again.
Attention
Authentication tokens are unrecoverable. If you misplace this token, you must reregister the device
to generate a new authentication token.
__ 13. To add an application, click Apps. In the next window, click Generate API key.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-18
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 14. In the next window, click Next, as shown in the following figure.
__ 15. Click the Role menu and select Standard Application to add permissions to this
application. The application has access for this role.
__ 16. Click Generate Key.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-19
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 17. You are redirected to the generated details, where you see the API key and authentication
token, as shown in the following figure. Click the copy/paste icon to copy the API key and
the authentication token and paste the information in a text editor on your computer.
Important
Make a note of the generated authentication token. Lost authentication tokens cannot be
recovered. If you lose the token, you must reregister the API to generate a new token. You do not
have access to this information again after you close the window.
__ 18. Click Close.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-20
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Part 5: Configuring Node-RED on IBM Cloud
In this part, you configure Node-RED on IBM Cloud so that Node-RED acts as a cloud application
that receives readings from the CPU usage monitor simulator.
Complete the following steps:
__ 1.
In your IBM Cloud, click the hamburger icon in the upper left corner and select Resource
List, as shown in the following figure.
__ 2.
Expand the Cloud Foundry apps section, and then click your Node-RED application.
__ 3.
Click Visit App URL next to your application’s name, as shown in the following figure
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-21
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 4.
The Node-RED on IBM Cloud page opens. Click Go to your Node-RED flow editor, as
shown in the following figure.
Your Node-RED application environment opens, as shown in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-22
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 5.
Configure the cloud application flow to receive readings from the server. Drag the ibmiot in
node from the input section to the canvas. You can find the node by entering its name in the
filter field on the top.
Note
If you did not find the ibmiot node in the palette on the left, click Manage Palette on the right to
install ibmiot, which is titled node-red-contrib-scx-ibmiotapp, as shown in the following figures.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-23
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Note
__ 6.
Double-click the node to change its configuration. Change the Authentication field to
API Key.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-24
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 7.
Click the API Key field, select Add new ibmiot, and click the edit icon (pencil).
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-25
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 8.
Enter the API Key and Authentication Token that was generated in Part 3 and click Add.
__ 9.
Click Done to exit the configuration.
__ 10. Click Deploy to save the changes and deploy the flow. The node is now connected by
Watson IoT Platform.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-26
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Part 6: Connecting the Node-RED application on cloud and the Node-RED
application on the Raspberry Pi device through Watson IoT
Platform
In this part, you integrate the Node-RED application on the Raspberry Pi device with the Node-RED
application on cloud to monitor reading changes from the cloud application.
Complete the following steps:
__ 1.
Return to the flow that you created on the Raspberry Pi device in Part 2. From the output
section, drag the Watson IoT output node to the canvas, as shown in the figure. You can
find the node by searching for it in the search filter at the upper right corner of the page.
__ 2.
Double-click the IBM IoT Device node and configure it to connect the registered device to
the cloud application. Select Registered, as shown in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-27
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 3.
Click the pen icon to edit the Credentials field. In the window that opens, enter the details for
the device that you registered in Part 3, as shown in the following figure. Then, click
Update.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-28
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-29
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Note
The value of the Organization field is different for your organization. If you did not take note of your
organization when you registered the device, you can find its value from your Watson IoT Platform
URL or below your email ID at the upper right, as shown in the following figure.
__ 4.
Click Done.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-30
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
The node name on the canvas changes to event, as shown in the figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-31
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 5.
Wire the components together, as shown in the following figure.
__ 6.
Click Deploy
connected.
to deploy the flow. The Watson IoT node (event node) is
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-32
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 7.
Return to your Node-RED flow on IBM Cloud. Add the debug node from the output section
by dragging it into the canvas. The node is named msg.payload. Wire the nodes, as shown
in the following figure.
__ 8.
Click Deploy to deploy the flow.
__ 9.
On the Node-RED flow on your local computer, click the inject node (timestamp on the
canvas) to inject a message into the flow to start the CPU usage monitoring system.
Observe the value on the debug tab, as shown in the following figure.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-33
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
__ 10. On the Node-RED application on IBM Cloud, look at the debug tab. Expand the object field
if needed.
You see that the value that you got from the local computer is transferred to the Node-RED
application on IBM Cloud through Watson IoT Platform.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-34
V11.2
Exercise 5. Monitoring server CPU usage and reporting statistics by using a Raspberry Pi device (optional)
EXempty
Exercise review and wrap-up
In this exercise, you set up the Raspberry Pi device by connecting it to the internet and installing the
Raspbian operating system on it by using the Raspberry Pi Imager. Then, you installed and
configured Node-RED. You installed the packages that provide the nodes that are required to build
a flow for a CPU usage monitor simulator.
You chose and configured the nodes and tested the CPU usage monitor on the Raspberry Pi
device.
Next, you set up Watson IoT Platform on IBM Cloud. You configured the CPU usage monitor device
and generated an API key to enable the connectivity of the simulator that is running on the
Raspberry Pi device to Watson IoT Platform on IBM Cloud.
Next, you created a Node-RED application on IBM Cloud, which represents a generic cloud
application that receives CPU usage reading from the CPU usage monitor simulator on the server.
Finally, you connected the Node-RED CPU usage monitor simulator application that is running on
the Raspberry Pi device to the Node-RED application on IBM Cloud through Watson IoT Platform.
© Copyright IBM Corp. 2018
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
5-35
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Exercise 6. Integrating IoT applications
with IBM Watson Visual
Recognition
Estimated time
01:00
Overview
In this exercise, you learn about the Watson Visual Recognition service, and how to integrate it with
IoT applications by using a Node-RED application.
Objectives
After completing this exercise, you should be able to:
• Create a Watson service instance and integrate it with Node-RED.
• Create a Watson Visual Recognition service instance and classify images.
• Store to and extract images from an IBM Cloudant database by using Node-RED.
• Create a Watson Studio project and add a Visual Recognition built-in model to classify images.
Introduction
This exercise demonstrates the power of Watson AI services and how you can integrate them with
an IoT system. Watson AI services add AI capabilities to your applications. They simplify analysis
and help improve the customer experience of the application and the application’s outcome.
This exercise demonstrates how you can use IoT and Watson Visual Recognition to detect the
people who enter a facility building by capturing their faces and classifying them according to age
group and gender. By using applications based on these services, facility building management or
security can track the number of visitors and get insights about the age groups of the visitors and
their gender.
This solution can be implemented in any building, shop, or museum that is interested in increasing
their marketing efforts or detecting their market segments by analyzing visitor’s data.
Prerequisites
Complete exercise Creating your first IoT application.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-1
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Requirements
You must meet the following requirements:
• Access to the internet and the IBM Cloud console from your workstation through a modern web
browser with the latest updates.
• IBM Cloud Lite account.
• Basic knowledge of IBM Cloud.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-2
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Exercise instructions
In this exercise, you complete the following tasks:
__ 1.
Open a Node-RED application.
__ 2.
Create a Node-RED flow to capture and store images.
__ 3.
Create a Watson Visual Recognition service instance.
__ 4.
Classify people and store images in a Cloudant database.
__ 5.
View a report of the classified images in the Cloudant DB dashboard.
__ 6.
(Optional) Classify people with Visual Recognition in Watson Studio.
Part 1: Opening a Node-RED application
In this part, you open the Node-RED app that was created and deployed in the exercise Creating
your first IoT application.
To open the Node-RED application, complete the following steps:
__ 1.
Log in to IBM Cloud at https://cloud.ibm.com.
__ 2.
Click the Navigation Menu (burger icon) on the upper left and select Resource List.
__ 3.
Under Cloud Foundry apps, open the Node-RED application by clicking the app name as
shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-3
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 4.
From the application overview page, click Visit App URL to access the Node-RED
application.
__ 5.
You are redirected to the Node-RED welcome page as shown in the following figure. Click
Go to your Node-RED flow editor.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-4
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 6.
You are redirected to the Node-RED flow editor.
Part 2: Creating a Node-RED flow to capture and store images
In this part, you use the Node-RED flow editor to store images of the entry gates of the building in
the database. In Part 4. Classifying people and storing images in a Cloudant database, you add
nodes to detect people by using the Watson Visual Recognition service. You will be able to
distinguish between images that include people and other images that do not include persons.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-5
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Complete the following steps:
__ 1.
If there are nodes in the Node-RED flow editor canvas, delete them. Select all the nodes by
pressing Ctrl+A and then press Delete to clear the canvas.
__ 2.
Rename the flow to Watson IoT VR. Click the hamburger menu at the upper right and
select Flows > Rename, as shown in the following figure.
__ 3.
Enter the new name for the flow and click Done as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-6
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 4.
The flow canvas looks like the following figure.
__ 5.
Use a search engine to find the image of a person’s face, for example,
https://upload.wikimedia.org/wikipedia/commons/thumb/7/7e/Thomas_J_Watson_Sr.jpg/10
24px-Thomas_J_Watson_Sr.jpg.
Note
This image is of Thomas J Watson, the first IBM CEO. IBM Watson was named after him.
__ 6.
Back in the Node-RED canvas, drag the inject node from the Input section to the flow
canvas. The node name changes to timestamp on the canvas as shown in the following
figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-7
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 7.
Double-click the inject (timestamp) node to configure it. Select string for Payload, enter the
image URL, and enter Send Image in the Name field. Then, click Done.
__ 8.
Search for the cloudant out node by typing cloudant in the search bar on the upper left as
shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-8
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 9.
Drag the cloudant out node to the flow canvas to store the injected image in the Cloudant
DB, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-9
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 10. Double-click the cloudant node and configure it as follows:
__ a.
Select the cloudant service.
__ b.
Name the images database, for example, images.
__ c.
Select the insert operation.
__ d.
Select Only store msg.payload object?
__ e.
Click Done.
Important
Select Only store msg.payload object? to store all the images in the msg.payload file, as shown
in the following figure. Now you can send the image, create a Cloudant DB, and store images in a
new database.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-10
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 11. Connect the Send Image node to the images Cloudant DB node, as shown in the following
figure. Then, click Deploy on the upper right. Your flow is deployed successfully.
__ 12. To check that your image is stored successfully in the database, complete the following
steps:
__ a.
Click the left button of the Send Image node, as shown in the following figure.
__ b.
Return to the Overview page of the Node-RED application on IBM Cloud.
__ c.
Scroll down to Connections and select the Cloudant service as shown in the following
figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-11
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ d.
Click the Alias of link that is shown next to the service name, to be directed to the
Cloudant service page.
__ e.
Select Manage as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-12
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ f.
Wait until the content of the Manage page is loaded and then click Launch Cloudant
Dashboard.
__ g.
The stored image is in the images database as shown in the following figure.
Part 3: Creating a Watson Visual Recognition service
In this part, you create a Visual Recognition service instance on IBM Cloud. The Visual Recognition
service is used by your application to analyze images. This service might also be used to detect, for
example, people, animals, and food in the images.
Complete the following steps:
__ 1.
Return to IBM Cloud and open the Catalog.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-13
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 2.
In the search field, type Visual Recognition and then select the service.
__ 3.
Keep the default values and click Create as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-14
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 4.
Click Manage on the left menu as shown in the following figure.
__ 5.
Copy the service credentials by clicking the copy icon to the right of API Key and URL, as
shown in the following figure. Keep the credentials in a safe place as you need them later in
the exercise.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-15
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Part 4: Classifying people and storing images in a Cloudant database
In this part, you classify images by using a Node-RED flow that includes a Visual Recognition node.
The images are then stored in a Cloudant DB by using a cloudant out node.
Complete the following steps:
__ 1.
Reopen the Node-RED application from the IBM Cloud Resource List, or switch to the
Node-RED tab if it is still opened.
__ 2.
Find the visual recognition node in the Node-RED pallet under the IBM Watson category.
If necessary, use the search field on the upper left.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-16
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 3.
Drag the visual recognition node and configure it as follows:
__ a.
Double-click the visual recognition node to open its configuration.
__ b.
In the API Key field, paste the API Key that you copied from the Watson Visual
Recognition service credentials.
__ c.
In the Service Endpoint field, paste the URL that you copied from the Watson Visual
Recognition service credentials.
__ d.
For Detect, keep Classify an image that is selected as shown in the following figure.
__ e.
Name the node Classifier.
__ f.
Click Done.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-17
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 4.
Wire the Classifier node and the Send Image node as shown in the following figure.
__ 5.
Drag the debug node (the name changes to ms.payload on the canvas).
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-18
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 6.
Double-click the debug node, then change the Output field to msg.result and click Done.
__ 7.
Wire the Classifier and the debug (msg.result) nodes.
__ 8.
Click Deploy at the upper right to deploy the flow.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-19
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 9.
Select the Debug messages tab as shown in the following figure.
__ 10. Click the left button in the Send Image node and check the output of msg.result. Expand
the object that is received to inspect the results, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-20
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Troubleshooting
If you receive the error “Internal Server Error”, as shown in the following figure, it means that the
connection to your Visual Recognition service failed. Possible reasons are wrong Service Endpoint
URL or wrong API Key.
If you receive the error “Bad Request: Access is denied due to invalid credentials.”, as shown in
the following figure, it means that the connection to your Visual Recognition service failed
because of wrong API Key.
If you receive the error “Payload must be either an image buffer or a string representing a url”,
as shown in the following figure, it means that the input in the inject node need is an incorrect
url.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-21
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Note
The classified image contains a person which is being classified and presented in the result
message in JSON format as class: “people”, class: “person” or both. To parse the JSON
object and obtain the path of the class, hover your cursor over class and click the leftmost icon to
copy the path.
__ 11. Hover your cursor over class: “person” and click the leftmost icon to copy the path, as
shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-22
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 12. Paste the path in a text editor for future use when you configure the switch node. The path
should look like the following:
result.images[0].classifiers[0].classes[0].class
__ 13. Repeat the previous step for score to get the following path:
result.images[0].classifiers[0].classes[0].score
__ 14. Drag a function node from the pallet as shown in the following figure. The function node is
used to apply some processing, which is used in this exercise to identify whether there is a
human in the image.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-23
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 15. Double-click the function node and configure it as follows:
__ a.
Enter Recognizer in the Name field as shown in the following figure.
__ b.
Enter the following code in the Function field:
let classes = msg.result.images[0].classifiers[0].classes;
for (let i = 0; i < classes.length; i++) {
if ((classes[i].class === 'person' || classes[i].class === 'people') &&
classes[i].score >= 0.5) {
msg.payload = 'Person';
return msg;
}
}
msg.payload = 'Other';
return msg;
__ c.
Click Done.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-24
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Note
The function uses the paths that are retrieved in steps 12 and 13 to return one of the following
options:
• Person is returned if the class has the value “person” or “people” and the score is greater than
or equal to 50%.
• Other is returned in all other cases.
__ 16. Wire the Recognizer and Classifier nodes as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-25
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 17. Drag a switch function node from the pallet, as shown in the following figure. The switch
node is used to classify the images that are detected by the Watson Visual Recognition
service. If the service detects a person, the image is classified as person, otherwise it is
classified as other.
__ 18. Double-click the switch node and configure it as follows:
__ a.
Enter Detect People in the Name field.
__ b.
In the Property field, keep the default value, which is msg.payload.
__ c.
In the Switch cases field, select String type and enter Person in the first option.
__ d.
Click +add to add the otherwise case, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-26
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Note
Be sure to select the otherwise case from the value rules list as shown in the following figure.
__ e.
Click Done.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-27
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 19. Wire the Recognizer and Detect People nodes as shown in the following figure.
__ 20. Drag two Cloudant DB out nodes to store the classified images.
__ 21. Configure the first cloudant node to store the people images as follows:
__ a.
Select the cloudant service (it might be selected by default).
__ b.
Enter people in both the Database and Name fields.
__ c.
Select insert in Operation field.
__ d.
Click Done.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-28
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 22. Configure the other cloudant node to store the other images (non-human images), as
follows:
__ a.
Select the cloudant service.
__ b.
Enter others in both Database and Name fields.
__ c.
Select insert in the Operation field.
__ d.
Click Done.
__ 23. Wire the first case of the switch node (Person) to the people database, and the second
case (otherwise) to the others database as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-29
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 24. Drag three debug nodes and wire them to each case of the switch (Detect People) node
and to the Recognizer as shown in the following figure. The debug node name changes to
msg.payload when dropped on the canvas.
__ 25. Click Deploy to deploy the flow.
__ 26. Test the flow by injecting images. In the Send Image node, change the URL in the Payload
field, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-30
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
The following links are images that you can use in the test:
○ Thomas Watson (person)
https://upload.wikimedia.org/wikipedia/commons/thumb/7/7e/Thomas_J_Watson_S
r.jpg/1024px-Thomas_J_Watson_Sr.jpg
○ Ginni Rometty (person)
https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/
Ginni_Rometty_at_the_Fortune_MPW_Summit_in_2011.jpg
○ Circuit (other)
https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/6
40px-IBM_VGA_90X8941_on_PS55.jpg
Note
No human is detected for the circuit image.
__ 27. Make sure to click Deploy after you inject each image to redeploy the flow and then click
the left button in Send Image node to inject with different images.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-31
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Part 5: Viewing a report of the classified images in the Cloudant DB
dashboard
In this part, you view people and others databases by using the Cloudant DB dashboard.
Complete the following steps:
__ 1.
Select Resource List from the IBM Cloud Navigation Menu.
__ 2.
Expand Services and click the Cloudant service that you are using with your Node-RED
application as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-32
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 3.
Wait until the page is loaded then click Launch Cloudant Dashboard.
__ 4.
Your Cloudant databases are displayed. Notice documents that in injected to the people
and others databases.
Part 6: (Optional) Classifying people with Visual Recognition in Watson
Studio
The IBM Watson Visual Recognition service uses deep learning algorithms to analyze images for
scenes, objects, faces, and other content. IBM Watson Studio provides a collaborative environment
in the cloud where you can work with your images and your Visual Recognition models.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-33
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Visual Recognition is a service on IBM Cloud. You can use the service in Watson Studio projects or
outside of Watson Studio, as you did in Part 3. Creating a Watson Visual Recognition service.
In this part, you create a Watson Studio project and associate your project with the Visual
Recognition service instance that you created in Part 3. You use the built-in Face model in Watson
Visual Recognition from a Watson Studio project. The goal of this part is to introduce you to using
Watson AI services from Watson Studio for data analysis and visualization.
Complete the following steps:
__ 1.
Open the IBM Cloud Catalog, enter Watson Studio in the search field, and click the
Watson Studio tile as shown in the following figure.
__ 2.
Keep the default values and then click Create as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-34
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 3.
Click Get Started as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-35
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 4.
Click the Navigation Menu (hamburger icon) on the upper left and select Watson
services, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-36
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 5.
Click Launch tool for the Visual Recognition service that you created in Part 3. Creating a
Watson Visual Recognition service.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-37
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Note
If you cannot find the visual recognition service that you created in Part 3, click the LOCATION drop
down and check all locations.
__ 6.
Click Test in the General model under Prebuilt Models. This service can classify the
images and describe the content of each figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-38
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
__ 7.
The General model summary window is displayed as shown in the following image.
__ 8.
Select the Test tab.
__ 9.
Create the directory faces on your local drive and download all the images from faces link to
your local faces directory.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-39
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Note
Faces folder link: https://ibm.ent.box.com/s/1gezkqtjl2j0wnlhp97iebvkphuwb2zj
__ 10. Click browse and select all the images in the faces folder. Then, click Open to upload the
images for classification as shown in the following figure.
__ 11. The result of the analysis is shown in the following figure. The results show the classes that
are identified for each image with the corresponding confidence level which is a value
between 0 and 1 to show the accuracy of this classification.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-40
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
End of exercise
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-41
V11.2
Exercise 6. Integrating IoT applications with IBM Watson Visual Recognition
EXempty
Exercise review and wrap-up
In this exercise, you learned about Watson services and how to integrate them with IoT applications
by using Node-RED. You also learned about working with JSON objects and APIs. You can apply
what you learned to other IoT applications and integrate them with several Watson services.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
6-42
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Exercise 7. Monitoring parking
utilization with IBM Cloudant
Geospatial
Estimated time
02:00 hours
Overview
In this exercise, you learn about geofencing, which is one of the common use cases of IoT. This
exercise demonstrates how to configure geofencing in IBM Cloudant, and how to build a
Node-RED flow that detects when a car reaches certain points.
Objectives
After completing this exercise, you should be able to:
• Build a car simulator with Node-RED to build a car simulator.
• Analyze raw data in real time and apply the analysis conclusions to a business case.
• Configure Cloudant to do geospatial analytics.
Introduction
In this use case, you build a parking monitoring system that uses car telematics information,
including longitude and latitude. Based on this information, the system detects whether a car
entered the parking area.
Prerequisites
Complete exercise Creating your first IoT application.
Requirements
• IBM Cloud Lite account
• A modern web browser with the latest updates (Google Chrome browser is preferred).
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-1
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Exercise instructions
In this exercise, you complete the following tasks:
__ 1.
Create a Watson IoT Platform application.
__ 2.
Add a car as a device to Watson IoT Platform.
__ 3.
Create a Node-RED flow to simulate car telematics.
__ 4.
Configure the Cloudant Geospatial index.
__ 5.
Build a Node-RED flow to handle geofencing.
Part 1: Creating a Watson IoT Platform application
This part summarizes the results of the prerequisite exercise Creating your first IoT application.
After you complete the exercise Creating your first IoT application, the Resource List in your IBM
Cloud dashboard looks similar to the following figure:
Part 2: Adding a car as a device to Watson IoT Platform
A car must be registered in the Watson IoT Platform device list. In the following steps, you create a
car type and add the car as a device that can receive data from the simulator.
Complete the following steps:
__ 1.
Go to the IBM Cloud dashboard at https://cloud.ibm.com/.
__ 2.
Open the side bar by clicking the Navigation Menu (hamburger icon) on the upper left, and
then click Resource List as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-2
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 3.
Expand Services and click the IoT service that is named Internet of Things Platform-xx
where xx is different for each user as shown in the following figure.
__ 4.
In the Internet of Things Platform service page, click Launch to open the Watson IoT
Platform dashboard, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-3
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 5.
In the IBM Watson IoT Platform dashboard, select the Device Types tab and click Add
Device Type + as shown in the following figure.
__ 6.
Make sure that Device is selected for Type and enter Car in the Name field as shown in the
following figure. Click Next.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-4
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 7.
Continue with the installer and keep all the defaults values until you finish. Click Finish, as
shown in the following figure.
__ 8.
Register a device by clicking Devices and then click Add Device + as shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-5
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 9.
Complete the Add Device wizard. For Device Type, click inside the box and select Car, and
for the Device ID, type car1 as shown in the following figure. Click Next.
__ 10. Continue with the wizard by clicking Next until you reach the Summary window. At the
Summary window, click Finish as shown in the following figure.
__ 11. A window opens and shows the device credentials as shown in the following figure. Copy
the Organization ID and the Authentication Token and paste them in a text editor for
future use.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-6
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Important
Authentication tokens are unrecoverable. If you misplace this token, reregister the device to
generate a new authentication token. In production projects, do not share the device credentials
and keep them under the possession of the device owner. Do not store the credentials in a
database on the back-end system.
Now that the device is registered, you can simulate sending data to Watson IoT Platform.
Part 3:
Creating a Node-RED flow to simulate car telematics
In this part, you use the Node-RED flow editor to simulate cars telematics. For this simulation, you
simulate the car movement in only one direction, from west to east.
Complete the following steps:
__ 1.
From the resource list, expand Cloud Foundry apps and open your node-RED application
as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-7
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 2.
Click Visit App URL next to the application name as shown in the following figure.
__ 3.
The Node-RED on IBM Cloud page is displayed. Click Go to your Node-RED flow editor
as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-8
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 4.
Select all nodes in the flow canvas by pressing Ctrl+A and then press Delete to clear the
default flow.
Note
You already installed the ibmiot node in exercise Extending IoT application functions by using
Node-RED. If you deleted the Node-RED application after you completed this exercise, you must
install the ibmiot node again as shown in the following figure
__ 5.
To import the flow, go to
https://github.com/IBM-SkillsAcademy/IoTCloudDeveloper2020/blob/master/car%20simulat
or%20flow.json, and copy the content of the JSON code to the clipboard. This flow
simulates the car movement.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-9
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 6.
In the Node-RED flow editor, click the hamburger menu and select Import.
__ 7.
Paste the flow JSON and then click Import.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-10
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 8.
Check that the Car Simulator flow looks similar to following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-11
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 9.
Double-click the IBM IoT node and confirm the following configuration:
- Authentication: Bluemix service
- Output Type: Device Event
- Device Type: Car
- Device Id: car1
- Event Type: location
- Format: json
- Data: {}
- QoS: 0
- Name: IBM IoT
- Service: registered
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-12
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 10. The simulated device data is inserted into the Cloudant database through the Cloudant
node. Double-click the Cloudant car-park node and confirm the following values:
Note
Your service value looks similar to the figure but is not exactly the same.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-13
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 11. Click Deploy.
__ 12. Check that the data is sent to the Watson IoT Platform. To open the Watson IoT Platform, go
back to the Resource List in your IBM Cloud dashboard, expand Services, and click
Internet of Things Platform.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-14
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 13. Click Launch.
__ 14. Expand car1 from the device list and select the Recent Events tab as shown in the
following figure. Confirm that new “location” events are received, which indicate that the car
data is sent correctly.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-15
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Part 4: Configuring the Cloudant Geospatial index
In this part, you create a Cloudant Geospatial index on IBM Cloud to track the car location and
check its location inside a geofence. A Cloudant database can query geospatial data. The data that
is stored in the database can be queried by value, and you can query all cars within a specific
region.
Complete the following steps:
__ 1.
Go to the IBM Cloud dashboard at https://cloud.ibm.com.
__ 2.
Select Resource List from your IBM Cloud dashboard Navigation Menu (hamburger icon)
as shown in the following figure.
__ 3.
Expand Services and select the Cloudant service as shown in the following figure. Click
the service name to open the service page.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-16
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 4.
Click LAUNCH CLOUDANT DASHBOARD to open the Cloudant dashboard.
__ 5.
Verify that the “car-park” database is in the list. This database was created automatically
from the cloudant node in the car simulator flow that you created in Part 3.
__ 6.
Click car-park to launch the database dashboard. You should find multiple documents in
the database as shown in the following figure. These documents are inserted by the car
simulator that you built in Part 3.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-17
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 7.
Add a document by clicking the + icon next to All Documents and selecting + New Doc as
shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-18
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 8.
Define the location for the parking area in GeoJSON format by using the following code.
The location in this case is Cairo – Tahrir Square.
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[[31.2357,30.0444],[31.236,30.0444],[31.236,30.0447],[31.2357,30.0447],[3
1.2357,30.0444]]]}
}
Add this code to the new document as shown in the following figure.
__ 9.
Click Create Document.
Information
GeoJSON is a standard format that is defined by the Internet Engineering Task Force FRC 7946.
For more information, see http://geojson.org/. By using the GeoJSON format, you are creating the
geofence that detects the car if it reaches the geofence.
__ 10. To create a Cloudant Geospatial index of this data, click the + icon next to Design
Documents, and click + New Doc as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-19
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 11. Enter the following code as shown in the following figure and then click Create Document.
{
"_id": "_design/geodd",
"st_indexes": {"geoidx": {"index": "function(doc) {if (doc.geometry &&
doc.geometry.coordinates) {st_index(doc.geometry);}}"}
}
}
__ 12. A Cloudant Geospatial index is created that contains the geospatial location on the map.
You can check the index on the Cloudant dashboard by selecting geodd > Geospatial
Indexes > geoidx as shown in the following figure. The polygon is drawn and it appears on
the map.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-20
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 13. Observe the markers representing the car location. They look similar to the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-21
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Note
If you do not see the markers, click the UI element “>” as shown in the figure.
Part 5: Building a Node-RED flow to handle geofencing
In this part, you build a Node-RED flow to send data and check these values against the Cloudant
Geospatial index. This task is similar to what you already did in Part 4 by using the Cloudant
dashboard, but instead it is done programatically by using an API and the Node-RED flow.
Complete the following steps:
__ 1.
Go to your Node-RED flow.
__ 2.
Add a flow by pressing the + icon at the upper right. The following figure shows the new
flow.
__ 3.
To import the flow, go to
https://raw.githubusercontent.com/IBM-SkillsAcademy/IoTCloudDeveloper2020/master/nod
e-red-geospatial.json, and copy the content of the JSON code to the clipboard.
__ 4.
In the Node-RED flow editor, click the hamburger menu icon in the upper right and
selecting Import > Clipboard as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-22
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 5.
Paste the flow into the text area and click Import, as shown in the following figure.
__ 6.
The imported flow is now on the canvas, as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-23
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 7.
Return to the IBM Cloud dashboard, expand Services, and click your Node-RED Cloudant
service, as shown in the following figure.
__ 8.
Select Service credentials, and then click New credential +, as shown in the following
figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-24
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 9.
Keep the defaults values and click Add as shown in the following figure.
__ 10. Expand Service credentials-1 and then click the copy to clipboard icon. You use the host,
username, and password in a future step.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-25
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 11. Go back to the Node-RED flow, double-click the http request node to open the
configuration.
Note
This Node-RED flow receives the data from the IoT simulated car, extracts the latitude and
longitude, and checks these values against the Cloudant Geospatial index. This task is similar to
what you already did by using the Cloudant dashboard, but instead it is done programatically by
using an API and the Node-RED flow.
__ 12. Configure the http request as follows:
__ a.
URL:
https://<your-host>/car-park/_design/geodd/_geo/geoidx?g=POINT({{{lon}}}%
20{{{lat}}})
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-26
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Replace <your-host> with the host value that you copied from the Cloudant service
credentials.
__ b.
Use basic authentication: Select this checkbox.
__ c.
Username: Paste the value that you copied from your Cloudant service credentials.
__ d.
Password: Paste the value that you copied from your Cloudant service credentials.
__ e.
Click Done, as shown in the following figure.
__ 13. Click Deploy to redeploy the flow.
__ 14. Click the debug icon on the right pane. When the car enters the region that you defined in
Cloudant, the debug node shows the traffic as shown in the following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-27
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Part 6: Cleaning up the environment
In this part, you clean up the environment by deleting the applications and services that you created
in all the exercises in this course.
To clean up your environment, complete the following steps:
__ 1.
Access the IBM Cloud Dashboard at https://cloud.ibm.com
__ 2.
Expand Cloud Foundry apps.
__ 3.
Click the Actions menu for your Node RED XXXXX app and select Delete as shown in the
following figure.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-28
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
__ 4.
Select all the services and routes that are associated with your application and click Delete
as shown in the following figure. The Cloud Foundry services will be deleted.
__ 5.
Expand Services and delete each service by selecting Delete.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-29
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Repeat this step for each service.
__ 6.
Expand Apps and delete the Node Red app as shown in the following figure.
End of exercise
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-30
V11.2
Exercise 7. Monitoring parking utilization with IBM Cloudant Geospatial
EXempty
Exercise review and wrap-up
In this exercise, you created a Watson IoT Platform application and you added a car as a device to
Watson IoT Platform to receive data from a simulator.
Next, you created Node-RED flow to simulate car telematics and monitored the car movements
from Recent Events in the Watson IoT Platform dashboard.
You learned to add a world map to a Node-RED flow to visualize geospatial data. You used a
Cloudant database as a query to track the car location and check its location inside a geofence.
Finally, you created a new flow to handle geofencing by sending the coordinates that are received
by the car to a Cloudant database to checked whether the car entered the virtual geographic
boundary and you monitored the results on the debug tab.
© Copyright IBM Corp. 2019, 2020
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
7-31
V11.3
backpg
®
© Copyright International Business Machines Corporation 2019, 2020.
Download