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.
- 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.
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.
Complete the following tasks to use the Batch-Write topic.
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.
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.
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. You will refer to this topic later on.
Copy the Raw Topic. This will copy the RAW topic. You will refer to this topic later on.
- Navigate to Flows Manager.
For a Flows Manager, click the Go To Flow Definition icon. The Flow canvas opens in a new browser tab.
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.
You can now configure the nodes on the canvas.
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.
Expand the message window beneath the flow.
Click the Debug icon to view debug messages.
If not already activated, click the debug button to activate it. Then, wait for the first debug message to appear.
When the first debug message displays, copy the registerID values. 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.
- 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.
To send the batch data:
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.
Wait up to 10 seconds for the next debug message. The three values display based on the Address and value parameters you configured previously.