Use the Batch-Write Topic to Send Multiple Write Requests
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.
- If Enable Alias Topics is selected in the device configuration, then the DeviceName and TagName parameters need to be used for setting up batch-write topics. If Enable Alias Topics is not selected, then deviceID and registerID need to be used. See Connect a Device and Manage Devices for more information.
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
We will be using the DeviceName and TagName parameters to set up the device. If you don't enable Alias topics for the device, you will need to use the deviceID and registerID parameters. To get the registerIDs, you will need to set up a flow and view the payload of the device.
Step 1: Connect Device
Follow the steps to Connect a Device and configure the following parameters:
- Device Type: Simulator
- Driver Name: Generator
- Enable Alias Topics: Select the checkbox.
Step 2: Add Tags
After connecting the device, add the following tag. See Add Tags to learn more.
Tag 1
- Name: Select M - Memory Register
- Value Type: Select int64
- Polling Interval: Enter 10
- Tag Name: Enter Tag_1
- Address: Enter 1
Tag 2
- Name: Select M - Memory Register
- Value Type: Select int64
- Polling Interval: Enter 10
- Tag Name: Enter Tag_2
- Address: Enter 2
Tag 3
- Name: Select M - Memory Register
- Value Type: Select int64
- Polling Interval: Enter 10
- Tag Name: Enter Tag_3
- Address: Enter 3
Step 3: Collect Topic Names
You will need to copy and store the Manage topic and Alias topic for the device. You will use these topic names later on.
To collect the topic names:
- Navigate to DeviceHub > Devices.
Step 4: Create Flow
You will now create the Flow that will set up the batch-write topics.
To create the Flow:
- Navigate to Flows Manager.
- Double-click the DataHub Subscribe node. The Edit DataHub Subscribe node dialog box displays.
- In the Topic field, paste the Alias 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: {"TagName_1": value_1, "TagName_2": value_2, "TagName_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: {"Tag_1": 11, "Tag_2": 22, "Tag_3": 33}. The first tag name is the one configured with Address 1 in the tag configuration, the second tag name is the one configured with Address 2, and the third tag name 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.Simulator is changed to devicehub.batch_write.Simulator.
- Click Done, and then click Deploy.
You can now send the batch data to the device tags.
Step 5: Send Batch Data
To send the batch data:





