How-To Guides
DeviceHub Guides

Use the Write Topic to Send Data to a PLC

3min

Notes:

  • You need to follow the following guidelines for topic names: Subject-Based Messaging.
  • When publishing structured data such as JSON, you must convert to a byte array (string) first. To do this in a flow, you can use the json node.

The Write Topic allows you to write data to a PLC device.

Video



User Scenario

In your production environment one of the sensors that a PLC uses malfunctions, causing the PLC to receive inaccurate data. While waiting for the sensor to be repaired, you input a value manually to simulate the correct sensor data.

Use the Write Topic

Complete the following steps to use the write topic based on the user scenario.

To use the Write topic:

  1. Follow the steps to Connect a Device. For this use case, a Simulator Generator device is used.
  2. Follow the steps to Add Tags and create one tag with the following parameters.
    • Name: M - Memory Register
    • Value Type: int64
    • Polling Interval: 5
    • Tag Name: Enter a name for the tag.
    • Address: 1
  3. Copy the topic name under the RAW Topic column. You will refer to this later.

    Copy tag icon
    Copy tag icon
    
  4. Click the Action menu for the tag and select View Write Topic. The Write dialog box displays.

    View Write Topic option
    View Write Topic option
    
  5. Click the Copy icon for the tag. You will refer to this later.

    Copy Write topic icon
    Copy Write topic icon
    
  6. Navigate to Flows Manager. For a Flows Manager, click the Go To Flow Definition icon. The Flow canvas opens in a new browser tab.

    Go To Flow Definition icon
    Go To Flow Definition icon
    
  7. On the Flow canvas, drag the inject node and DataHub Publish node onto the canvas. Then, connect the two nodes.

    The inject and DataHub Publish nodes
    The inject and DataHub Publish nodes
    
  8. Double-click the DataHub Publish node. The Edit DataHub Publish node dialog box displays.
    • In the Topic field, paste the Write topic you copied previously (number 5).
    • If needed, configure the Datahub Publish connection. See the Step 3: Configure Connector Nodes section in Create a Flow to learn more.
    • Click Done.
  9. Double-click the inject node. The Edit inject node dialog box displays.
    • For msg.payload, update the timestamp selection and select string.
    • In the string field, enter {"value":114}. This will insert the desired value into the tag payload.
    • Click Done.
  10. Drag the DataHub Subscribe node and debug node to the canvas and connect them.

    Document image
    
  11. Double-click the DataHub Subscribe node. The Edit DataHub Subscribe node dialog box displays.
    • In the Topic field, paste the topic name you copied previously (number 3).
    • If needed, configure the Datahub Subscribe connection. See the Step 3: Configure Connector Nodes section in Create a Flow to learn more.
    • Click Done.
  12. Click Deploy.
  13. Expand the message window beneath the flow.

    Document image
    
  14. Click the Debug icon to view messages from the debug node.

    Document image
    
  15. Click the inject node button. This will insert the value (114) into the payload of the tag. Confirm you see the value in the debug window.

    Document image