Use the Batch-Write Topic to Send Multiple Write Requests
7 min
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.
You can use the Batch-Write topic to send multiple write requests simultaneously.
Important:
- Only Gen 2 drivers can use batch-write topics. See the Industrial Systems Connection Guide to review available Gen 2 drivers.
- This is only available for devices that don't select the Enable Alias Topics checkbox in the device configuration. You must use tags in the raw topic format. See Connect a Device and Manage Devices for more information.
Video
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.
Set Up and Use the Batch-Write Topic
Complete the following tasks to use the Batch-Write topic.
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.
Step 1: Set Up Flow Canvas
To set up the Flow canvas:
- Name: M - Memory Register
- Value Type: int64
- Polling Interval: 10
- Tag Name: Enter a name for each tag.
- Address: Enter 1 for the first tag, 2 for the second, and 3 for the third.
- Navigate to DeviceHub > Devices.
- Navigate to Flows Manager.
You can now configure the nodes on the canvas.
Step 2: Configure Nodes
To configure the nodes:
- Double-click the DataHub Subscribe node. The Edit DataHub Subscribe node dialog box displays.
- In the Topic field, paste the Raw topic you copied previously.
- If needed, configure the Datahub Subscribe connection. See the Step 3: Configure Connector Nodes section in Create a Flow to learn more.
- Click Done, and then click Deploy.
- Double-click the inject node.
- For msg.payload, update the timestamp selection and select string.
- In the string field, 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 1 in the tag configuration, the second register ID is the one configured with Address 2, and the third register ID is the one configured with Address 3. 11, 22, 33 are values chosen for this example.
- Click Done.
- Double-click the DataHub Publish node. The Edit DataHub Publish node dialog box displays.
- In the Topic field, 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.
You can now send the batch data to the device tags.
Step 3: Send Batch Data
To send the batch data:








