Overview

Skill Level: Any Skill Level

Beginner

Ingredients

  1. IBM Bluemix account
  2. Eclipse with Maven Plug-in
  3. JDK 7

Step-by-step

  1. Introduction

    We have made changes in the existing java client library for Watson IoT Platform to register and simulate multiple devices.

    You need to make changes to the code to provide device type under which you want to register and simulate devices.

    You will have the option to provide no of device that you want to register and simulate. It will create device type and then devices in Watson Iot Platform service and publish events continuously for each device.

    Note: You can deploy this as a standalone Java application on bluemix so that you can just start the application to get the required feeds continuously from multiple simulated devices.

  2. Running Multiple Device Simulation Application on Eclipse

    1. Open Eclipse

    2. Import the Device simulation code project provided here:

    https://hub.jazz.net/project/utdixit1/IOTMultiDevicesSimulation/overview

    You can download the code as zip in your workstation and then import it or you can directly import it from git

    using eclipse .

    Here is the git url:

    https://hub.jazz.net/git/utdixit1/IOTMultiDevicesSimulation

    3. Then select the project and expand and open IoTDevices.java under src-> deviceSimulation

    Look for org, type, no of devices and change them to match your device type and org.

    You also need to provide Watson API key and token credentials in the code.

    Launch Watson IoT platform dashboard

    Navigate to the Access section, choose api-keys tab and then click on Generate API Key to generate a new set of API Key, that shall be used as access credentials in the application samples. You could find more details under this Recipe about how to generate API key.

    After you get API key and token you can update following snippet of code:

     


    byte[] encoding = Base64.encodeBase64(new String("API-key" + ":" + "Token").getBytes() );

    String encodedString = new String(encoding);

    httpPost.addHeader("Authorization", "Basic " + encodedString);

    You have to replace API key and token under RegisterDevices and Devicetype function in IoTDevices.java

    After making all the changes you can run it as Java Application

     IOTMultiDeviceSimulation -> Run As -> Java Application

    This will create WaterPump device type and then create 10 devices under WaterPump devicetype.

    You can change no of devices to simulate as many devices as you want.

    You can also check events being published in Watson IoT Platform service under Device tab.

    Click on any device that you see under device tab to check the events.

  3. Deploy this Application on bluemix

    If you want to deploy this application on bluemix and generate device events continuously then here are the steps to follow:

    Go to this link

    https://hub.jazz.net/project/utdixit1/IOTMultiDevicesSimulation/overview

    You will get the option to Fork the project. Fork it and create a new git repository for this project.

    It will ask for project name and allow you to choose organization and space.

    Once the repository gets created then click on Edit code and make similar changes to IoTDevices.java as described above.

    Look for org, type, no of devices and change them to match your device type and org.

    You also have to replace API key and token under RegisterDevices and Devicetype function in IoTDevices.java

    After making all changes Click File -> Save to save the changes,

    Click on Git icon, provide a commit message and click Commit button to commit the changes

    Click Push button to push the changes to the main branch.

    After changes being pushed click on Build & Deploy tab.

    Create Build and Deploy stages.

    Configure Build stage

    Configure Deploy stage

    You have to change organization, space and application name with your own information.

    After you have configured both Build and Deploy stage then run the build stage and your

    application will be deployed on bluemix.

    Note: This application currently creates waterpump devicetype and then publish temp, pressure, energy consumption and water usage data parameters from each simulated sensor. If you are interested in changing data parameters based on your device type then you have to make changes in DeviceClient.java under src directory.

Join The Discussion