Overview

Skill Level: Intermediate

It helps to be familiar with the IBM Watson IoT Platform service and how to register devices.

KEPServerEX from Kepware is a popular connectivity gateway for industrial automation devices. It provides a plug-in called "IoT Gateway" that enables users to forward industrial device data from PLCs and OPC servers to the IBM Cloud using MQTT.

Ingredients

1.  IBM Cloud account:  https://console.bluemix.net/

2.  KEPServerEX installed with the IoT Gateway plug-in:  https://www.kepware.com/en-us/products/kepserverex/advanced-plug-ins/iot-gateway/

3.  An instance of the IBM Watson IoT Platform service:  https://console.bluemix.net/catalog/starters/internet-of-things-platform-starter  

Step-by-step

  1. Register your KEPServerEX server with Watson IoT Platform and acquire device credentials

    1. Launch your Watson IoT Platform Service and navigate to the Devices page using the “DEVICES” tab.¬†¬†Devices1
    2. Click the “+ Add Device” button to add a new device.
    3. Click the “+ Add Type” button to add a new type.
    4. Give the type a name, for example “KEPServerEX” and then click “Add.”Devices2
    5. Give the device an ID, for example “MyKEPServerEX” and then click “Next.”Devices3
    6. Continue clicking “Next” a few more times until you reach the summary and then click “Done.”¬† IMPORTANT:¬† After clicking “Done” the next view will show the “Device Credentials.”¬† Make sure you copy these credentials and store them somewhere so that you can access them again.¬† Once you leave this view, you will not be able to get them back.¬†¬†Devices4
  2. Configure the KEPServerEX IoT Gateway Plug-in

    1. Open KEPServerEX and select “Add Agent…” under the “IoT Gateway” in the left hand project browser.¬† Give the agent a name such as “IBM Cloud” and select “MQTT Client” in the type drop down list.¬† Then select “Next.”¬†¬†kepware1
    2. In the “MQTT Client – Broker” dialog, enter the URL, Topic and Timeout.¬† The URL should be in the format like the following:¬† ssl://<orgid>.messaging.internetofthings.ibmcloud.com:8883¬† ¬†The¬†<orgid> is your Organization ID from your Waton IoT Platform device credentials obtained in step one of this recipe.¬† The topic should be in the format:¬† iot-2/evt/<event name>/fmt/json¬† ¬†The¬†<event name> is the name of the event you want sent to Watson IoT Platform.¬† For example, “status.”¬† Lastly, put 60 for the timeout field and then click “Next.”¬†¬†kepware2
    3. In the MQTT “Client – Security” dialog, enter the Client ID, Username and Password.¬† The Client ID is in the following format:¬† d:<orgid>:<device Type>:<device ID>¬† ¬†You can get your¬†<orgid>, <device Type> and <device ID> from your device credntials obtained in step one of this recipe.¬† The username should be “use-token-auth” and your password should be your Authentication Token from your device credntials obtained in step one of this recipe.¬† Lastly, click “Finish” to complete the agent.¬† ¬†kepware3
    4. We need to change one more setting before the agent is complete.¬† Double-click on your new IoT Gateway agent in the project borwser.¬† Switch to the “Security” section and select “v1.2” as the TLS Version.¬† Then click “OK.”¬†¬†kepware4

    If successful, you should eventually see something like the following in the KEPServerEX Event Log window:

    “MQTT agent ‘IBM Cloud’ is connected to broker ‘ssl://u87tmj.messaging.internetofthings.ibmcloud.com:8883′”

  3. Add some simulated tags to the IoT Gateway and view events in Watson IoT Platform

    1. Now we need to add some simulated tags to send from the KEPServerEX server to the IBM Watson IoT Platform.¬† With the new IoT Gateway agent selected in the KEPServerEX project browser, click on “Add IoT items…” in the right side pane.¬† This will bring up the “Tag Browser.”¬† In the Tag Browser left side navigation pane, select the “Functions” node under “Simulation Examples.”¬† This will bring up the tags in the right side pane.¬† Select tags “Ramp2” and “User3.”¬† Then click “Apply.”¬†¬†kepware5
    2. In the “IoT Items” dialog, leave the defaults and click “OK.”¬†¬†kepware6
    3. You should now see the two tags added to your IoT Gateway agent.  kepware7
    4. Once the tags are added, the IoT Gateway agent will begin to send the simulated data to Watson IoT Platform every 10 seconds.¬† To view the incoming messages on IBM Cloud, Navigate to your Watson IoT Platform service “DEVICES” tab.¬† Your device should have a small green dot next to it to denote that it is connected.¬† If not, recheck the KEPServerEX event log to ensure there are no connection errors.Devices5
    5. Click on the device and switch to the “Recent Events” tab to view incoming messages.¬† You should see messages coming in about every 10 seconds.¬†¬†Devices6
    6. Lastly, you can click on the message itself to view the raw JSON payload.  Devices7
  4. Summary

    In this recipe you learned how to connect a Kepware KEPServerEX to the IBM Watson IoT Platform using MQTT.  Now that the data is flowing to the IBM Cloud, there is a whole catalog of micorservices you can use to make use of that data.  Looking for an end-to-end IoT solution that will help you get jumpstarted in days?  Take a look at the IBM IoT Connection Service:  https://www.ibm.com/support/knowledgecenter/en/SSQP8H/iot-connected-products/kc_welcome.htm.  This managed service offering from IBM provides the IoT Platform service as well as security, data lifecycle management and analytics. 

    If you have any questions or issues with this recipe, please post comments below.

2 comments on"Connect a Kepware KEPServerEX to IBM Watson IoT Platform"

  1. MayssaBenJmaa March 01, 2019

    Hi all ,
    I have faced a problem when connecting KEPServerEx 6 to IBM watson IOT platform .
    I have already followed the steps mentioned below : https://developer.ibm.com/recipes/tutorials/connect-a-kepware-kepserverex-to-ibm-watson-iot-platform/
    At first, I have faced 2 errors :
    1)Error KEPServerEX\IoT Gateway Failed to launch IoT Gateway: no suitable 32-bit JRE was configured or found.
    2)Error IoT Gateway Failed to connect to server: ‘127.0.0.1:57212’. Please verify this connection information is correct and that the host can be reached.
    Although I have managed to fix them, the connexion didn’t happen .
    The device created is not connected and the event is not created.
    I would be grateful if you could help me in this regard.

Join The Discussion