Skip to content

Provides examples of using the API of the IBM Bluemix IoT for Insurance service from Node.js

License

Notifications You must be signed in to change notification settings

fxulusoy/iot4i-api-examples-nodejs

 
 

Repository files navigation

IoT for Insurance API Examples#

The IoT4I API Examples provides examples of using the API of the IBM Bluemix IoT for Insurance service. The examples show how to register users, create devices, create shields and generate events using the REST API from a Node.JS environment.

Overview

The sample demonstrates the expected flow of the IoT for Insurance

  1. Create a user

  2. Create a device associated to the user

  3. Create a new shield

  4. Associate the shield with the user

  5. Simulate an event for the device

Requirements

To use this sample, you need:

  • IBM Bluemix account. Sign up for Bluemix, or use an existing account.
  • At least 2GB of memory available in your Bluemix organisation to provision the IoT for Insurance service and its dependencies

IoT for Insurance Architecture

To better understand this example and the IoT for Insurance API this section contains a brief overview of its architecture. IoT for Insurance Architecture

Component Description
API The entry point of the service. It allows developers to register devices, create users and monitor the behavior.
Action Engine Sends email and mobile notifications for events generated by the Shield Engine
Aggregator Periodically aggregates the data for display purposes in the Insurance Dashboard
Insurance Dashboard Provides visualization for the data
Shield Engine Rule Engine. Reads data from the IoT platform, runs the rules on it and if needed generates events for the Action Engine
Transformer provides cloud to cloud communication capabilities. Device data for registered devices is read from Wink and delivered into IoT platform

Run on Bluemix

  1. Create an IoT4Insurance on Bluemix
  2. Rename the service to iot4Insurance
  3. Use the button below to Deploy the examples on Bluemix via IBM Bluemix DevOps services

Deploy to Bluemix

Run locally

  1. If you do not already have a Bluemix account, sign up here

  2. If you have not already, download node.js and install it on your local machine.

  3. If you have not already, download Git and install it on your local machine.

  4. Clone the app to your local environment from your terminal using the following command:

git clone https://github.com/IBM-Bluemix/iot4i-api-examples-nodejs.git
  1. cd into this newly created directory

  2. Install the required npm and bower packages using the following command

npm install
  1. Create an IoT for Insurance service on Bluemix

  2. Use the Deploy button from the service console to deploy all the required application parts and depending services. This may take a few minutes. If you don't see the Deploy button, make sure your organization has at least 2GB of memory available.

  3. Update the credentials in config.js with the data available in the IoT4I Service Credentials page on Bluemix. The URI of the API looks like https://iot4insurance-api-<uuid>.mybluemix.net/ If running in a different region than US the URL will contain the region's name too.

NOTE: when copying the URI of the API in config.js make sure it does not contain a trailing /

NOTE: the aggregator URL listed in config.js is optional. The URL is not available in the Service Credentials and can be obtained from the Bluemix page of the aggregator application created by IoT4 for Insurance.

  1. Create a user. If successfull the application will print the details of the newly created record.
node createUser.js
  1. Create a shieled.If succesfull the application will print the details of the newly created record.
node createShield.js
  1. Attach the shield code to your newly created shield. The command will use the source code from the resources/shieldCode.js file
node createShieldCode.js
  1. Associated the newly created shield with the user.
node createUserShieldAssociation.js
  1. Generate a hazard event for your user. This simulates a message sent by the sensors installed in the user's home. The message is routed through the IoT Platform service and is processed by the Shield created and registered for the user.
node simulateHazard.js
  1. Open the Insurance Dashboard and search for the newly created user.

Code Structure

The primary purpose of this demo is to document the usage of the IoT for Insurance API. You can use the access methods (createUser, createDevice) and the helper functions (csrfRequest) as starting points for your integration.

File Description
config.js Contains the connection URI and credentials. This must be updated to match your IoT4I Deployment
createDevice.js Shows how to create a device.
createHistoricalData.js Shows how to use the historian service API to generate historical data.
createPromotion.js Shows how to use create promotions visible to end users in the mobile application.
createShield.js Shows how to add a shiled in the system.
createShieldCode.js Shows how to associate JavaScript code to a shield.
createUser.js Shows how to register a new user in the system.
createUserShieldAssociation.js Shows how to associate a shield to a user.
csrfRequests.js Helper functions for adding the CSRF tokens to the POST/PUT requests.
readShield.js Shows how to read shield information.
readUser.js Shows how to read user information.
readUserShieldAssociation.js Shows how to read user and shield associations.
simulateHazard.js Helper tool for simulating device events in the absence of actual sensors.

For more information on the notion of shield please see the IoT for Insurance Documentation

Contribution

We are more than happy to accept external contributions to this project, be it in the form of issues and pull requests. If you find a bug, please report it via the issues section or even better, fork the project and submit a pull request with your fix! Pull requests will be evaluated on an individual basis based on value add to the sample application.

License

This sample code is licensed under Apache 2.0. See the license file for more information.

About

Provides examples of using the API of the IBM Bluemix IoT for Insurance service from Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 87.8%
  • CSS 6.6%
  • HTML 5.6%