---
title: Use the Batch-Write Topic to Send Multiple Write Requests
slug: litmusedge-v1/how-to-guides/devicehub-guides/batch-write-topic-guide
description: Learn how to use the Batch-Write topic. 
docTags: 
createdAt: 2023-09-07T17:25:48.503Z
---

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

You can use the Batch-Write topic to send multiple write requests simultaneously.&#x20;

:::hint{type="warning"}
**Important**:

- Only Gen 2 drivers can use batch-write topics. See the [Industrial Systems Connection Guide](docId\:x7F6RogWGUb9AiJkZ8aFr) to review available Gen 2 drivers.&#x20;
- This is only available for devices that don't select th&#x65;**&#x20;Enable Alias Topics** checkbox in the device configuration. You must use tags in the raw topic format. See [Connect a Device](docId:3eyAfPpweuVmBLCEy17sq) and [Manage Devices](docId\:p4VpVE-BxtLSJqn37yROr) for more information.&#x20;
:::

# Video

:::Iframe{iframeHeight="0" code="<iframe width=&#x22;560&#x22; height=&#x22;315&#x22; src=&#x22;https://www.youtube.com/embed/wU_gvFLplLQ?si=8D-EB7QE9YeYE0N4&#x22; title=&#x22;YouTube video player&#x22; frameborder=&#x22;0&#x22; allow=&#x22;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&#x22; allowfullscreen></iframe>"}

:::

# User Scenario

Litmus Edge collects process data on a PLC, and the setpoint values for the PLC are continuously re-calibrated. These new setpoints and other control values can be collected and sent in one request through the Batch-Write topic.&#x20;

# Set Up and Use the Batch-Write Topic

Complete the following tasks to use the Batch-Write topic.&#x20;

## Before You Begin

You will need the register IDs for the tags included in the batch write operation. If you don't have these values, you can get them by completing the steps in *Step 2: Configure Nodes* below.&#x20;

## Step 1: Set Up Flow Canvas

**To set up the Flow canvas:**

1. Follow the steps to [Connect a Device](docId:3eyAfPpweuVmBLCEy17sq). For this use case, a Simulator Generator device is used.&#x20;
2. Follow the steps to [Add Tags](docId:8sE7z3PmRfwL1nmzcwaLX) and create three tags with the following parameters.
   - **Name**: M - Memory Register
   - **Value Type**: int64
   - **Polling Interval**: 10
   - **Tag Name**: Enter a name for each tag.&#x20;
   - **Address**: Enter 1 for the first tag, 2 for the second, and 3 for the third.&#x20;
3. Navigate to **DeviceHub&#x20;**> **Devices**.&#x20;
4. In the Generator device tile, click the **Display Copy Options** icon and select the **Manage&#x20;**&#x74;opic. This will copy the PLC Manage topic. You will refer to this topic later on. Save (paste) this topic somewhere secure.

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/nk9-19PTw9RWUiepfqejr_copy-manage-topic.png" size="80" width="671" height="373" caption="The manage topic" position="center" showCaption="true"}
5. Copy the **Raw&#x20;**&#x54;opic. You will refer to this topic later on.&#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/4mjaEluZMCfFmxr6dFxqD_copy-device-raw-topic.png" size="80" width="668" height="385" caption="The device Raw Topic" position="center" showCaption="true"}
6. Navigate to **Flows Manager**.&#x20;
7. For a Flows Manager, click the **Go To Flow Definition** icon.&#x20;
   The Flow canvas opens in a new browser tab.&#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/kNr8nC8m2jwwx3dYuHdlR_use-case-5-pic.png" size="80" width="1017" height="493" caption="Go To Flow Definition icon" position="center" showCaption="true"}
8. On the Flow canvas, drag the **DataHub Subscribe** node and **debug&#x20;**&#x6E;ode on the canvas and connect them. Then, drag the **inject&#x20;**&#x6E;ode and the **DataHub Publish&#x20;**&#x6E;ode onto the canvas and connect them. &#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/Shx9UdNx5PcnpI-CzhyQX_batch-write-four-nodes.png" size="80" width="922" height="536" caption="Set up the four nodes for batch write" position="center" showCaption="true"}

