Use the Write Topic to Send Data to a PLC
Notes:
- 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.
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.
Complete the following steps to use the write topic based on the user scenario.
To use the Write topic:
- Name: M - Memory Register
- Value Type: int64
- Polling Interval: 5
- Tag Name: Enter a name for the tag.
- Address: 1
Copy the topic name under the RAW Topic column. You will refer to this later.
Click the Action menu for the tag and select View Write Topic. The Write dialog box displays.
Click the Copy icon for the tag. You will refer to this later.
Navigate to Flows Manager. For a Flows Manager, click the Go To Flow Definition icon. The Flow canvas opens in a new browser tab.
On the Flow canvas, drag the inject node and DataHub Publish node onto the canvas. Then, connect the two nodes.
- 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 Subscribe connection. See the Step 3: Configure Connector Nodes section in Create a Flow to learn more.
- Click Done.
- 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.
Drag the DataHub Subscribe node and debug node to the canvas and connect them.
- 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.
- Click Deploy.
Expand the message window beneath the flow.
Click the Debug icon to view messages from the debug node.
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.