---
title: Use the Write Topic to Send Data to a PLC
slug: bhdo-v3/use-the-write-topic-to-send-data-to-a-plc
createdAt: 2023-09-27T17:07:41.846Z
---

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

# 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\:AVTs_R7RjIdM9g7LSawjm). For this use case, a Simulator Generator device is used. Click the checkbox for **Enable alias topics**.&#x20;
2. Follow the steps to [Add a Tag](docId\:CsrurTOACnmmAMyN_uC5o) 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/vAqK-046vdh4I0e1y9cfX/jx1rHgXJfu6oXqZbuAWXp_bhdocopytag.png "Copy tag icon")
4. Click the **Action menu** for the tag and select **View Write Topic**.&#x20;
   The *Write* dialog box displays.

   ![](https://api.archbee.com/api/optimize/vAqK-046vdh4I0e1y9cfX/XRQQW8edJHIit1wUMt3aV_bhdoviewwritetopic.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/vAqK-046vdh4I0e1y9cfX/D_wPRpI-T3QSQbHY4pHD1_bhdocopywritetopic.png "Copy icon for Write topic")
6. Navigate to **Flows Manager**. For a Flows Manager, click the **Go To Flow Definition** icon.&#x20;
   The Flow canvas opens in a new browser tab.

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/DTraaEexmGJNFjyI4mlDh_go-to-flow-definitionbhdo.png" size="80" width="931" height="481" position="center" caption="Go To Flow Definition icon" 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;

   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/NVB_Ibwtx1yNe01-rswWG_inject-and-publish-nodes.png)
8. Double-click the **DataHub Publish&#x20;**&#x6E;ode.&#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\:CrMXrOqTwtycjCddtoaHD) 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/vAqK-046vdh4I0e1y9cfX/cmBKkfGMlw3271N_Rfjt2_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\:CrMXrOqTwtycjCddtoaHD) 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/vAqK-046vdh4I0e1y9cfX/woRka6vsjqXH6vyk3rb_M_flow3.png)
14. Click the **Debug&#x20;**&#x69;con to view messages from the debug node.&#x20;

    ![](https://api.archbee.com/api/optimize/vAqK-046vdh4I0e1y9cfX/uONqtt_ITQGccj5-6bc-2_flow4.png "Debug icon")
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/vAqK-046vdh4I0e1y9cfX/IpqI394J_yHe8wJ7CWJeq_flow5.png)

