Connect real-world industrial devices to IBM Watson IoT

Posted by Selam Shimelash on Sep 30, 2016 11:56:13 AM

Opto 22 SNAP-PAC-R1 programmable automation controller with built-in RESTful APIIf you've heard about our Opto 22 SNAP PACs with their built-in RESTful API (application program interface), you may be wondering how you'd use that API to send real-world data to the IBM Watson IoT platform.  

I'll show you how, step-by-step, in this blog post. It's a long post, but it includes everything you'll want to know.

What you’ll need:

  • An org account with IBM Bluemix. Follow the steps on the screen to create one.
  • An Opto 22 SNAP PAC controller with firmware version R9.5a or higher, with its RESTful server enabled. In this example, we’re communicating with a SNAP-­PAC-­R1 that’s part of a SNAP­-PACLC Learning Center. This Learning Center hardware also includes a temperature probe.
  • A Node­-RED flow to connect the Opto 22 hardware to an IBM device.

What you'll do (detailed steps below):

1. Configure the Opto 22 PAC Hardware
2. Create a device in IBM Watson IoT platform
3. Configure the Node­-RED flow to connect the Opto 22 PAC to IBM Watson
4. Deploy Node-RED and check out your data in the IBM cloud!

1. Configure the Opto 22 PAC Hardware 

  • Assemble and program the SNAP­-PAC­-R1 as described in the SNAP PAC Learning Center User’s guide, Opto 22 form 1638.

Note: for this example, we re­named the temperature input in the control strategy from Store_Temperature to Lamp_Temperature. We also added an output to turn on a Lamp so we could remotely increase that temperature by turning on the lamp. While this post only describes how to read/monitor the temperature, you can also control an output, such as turning on the lamp, via similar steps.

  • Follow SNAP PAC REST API Quick Start steps on to configure the controller to use the API.

2. Create a Device in IBM Watson IoT Platform

  • Quickstart is the easiest and fastest way to see data in the IBM IoT platform without registering a device or creating a logon account. Simply click this link and copy the device ID that will later be used in the Watson node when creating a Node-RED flow.
  • Or to register a device, log onto IBM Watson IoT Platform.
  • Click Bluemix Standard, shown on the top right-hand corner of the screen, under your logon account.


  • Click Devices from the list


  • Click Add Device.
  • Click Create type. The device type name is used to identify the device type uniquely. Follow the screen to define template and attributes for the device.
  • Once the device type is created, click Next to create a Device ID. A Device ID can be any name for the sensor to identify what the device is.
  • Click Next until you reach the security screen, where the authentication token is generated. Click Next again to auto-generate a token and add the device.

When you are done, you will see a screen similar to the one shown below. Save this screen by taking a screen capture, since you won’t be able to get the token back if lost.



3. Configure the Node-­RED flow to connect the Opto 22 SNAP PAC to Watson IoT node

  • Install Node­-RED, including the SNAP PAC Nodes, as described on this Node­RED for SNAP ­PAC page. This includes the controller configuration to enable the RESTful server which the SNAP PAC Node­-RED nodes use to read or write to the SNAP ­PAC controller.
  • Install Node-­RED Watson IoT node (wiotp) from or copy paste the following on your Node.js command prompt
  • npm install node-red-contrib-ibm-watson-iot
  • Create a flow using the inject, snap pac read and Watson IoT output nodes.


  • In the inject node, choose how often to send data. Select an interval or none to send only once.


In the snap pac read node:
  • Add your SNAP PAC controller using its IP address or hostname. Enter the key ID and value pair you selected for your controller when you enabled the RESTful interface.
  • Unless you're using an SSL certificate, select HTTP from the dropdown menu. 


  • After the SNAP PAC controller is added, choose the data type and the tag name for the point you want to see in the Watson IoT platform. You'll find the tag name in the PAC Control strategy running on the Learning Center.


In the Watson IoT node:

  • Connect as Device. If you are using the Quickstart, choose quick start and enter the quick start ID, leave the event type as event and the format as JSON. But if you have created a device, select Registered.
  • Click Credential and enter the organization ID, device type, device ID, and token. You'll find all of this information on the screen shot you saved after creating a device and generating a token.
  • Click Update.
  • Leave Event type as event and Format as JSON.




4. Deploy Node-RED and check out your data in the IBM cloud! 

  • Click Deploy.
  • Click the inject button.
  • Open the Watson IoT platform if it’s not already.
  • Click Devices. The device or devices you created appear here.


  • Double-click the Device ID LampTemperature to see information on the device (connection information, recent events, errors, etc.). Scroll down to Sensor Information to see the data for LampTemperature from the SNAP PAC controller.
  • Create cards in the Watson IoT platform to see your data trend or to create a visually pleasing dashboard.
  • Click Boards in the top-left corner.


  • Create a new board.
  • Double-click the board you created.
  • Click Add new card. Here you have some options (gauge, line graph, bar graph etc.) to present the data.
  • Click line graph.
  • Select your device ID.


  • Click Next.
  • Click Connect new dataset.
  • Leave Event as event and Property as value.
  • Name the point, choose the type and engineering unit, precision, min and max.


  • Click Next. You should see the line graph with the data on it. Under Settings you can make the graph small, medium, or large. On the next screen you have options for color.
  • Click Next and give it a title.
  • Click submit.



What's next?

You can similarly get data from other input points and signals on the SNAP PAC Learning Center (try the Fuel Level as shown above).

Also, try using the tools in Watson to trigger an output point on the SNAP PAC Learning Center.

Further, IBM Bluemix and Watson have a host of tools that allow you to gather data, visualize patterns, advance to analytics, and ultimately make better business decisions. 

Bottom Line:

Opto 22’s SNAP PAC and IBM Bluemix are the perfect combination to deploy in industrial IoT applications for increased business intelligence.

See SNAP PAC controllers—industrially hardened, small-footprint programmable automation controllers that communicate over standard Ethernet networks using TCP/IP, with a built-in HTTP/HTTPS server and a RESTful API

See SNAP PAC controllers

Topics: Internet of Things, IoT, PACs, API, REST API, RESTful server, REST

Subscribe to Email Updates

Posts by Topic

see all

Follow Me