Oracle by Example brandingQuick Start Tutorial Using a JavaScript Application

section 0Before 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?


section 1Install the JavaScript Client Software Library

  1. 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, and iotcs-csl-js-samples-release.zip, where release is the release and version number.
  2. Extract the contents of each of the zip files to My Documents directory.
  3. Browse to the My Documents\iot\csl\js subdirectory to verify the zip files.

section 2Installing Node.js with npm

  1. 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.
  2. Go to the installation location, C:\Program Files\nodejs, and verify that the contents of the folder are similar to the following screenshot:
    installed files of nodejs
    Description of the illustration nodeinstall_05.png
  3. 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
    
    command to install node modules using npm
    Description of the illustration nodeinstall_06.png
  4. Verify the installation by going to the C:\Program Files\nodejs\node_modules directory and ensure that it contains a node-forge, sqlite3 and debug directory.

section 3Set the Environment Variable

Set environment variable for the software that you installed, on your host system.

  1. From the Start menu, right-click Computer and select Properties.
  2. Under Control Panel Home, select Advanced system settings.
  3. In the System Properties dialog box, click the Advanced tab and then click Environment Variables.
  4. In the lower half of the Environment Variables dialog box (System variables), click New.
  5. 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.
    Specifying NODE_MODULES_PATH system variable
    Description of the illustration envwin_05.png
  6. Verify that the environment variable NODE_PATH is set. Restart any prompt windows opened.
  7. In the Environment Variables dialog box, click OK then in the System Properties dialog box,  click OK. Close the Control Panel window.

section 4Run the HelloWorld JS sample

  1. In your My Documents\iot\csl\js\samples directory, copy the JavaScript code file HelloWorldSample.js to create a basic simulator application.
  2. 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.
  3. 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>
  4. 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.
  5. Find your messages in the Messages table and verify that the message attribute's value has changed.
    Messages table
    Description of the illustration messages_table.png

more informationWant to Learn More?