Documente Academic
Documente Profesional
Documente Cultură
biz/bluemixph
A platform where developers can act like kids in a sandbox except this box is enterprise-grade.
Prerequisite
Item Comment
Bluemix Account do the Creating a Bluemix Account laboratory exercise if you do not
have a Bluemix account
cf tool do the Setting-up Laboratory Environment (section: Installing the cf
tool) laboratory exercise to install the cf tool
JDK do the Setting-up Laboratory Environment (section: Installing Java
JDK) laboratory exercise to install JDK
In an actual device the device ID is usually the MAC address of the device. In the emulator, you are
using a hypothetical MAC address 080028572C3f. You may use a different device ID but it is
recommended in this experiment that you use 080028572C3f.
Fill-up the "Register Device" form. In the Device Type field, select Create a device type and
below it type Arduino. In the Device ID field, type 080028572C3f. Click Continue.
IMPORTANT:
It is important that you copy ACCURATELY the information especially auth-token. Once you
click Done you cannot anymore recover the auth-token value.
In an actual deployment, you should keep the auth-token a secret otherwise other people
who knows the auth-token of your device can easily use this credential to connect to your
Internet of Things service.
12. Download device-emulator.zip. Extract the folder found inside the zip file to the folder
c:\bluemixtemp. Make sure that the following folder structure is followed:
c:\bluemixtemp
device-emulator
Arduino.java
Emulator.java
:
run.bat
17. Open the Arduino.java file in a text editor. Change the following values:
ORGANIZATION
PASSWORD
DO NOT use the values in the screenshot below. Use the org and auth-token values for the
ORGANIZATION and PASSWORD, respectively. These are the values you copied in the Connect Your
Device step.
IMPORTANT: It is important that you use the correct ORGANIZATION and PASSWORD values,
otherwise your device will not be able to send and receive messages from your Internet of Things
service.
You do not need to examine the other Java files since these are only created as part of the emulator.
Once you are done examining Arduino.java, save and close the file.
19. In the device-emulator folder, double click compile.bat. Make sure that there are no errors.
Press any key to close the compile.bat console.
The console provides a text-based notification on the status of the device. For example, it shows the
notification Setting LED to off to indicate that the LED is turned off. A notification Message
Sent: { "d": { "temp": 25.0, "led": 0 } } means that the device is sending the
message to the Internet of Things Service. The temp value 25.0 means that the virtual temperature
sensor of the device is sensing a temperature of 25.0 degrees Celsius. In addition, a led value of 0
means that the LED is turned off.
You can drag the fire towards or away the device in order to adjust the temperature sensed by the
virtual temperature sensor.
22. Click the + icon at the right side of the Just now text to see the details of the messages the
Internet of Things service is receiving. Take note that will keep on updating as long as your device is
running. The dashboard of your Internet of Things service is a good tool to verify if your device is
successfully connected to your service.
31. When asked to restage the application, click CANCEL since you will add another service.
38. In the Node palette (left pane), look for the ibmiot input node. Take note that there are two ibmiot
nodes, one is an input and the other one is an output. You may move your mouse over the node to
know if it is an input or output node.
This PUBLISH_TOPIC value is consistent with the values set in the ibmiot input node.
Click Ok.
42. Drag and drop a debug node to the work area to the right of the ibmiot input node.
43. Connect the ibmiot input node to the debug node. To do this, click (and hold) over the rounded-
square symbol of the ibmiot input node. Move the mouse until you reach the rounded-square
symbol of the debug node. Release the mouse button.
47. Go back to the device and drag the fire to change its value. Check the debug tab and see if the
message changes.
49. Drag and drop an ibmiot output node to the work area at the bottom of the debug node.
In thes SUBSCRIBE_TOPIC, the value after cmd is + which stands for ALL. This means that any
message with any command type is accepted by device. Since the ibmiot output nodes command
type is set to led-on, the node will be sending a message with a led-on command type. This
message is received by the device. If you will review further Arduino.java, if this message with a
led-on command type is received, it will turn on the LED.
The ibmiot output node will not automatically send a message. It needs to be triggered. The next
few steps will handle this.
54. Double-click the inject node in the work area. Change the values of the form to the following:
Payload : blank
Topic : <leave this blank>
Repeat : none
Fire once at start : <do not select>
Name : Turn On LED
Format : json
Data : {}
Name : <no need to update this>
Cllick Ok.
58. Go back to your device and take note that the LED is off.
59. Go back to the simpleremotecontrol app. Click the trigger button of the inject node. This will
trigger the ibmiot output node to send a message with a command type led-on.
60. Go back to your device and verify that the LED is now on.
62. Drag and drop an http node to the work area on top of the inject node.
Cllick Ok.
66. Double-click the function node in the work area. Set the function to:
msg.payload = "{}"
return msg;
Cllick Ok.
68. Drag and drop an http response node to the work area to the right of the function node.
The purpose of adding the http node, function node, and http response node to the work area will
be seen later.
70. Click at the left-top area near the http node. Do not release the mouse button. Drag until the
following nodes are selected:
Release the mouse button. The five (5) node are now selected.
72. Press Ctrl+V to paste a new set of the five nodes. Move the mouse to adjust the position of the new
set of five nodes. Place them just below the original set.
Cllick Ok.
Cllick Ok.
Click Ok.
78. Go back to your device and take note that the LED is on.
79. Go back to the simpleremotecontrol app. Click the trigger button of the new inject node. This will
trigger the ibmiot output node to send a message with a command type led-off.
80. Go back to your device and verify that the LED is now off.
81. The following steps will now demonstrate the purpose of the http node, function node, and http
response node.
Open another tab on the browser. Type the following URL on the browser and press enter:
http://simpleremotecontrol-<name>.mybluemix.net/led-on
82. Go back to your device and verify that the LED is now on.
http://simpleremotecontrol-<name>.mybluemix.net/led-off
84. Go back to your device and verify that the LED is now off.
86. Drag and drop a function node to the work area to the right-top of the ibmiot input node.
// convert to msec
// subtract local time zone offset
// get UTC time in msec
var utc = d.getTime() - (d.getTimezoneOffset() * 60000);
msg.payload._id = "1234";
msg.payload.timestamp= nd.toISOString();//.toLocaleString();
return msg;
Click Ok.
89. Drag and drop a mongodb output node to the work area to the right of the function node that was
added in the previous steps.
Click Ok.
These connections allow the mongodb database to be updated with the latest temperature reading
and LED status.
95. Open index.html using a text editor. Look for the text NOTE. Change the URL to
http://simpleremotecontrol-<your name>.mybluemix.net/. Take note that this is the URL of the
Node-Red project created earlier.
97. Enter the following command to login to Bluemix. Enter your Bluemix username and password
when prompted.
Windows Command Prompt
CMD>cf login -a https://api.ng.bluemix.net
99. If you encounter the error The host is taken, modify the name of the application and try to upload
the application again.
100. Go back to your Bluemix account and click the DASHBOARD link.
104. If your application is still staging, wait for the staging process to complete.
108. The remotecontrol app shows the temperature reading and the current status of the LED. These
information are taken from mongodb. Recall that the mongodb is periodically updated in the
simpleremotecontrol app.
109. Go back to the device and drag the fire to change its value. Check the remotecontrol app and
see if the temperature reading changed.
110. Press the Turn ON LED and Turn OFF LED buttons. Check the LED in the device if its status
changes based on the button that was pressed. Take note that the Turn ON LED and Turn OFF LED
buttons can control the status of the LED because in the index.html file the two buttons are tied to
the URLs that will allow the LED to turn on and off.