---
title: Use the Write Topic to Send Data to a PLC
slug: manufacturing-connect-edge-v2/use-the-write-topic-to-send-data-to-a-plc
docTags: 
createdAt: 2023-09-27T15:19:33.770Z
---

:::hint{type="info"}
**Notes**:

- You need to follow the following guidelines for topic names: [Subject-Based Messaging](https://docs.nats.io/nats-concepts/subjects).&#x20;
- 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&#x20;**&#x6E;ode.&#x20;
:::

The Write Topic allows you to write data to a PLC device.&#x20;

# 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.

# Set Up and Use the Write Topic

Complete the following steps to use the write topic based on the user scenario.&#x20;

**To use the Write topic:&#x20;**

1. Follow the steps to [Connect a Device](docId\:SqalV8ImyZmn8xA-56gno). For this use case, a Simulator Generator device is used.&#x20;
2. Follow the steps to [Add Tags](docId:-5nFrBQ-uriWOY3GACnPt) and create one tag with the following parameters.&#x20;
   - **Name**: M - Memory Register
   - **Value Type**: int64
   - **Polling Interval**: 5
   - **Tag Name**: Enter a name for the tag.&#x20;
   - **Address**: 1
3. Copy the topic name under the *RAW Topic* column. You will refer to this later.&#x20;
   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/aiNR0Swdjqr3QLiDUpd7T_mcecopytag.png "Copy tag icon")
4. Click th&#x65;**&#x20;Action menu** for the tag and select **View Write Topic**.&#x20;
   The Write dialog box displays.
   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/gLuWKguZdW7pY9dxHfZjV_mceviewwritetopic.png "View Write Topic option")
5. Click the **Copy&#x20;**&#x69;con for the tag. You will refer to this later.&#x20;
   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/41Ont8V0HwQW7Uv0gp-Oi_mcecopywritetopic.png)
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.
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/yByXgOI768OlHd37iwJey_go-to-flow-definitionmce.png" size="80" width="937" height="548" caption="Go To Flow Definition icon" position="center" showCaption="true"}
7. On the Flow canvas, drag the **inject&#x20;**&#x6E;ode and **DataHub Publish** node onto the canvas. Then, connect the two nodes.&#x20;
   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/yss_6il78powgyxnpFbEf_inject-and-publish-nodes.png" size="80" width="862" height="555" caption="The inject and DataHub Publish nodes" position="center" showCaption="true"}
8. Double-click the **DataHub Publish node**.&#x20;
   The *Edit DataHub Publish* node dialog box displays.&#x20;
   - In the **Topic&#x20;**&#x66;ield, paste the Write topic you copied previously (number 5).&#x20;
   - If needed, configure the Datahub Subscribe connection. See the *Step 3: Configure Connector Nodes* section in [Create a Flow](docId\:cvhYwrcRDrQPGReHBQNZ-) to learn more.&#x20;
   - Click **Done**.&#x20;
9. Double-click the **inject&#x20;**&#x6E;ode.
   The Edit inject node dialog box displays.&#x20;
   - For **msg.payload**, update the **timestamp&#x20;**&#x73;election and select **string**.&#x20;
   - In the **string&#x20;**&#x66;ield, enter **\{"value":114}**. This will insert the desired value into the tag payload.&#x20;
   - Click **Done**.&#x20;
10. Drag the **DataHub Subscribe** node and **debug&#x20;**&#x6E;ode to the canvas and connect them.&#x20;
    ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/OAfN2-c3z0Ul-GYSESEX4_flow2.png)
11. Double-click the **DataHub Subscribe** node.&#x20;
    The *Edit DataHub Subscribe* node dialog box displays.&#x20;
    - In the **Topic&#x20;**&#x66;ield, 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](docId\:cvhYwrcRDrQPGReHBQNZ-) to learn more.&#x20;
    - Click **Done**.&#x20;
12. Click **Deploy**.&#x20;
13. Expand the message window beneath the flow.&#x20;
    ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/B3upvjKwSjU23wU-3BbID_flow3.png)
14. Click the **Debug&#x20;**&#x69;con to view messages from the debug node.&#x20;
    ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/kNe096fxlBv6dmCVsHnRj_flow4.png)
15. Click the **inject&#x20;**&#x6E;ode button. This will insert the value (114) into the payload of the tag. Confirm you see the value in the debug window.&#x20;
    ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/05Efgq48b436G5slS_SVt_flow5.png)

