Before You Begin
This tutorial shows you how to install and configure a Node.js simulator by using the Oracle Internet of Things (IoT) Cloud Service JavaScript Client Software Library. This tutorial takes approximately 15 minutes to complete.
Background
To integrate Oracle Mobile Cloud Service with Oracle IoT Cloud Service, you can use simulator devices.
For this tutorial, you use the Node.js JavaScript simulator device, which sends messages to Oracle IoT Cloud Service. Based on the messages, Oracle IoT Cloud Service sends alerts and notifications to Oracle Mobile Cloud Service.
What Do You Need?
- A computer running Windows 8 or later
- Node.js 4.x.x version or later for your system platform, downloaded and installed from
https://nodejs.org/dist/latest-v4.x/
- JavaScript Client Software Library binary
iotcs-csl-javascript-bin-release.zip
file (where release is the version number), downloaded from Oracle Technology Network - Access to an instance of Oracle IoT Cloud Service
Install the Prerequisite Software
-
Extract the
DirectlyConnectedDeviceSample.js
file fromiotcs-csl-js-samples-version.zip.
- Extract the Node Package Manager (npm) tar file from
iotcs-csl-js-bin-version.zip.
This JavaScript package manager file is contained within Node.js and typically takes the form ofiotcs-csl-device-version.tgz.
-
Move
DirectlyConnectedDeviceSample.js
to a new directory. - Open a command prompt and browse to that directory.
-
Install the prerequisite software using npm ():
npm install node-forge
npm install iotcs-csl-device-x.x.x.tgz
Modify the Sample Code
- In a text editor, open the
DirectlyConnectedDeviceSample.js
file. - In the device activation line, replace
humidity_sensor
withtransport_container.
dcd.activate(['urn:com:oracle:iot:device:transport_container'], function (device, error)...
-
In the device model retrieval line, replace
humidity_sensor
withtransport_container.
device.getDeviceModel('urn:com:oracle:iot:device:transport_container', function (response, error)...
-
Modify the variable sensor values for the transport container device model:
var sensor = { humidity: 0, temperature: 0, ora_latitude: 44.481429, ora_longitude: 26.104218 };
- Change the
send
function code for the transport container device model:var send = function () { sensor.humidity = 40 + Math.floor(Math.random() * 20); sensor.temperature = 30 + Math.floor(Math.random() * 25); virtualDev.update(sensor); };
- Save and close the file.
Your code should look similar to this file: DirectlyConnectedDeviceSample.js.
Register the Device
- In a web browser, enter the URL for your instance of Oracle IoT Cloud Service, enter your user name and password, and click Sign In.
- On the Oracle IoT Cloud Service home page, click Action
, select Devices, and then select Registration. Click Register Single Device.
Description of the illustration device_registration.png -
Enter the following values and click Register:
-
Activation ID:
JS-SIMULATOR-01
-
Activation Secret:
12345
-
Name:
JS-SIMULATOR-01
-
Manufacturer:
JS-SIMULATOR-01
-
Serial Number:
JS-SIMULATOR-01
-
Model Number:
JS-SIMULATOR-01
Description of the illustration single_device_registration.png -
Activation ID:
-
On the Registration Successful page, enter the file protection password twice and click Download Provisioning File.
Description of the illustration registration_successful.png - Move the
conf
file to the same directory as theDirectlyConnectedDeviceSample.js
file. - Click Finish.
Run the Simulator
-
In a command-line interface, browse to
DirectlyConnectedDeviceSample.js.
- Run the simulator and replace
password
with the value that you specified when you downloaded theconf
file.node DirectlyConnectedDeviceSample.js provisioning-file.conf password
- To stop the simulator, press Control+C.