You can now configure the nodes on the canvas.&#x20;

## Step 2: Configure Nodes

**To configure the nodes:**

1. Double-click the **DataHub Subscribe** node.&#x20;
   The *Edit DataHub Subscribe&#x20;*&#x6E;ode dialog box displays.
   - In the **Topic&#x20;**&#x66;ield, paste the Raw topic you copied previously.&#x20;
   - If needed, configure the Datahub Subscribe connection. See the *Step 3: Configure Connector Nodes* section in [Create a Flow](docId:7x0n7C4DxswTD61vpIBza) to learn more.
   - Click **Done**, and then click **Deploy**.&#x20;
2. Expand the message window beneath the flow.&#x20;

   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/lAkehfri9Opxk0GUaHv7B_batch-write-message-bar.png "The message window")
3. Click the **Debug&#x20;**&#x69;con to view debug messages.

   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/Y8QE7Chyax0W07kwl3TAd_batch-write-debug-icon.png "The debug icon")
4. If not already activated, click the debug button to activate it. Then, wait for the first debug message to appear.&#x20;

   ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/TAqS_cDsdu6eH-Xjxo-T4_batch-write-debug-button.png "The debug button")
5. When the first debug message displays, copy the **registerId&#x20;**&#x76;alues. You may need to wait about 10 seconds (as this was the set polling interval value) for the **registerId** values to show up. These are the register IDs for each tag you created. You will use these values to configure the inject node.&#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/-NxEO5h_sofYMNgurwu0s_batch-write-register-ids.png" size="80" width="1920" height="813" caption="Register IDs for tags" position="center" showCaption="true"}
6. Double-click the **inject&#x20;**&#x6E;ode.&#x20;
   - For **msg.payload**, update the **timestamp&#x20;**&#x73;election and select **string**.
   - In the **string&#x20;**&#x66;ield, enter the payload in the following format: `{"registerID_1": value_1, "registerID_2": value_2, "registerID_3": value_3}`. Keep in mind that the order of the register IDs you configure is based on the address values you configured for the tags. `value_1`, `value_2`, `value_3` can be replaced with any value of your choosing.
   - For example, for this use case, the payload will be: `{"C3E1CC7C-143F-46DA-BB70-C40196E56763": 11, "BE047C8C-875F-4D47-84AE-4D224733FE1D": 22, "BB1D6677-F4AE-41FD-A5AA-25E9E4AC7917": 33}`. The first register ID is the one configured with **Address&#x20;**&#x31; in the tag configuration, the second register ID is the one configured with **Address&#x20;**&#x32;, and the third register ID is the one configured with **Address&#x20;**&#x33;. `11`, `22`, `33` are values chosen for this example.
   - Click **Done**.&#x20;
7. Double-click the **DataHub Publish** node.&#x20;
   The *Edit DataHub Publish* node dialog box displays.
   - In the **Topic&#x20;**&#x66;ield, paste the Manage topic you copied previously. Then, replace `manage` in the topic with `batch_write`. For example, `devicehub.manage.0F992AC9-4A73-4D7A-8134-6AB374BBE628` is changed to `devicehub.batch_write.0F992AC9-4A73-4D7A-8134-6AB374BBE628`.
   - Click **Done**, and then click **Deploy**.&#x20;

You can now send the batch data to the device tags.&#x20;

## Step 3: Send Batch Data

**To send the batch data:**

1. Click the **inject&#x20;**&#x62;utton. This sends the data to all the tags configured in the inject node simultaneously. For this use case, the inject node sends the values 11, 22, and 33 to the three device tags.&#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/9hY_bkZ_RBmCL8J0Igo5i_batch-write-inject-button.png" size="80" width="1564" height="427" caption="The inject node button" position="center" showCaption="true"}
2. Wait up to 10 seconds for the next debug message. The three values display based on the **Address&#x20;**&#x61;nd **value&#x20;**&#x70;arameters you configured previously.&#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/5fUCh4bpouOO4c-SQosx3_batch-write-messages.png" size="80" width="1920" height="937" caption="The batch write messages" position="center" showCaption="true"}

