How-To Guides
Flows Guides

Save Multiple Register Values to a CSV File

8min
you can use flows to save multiple register values to a csv file on your edge device user scenario in an industrial environment, engineers must keep a close eye on the performance of different machines in a factory to achieve this, they collect raw data at regular intervals from various programmable logic controller (plc) registers this data can be aggregated, saved in a file, and used by other applications using flows even if the collection intervals differ, the data can be conveniently accessed using global variables by analyzing this data, engineers can make informed decisions to improve the productivity of the factory step 1 add a 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 tags docid\ xgwokqbtpevii7or82ll0 to the device each tag will collect data from different types of inputs tag 1 input1 name select s random value generator value type select int64 polling interval enter 5 tag name enter input1 tag 2 input2 name select s random value generator value type select float64 polling interval enter 5 tag name enter input2 click the copy icon to copy the raw topic of both tags you created store them securely as you will refer to them later when configuring the flows step 3 create analytics flows you can use multiple input nodes in a flow to save values in a database or save values to a csv file to save values from multiple registers to a csv file note a similar method could be used to save values in a mysql database in litmus edge, navigate to the flows manager and create a new flow see create a flow docid\ veyyte7xdcangglzbqya0 to learn more drag two function nodes and two datahub subscribe nodes to the canvas and wire them together double click one of the function nodes the edit function node dialog box appears on message add the following lines to save the value to a global variable ( output1 ), which can be accessed by other flows, nodes, and functions var temp = (json parse(msg payload)) value; global set("output1",temp); return msg; click done double click the other function node the edit function node dialog box appears on message enter the following lines of code var temp = (json parse(msg payload)) value; global set("output2",temp); return msg; click done double click one of the datahub subscribe nodes the edit datahub subscribe node dialog box appears datahub configure the datahub connection if needed see the step 3 configure connector nodes section in create a flow docid\ veyyte7xdcangglzbqya0 to learn more topic paste the topic for input1 tag name enter input1 click done repeat the last step for the other datahub subscribe node and paste the topic for input2 tag on the same canvas, drag an inject node, a function node, and a write file node and wire them together as shown double click the inject node the edit inject node dialog box appears repeat select an interval for every 10 seconds to read the global variable values click done double click the function node the edit function node dialog box appears on message enter the following lines of code to set up the output for the csv file //create csv var temp = global get("output1") + "," + global get("output2"); msg payload = temp; return msg; click done double click the write file node the edit write file node dialog box appears filename enter a filename prefaced with a forward slash ( / ) the forward slash is required in the filename example /ftp data/sample csv the file is created on the litmus edge device if a subdirectory already exists, you can supply the full path to the file example /ftp data/sample or /logfiles/sample action select append to file from the drop down menu and click done click deploy to save the flow drag the sidebar up from the bottom of the canvas and select the debug icon click the button on the left side of the inject (timestamp) node to inject the current timestamp into the write file node, which creates the csv file locally if it does not already exist in this example, the /ftp data/sample csv file is saved step 4 read contents of csv file to read the output of the csv file, refer to create, write to, and read from a log file docid\ f52bbwikxrcxu46kj0a5n note change the name of the file with the csv file you created to save multiple register values the csv file holds the current register values from the two inputs and updates them in real time