How-To Guides
DeviceHub Guides

Use the Batch-Write Topic to Send Multiple Write Requests

6min
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 docid\ q9scssqe xxk9dg9by8vr 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 docid\ rfvijdxz7dbad8mwbisma and manage devices docid uc67yvju fop8hagr3bb 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 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 follow the steps to connect a device docid\ rfvijdxz7dbad8mwbisma for this use case, a simulator generator device is used follow the steps to add tags docid\ ioanzd2awqnkuppgee3eh 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 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 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 docid ol2gwhtg2gkdjlbr6cai 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 step 3 send batch data 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