2. • he Internet of Things, or IoT, refers to the growing range of Internet-connected
devices that capture or generate an enormous amount of information every day.
For consumers, these devices include mobile phones, sports wearables, home
heating and air conditioning systems, and more. In an industrial setting, these
devices and sensors can be found in manufacturing equipment, the supply chain,
and in-vehicle components. IoT can make life easier for all of us. To easily develop
and deploy IoT solutions of all sizes, IBM created the IBM Watson IoT Platform.
• In this tutorial, you will learn how you can use the Watson IoT Platform to build a
simple IoT solution by turning your smartphone into a sensor (reading and sending
data) but also into an actuator (reading and acting on data).
• You'll use an IoT Starter Mobile app on your smartphone. To transform your
smartphone into a sensor, we will build an IoT app that reads
the accelerometer values that are sent from your smartphone and reacts with a
specific action whether the values reach a certain threshold. To transform your
smartphone into an actuator, we will build an IoT app that sends specific
commands to your smartphone that can then react to the commands it receives.
3. • An IBM Bluemix® account. (You can request a free
trial here.)
• A smartphone (an Android or iOS smartphone).
• For an iOS smartphone, an iTunes account to
install the IoT Starter Mobile app.
• A twitter account to be notified by a tweet
(optional).
• An email account with SMTP relay capabilities to
be notified by an email message (optional).
4.
5. create your main IoT app in Bluemix
• Log in to your Bluemix account.
• In the Bluemix catalog, from the Boilerplates section,
select the Internet of Things Platform Starter
boilerplate.
• In the right pane, specify a unique name for your app,
which is used to create a unique host name for your
app. Then, click CREATE.
• The Internet of Things Platform Starter boilerplate
automatically adds the Internet of Things Platform
service and a Cloudant NoSQL Database service to your
app. It also includes a Node-RED runtime environment
for your app.
6. Register your smartphone in the
Watson IoT Platform
• you need to register your smartphone in the Watson
IoT Platform before you can connect it to the IoT. The
Bluemix IoT Platform service automatically allocates an
IoT organization to you. An IoT organization is a space
that is used for connecting and managing devices to
the IBM Watson IoT Platform so that your applications
can access their live and historical data.
• From your Bluemix dashboard, select the Internet of
Things Platform service. Then, click Launch
dashboard.
The dashboard for IBM Watson IoT Platform opens in a
new browser tab. The organization ID is assigned to
your app and is displayed in the upper right.
7. 2.in the Boards page, which is where you manage your devices and data, hover over the menu on
the left and selectDevices. On the Devices page, click Add Device.
3.In the Add Device page, click Create device type. The name for the device type is case-sensitive
and must be either Android or iPhone. The IoT
Starter Mobile app expects one of these words as the device type.
8. Install and configure the IoT Starter
Mobile app on your smartphone
• You will use the IoT Starter Mobile app to both
read and send sensor data that comes from your
smartphone and also to transform your
smartphone to be an actuator that can receive
and run commands. This application has been
developed with native languages on both iOS and
Android platforms. With this mobile app, you can
publish the following events:
• Accelerometer X, Y, Z event of your smartphone
• touchMove event
• Text event
9. Install the IoT Starter Mobile app on
your Android smartphone
• If you are an experienced Android developer, you can
download the IoT Starter Mobile app for Android demo
application from the ibm-watson-iot GitHub project, import
it into your Android development environment, and then
build the .apk file yourself. These steps here demonstrate
how to manually install the .ipa package file.
• On your Android phone, go to Settings > Security. Under
Smartphone Administration, enable Unknown sources. This
setting allows you to install .apk files from outside of
Google Play.
• Open the browser on your Android smartphone, and enter
this URL:
http://ibm.biz/asdwapkInstead of typing the URL, you can
use the QRcode in this article.
10. • Download the iot-starter-for-android.apk file
on your Android smartphone.
• Use a file explorer app to find the file in
the Downloads folder, and select the .apk file
to install it.
11. • verify that smartphone messages are being sent to the
Watson IoT Platform
• After you install the IoT Starter Mobile app on your
smartphone, you need to configure it with your IoT
credentials and connect the app to the Watson IoT
Platform.
• Open the IoT Starter app on your smartphone, and
specify your organization and smartphone credentials.
• Open the profile for the app.
– For Android devices, select the menu in the upper right,
and select Open profiles.
12.
13. • Click Save setting and give a name to your profile, such
as myProfile. Click Save, and go back to the login window. Your
credentials are now saved for the next time you connect.
• Click Activate Sensor, which causes your app to send messages to
the Watson IoT platform.
• In the Watson IoT Platform dashboard (in Bluemix), in the menu on
the left, select Devices. Select your smartphone in the list. Verify
that accelerometer events are displayed in the Recent
Events section.
• If you like, you can add a card to your dashboard to visualize your
smartphone data (in real-time even). Use the Watson IoT Platform
documentation on Bluemix to learn how to create boards and
cards.
14. • Process messages from your IoT sensor app
• Now that your smartphone is registered, and you
verified that it is sending its accelerometer data
to the Watson IoT Platform, we need to connect
the IoT app to the Watson IoT platform by using
the IoT service. We can then start to use that
smartphone data in our IoT solution.
• In the Bluemix dashboard, go to your application
and click your application route to access your
application.
15. now that your smartphone is registered, and you verified that it is sending its
accelerometer data to the Watson IoT Platform, we need to connect the IoT
app to the Watson IoT platform by using the IoT service. We can then start to
use that smartphone data in our IoT solution.
16. • In the Bluemix dashboard, go to your application and
click your application route to access your application.
• Open your Node-RED flow editor.
• In the Node-RED editor, which opens and contains a
sample flow, select all existing nodes and delete them.
• Create a new flow by dragging an ibmiot node from the
input section on to your workspace and also dragging a
debug node from the output section on to your
workspace. Connect the two nodes together.
17. Double-click the IBM IoT node to configure it. Specify the Bluemix service
authentication and device ID information, which is the one you choose when
you registered the smartphone with the Watson IoT Platform. Then, click
Done.
18.
19. • Double-click the IBM IoT node to configure it.
Specify the Bluemix service authentication
and device ID information, which is the one
you choose when you registered the
smartphone with the Watson IoT Platform.
Then, click Done.
20.
21. • send an alert when your smartphone falls down
• Now, we are going to update our Node-RED flow to use the sensor
data.
• We are going to do the following steps:
• Extract the "acceleration_y" value from the JSON payload message
• Trigger a value against an acceleration value (such
as 0.5 for iOS and 7 for Android)
• Debug the notification message
• Optionally, either post a tweet or send an email
• Go to your Node Red flow editor. You will create the following flow
by dragging the appropriate nodes and wiring them together as
shown in the following figure:
22.
23. • To extract the absolute acceleration_y value of the smartphone from the JSON payload message, we'll add and
configure a function node. From the function section of the palette, drag a function node to your workspace.
Double-click the function node to configure it with these values:
– Specify getAcceleration_y as the name for this node.
– In this function node, copy and paste the following code:
return {payload: Math.abs(msg.payload.d.acceleration_y)};
– Click Done.
• To create a trigger on the acceleration_y value, we'll add and configure a switch node. From the function section
of the palette, drag a switch node to your workspace. Wire the function node to the switch node. Double-click the
switch node to configure it with these values:
– Specify testAcceleration_y as the name for this node.
– Specify msg.payload as the property.
– In the condition value drop-down list, select ">=?", and specify 0.5 for iOS or 7 for Android.
– In the last drop-down list, select stopping after first match.
– Click Done.
• To define the notification message that you want to send when your phone is falling, we'll add and configure a
template node. From the function section of the palette, drag a template node to your workspace. Wire the switch
node to the template node. Double-click the template node to configure it with these values:
– Specify Acceleration_y_exceed_message as the name for this node.
– Specify msg.payload as the property.
– Copy and paste the following code to the node editor:
Wow! Is your phone falling?
Its acceleration y = {{payload}}!
– Click Done.
24. • o limit the number of messages for the notification and to avoid duplicate
notification messages, we'll add and configure a delay node. From the
function section of the palette, drag a delay node to your workspace. Wire
the template node to the delay node. Double-click the delay node to
configure it with these values:
– Specify Limit Rate as the name for this node.
– From the Action drop-down list, specify Limit rate to. Then, set the rate
to 1 and select Minute.
– Check the Drop intermediate message check box.
– Click Done.
• To display the notification message in the Debug tab of your flow, we'll
add and configure a debug node. From the output section of the palette,
drag a debug node to your workspace. Wire the delay node to the debug
node.
• To avoid getting too many debug messages in the Debug tab, you can
activate and deactivate the debug node by clicking the green rectangle in
the debug node.
25. 1.aA message is displayed at the top of your browser that explains if the
debug node is activated or deactivated.
2.To test your Bluemix application (and your Node-RED flow), complete these
steps:
a.Click Deploy to redeploy your Node-RED flow.
b.On your smartphone, run the IoT Mobile Starter app, and click Activate
Sensor.
c.Move your smartphone quickly up and down to simulate it falling down.
d.In your Node-RED flow editor, in the Debug tab, verify that cceleration_y values
are being displayed and that the notification message is also displayed.