How-To Guides
DeviceHub Guides

Use the Batch-Write Topic to Send Multiple Write Requests

11min

Notes:

  • You need to follow the following guidelines for topic names: Subject-Based Messaging.
  • 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

Manufacturing Connect 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:

  1. Navigate to DeviceHub > Devices.
  2. In the Generator device tile, click the Action menu, click Copy Topics, and then select the Manage topic. This will copy the Manage status topic. Save (paste) this topic somewhere secure.

    Document image
    
  3. Copy the Alias topic. You will refer to this topic later on. Save (paste) this topic somewhere secure.

    Document image
    

Step 4: Create Flow

You will now create the Flow that will set up the batch-write topics.

To set up the Flow canvas:

  1. Navigate to Flows Manager.
  2. For a Flows Manager, click the Go To Flow Definition icon. The Flow canvas opens in a new browser tab.

    Go To Flow Definition icon
    Go To Flow Definition icon
    
  3. On the Flow canvas, drag the DataHub Subscribe node and debug node on the canvas and connect them. Then, drag the inject node and the DataHub Publish node onto the canvas and connect them.

    Set up the four nodes for batch write
    Set up the four nodes for batch write
    
  4. 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.
  5. 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 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.
  6. 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 3: Send Batch Data

To send the batch data:

  1. Click the inject button. 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.

    The inject node button
    The inject node button
    
  2. Wait up to 10 seconds for the next debug message. The three values display based on the Address and value parameters you configured previously.

    The batch write messages
    The batch write messages