Before You Begin
This 15-minute tutorial shows you how to build a JavaScript application that simulates a virtual device and sends a message to Oracle Internet of Things (IoT) Cloud Service.
Background
Oracle IoT Cloud Service provides communication services between devices and enterprise applications. In this tutorial, you build a simulated device in a JavaScript application, and then transmit a Hello World message to Oracle IoT Cloud Service.
What Do You Need?
- Access to the Oracle IoT Cloud Service
- A computer running Windows 7 OS with a web browser
- Download the following software: Node.js with npm and save in a directory, for this tutorial we are using the
My Documents
folder - This JavaScript code file:
HelloWorldSample.js
- The latest version of the JavaScript Client Software Library from Oracle Technologies Network
- Firefox or Chrome web browser
- Complete the following tutorial: Configuring an Application in Oracle Internet of Things Cloud Service
Install the JavaScript Client Software Library
- In a web browser, open the Oracle IoT Cloud Service Client Software Library site, find and download the latest Client Software Library for JavaScript binary, source code and samples zip files:
iotcs-csl-js-bin-release.zip
,iotcs-csl-js-src-release.zip
, andiotcs-csl-js-samples-release.zip
, whererelease
is the release and version number. -
Extract the contents of each of the zip files to
My Documents
directory. -
Browse to the
My Documents\iot\csl\js
subdirectory to verify the zip files.
Installing Node.js with npm
-
Browse to the directory where you downloaded the windows installer package:
node-version-x64.msi
and double click on it, then follow the steps in the Node.js Setup wizard. -
Go to the installation location,
C:\Program Files\nodejs
, and verify that the contents of the folder are similar to the following screenshot:Description of the illustration nodeinstall_05.png - Open a command prompt in administrator mode by clicking on Start menu -> Accessories -> right click on
Command Prompt
, then select Run as administrator and enter the following commands, one at a time, to install the required node modules:npm install -g node-forge npm install -g sqlite3 npm install -g debug
Description of the illustration nodeinstall_06.png - Verify the installation by going to the
C:\Program Files\nodejs\node_modules
directory and ensure that it contains anode-forge
,sqlite3
anddebug
directory.
Set the Environment Variable
Set environment variable for the software that you installed, on your host system.
- From the Start menu, right-click Computer and select Properties.
- Under Control Panel Home, select Advanced system settings.
- In the System Properties dialog box, click the Advanced tab and then click Environment Variables.
- In the lower half of the Environment Variables dialog box (System variables), click New.
-
In the New
System Variable dialog box, enter
NODE_PATH
in the Variable name field, and enter the full path (C:\Program Files\nodejs\node_modules
) of your node modules in the Variable value field, then click OK.Description of the illustration envwin_05.png -
Verify that the environment variable
NODE_PATH
is set. Restart any prompt windows opened. - In the Environment Variables dialog box, click OK then in the System Properties dialog box, click OK. Close the Control Panel window.
Run the HelloWorld JS sample
-
In your
My Documents\iot\csl\js\samples
directory, copy the JavaScript code fileHelloWorldSample.js
to create a basic simulator application. -
Copy the Provisioning file obtained from the Configuring an Application in Oracle Internet of Things Cloud Service tutorial referred in the What Do You Need section, to the same directory as the
HelloWorldSample.js
file. -
Open a command prompt and run the following command in the same directory, replacing
<file protection password>
with the password you used to create the provisioning file.run-device-node-sample.bat HelloWorldSample.js <provisioning.file> <file protection password>
- In the Oracle IoT Cloud Service Management Console, navigate to the Oracle IoT Asset Monitoring application, select Data, and then in Filter By, select Device.
-
Find your messages in the Messages table and verify that the message attribute's value has changed.
Description of the illustration messages_table.png