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 docid 8o4ksduafz6jcegj0whs4 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 docid\ ish7bqhzxswtdx8vbnszb and manage devices docid\ esazv soo0efdw5 ivc6y 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 docid\ ish7bqhzxswtdx8vbnszb 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 docid\ xgwokqbtpevii7or82ll0 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 in the generator device tile, click the display copy options icon and select the manage topic this will copy the plc manage topic save (paste) this topic somewhere secure copy the alias topic you will refer to this topic later on save (paste) this topic somewhere secure 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 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 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 docid\ veyyte7xdcangglzbqya0 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 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