Hi, i'm trying to figure out how to basically just automatically inject a string that kind of acts like a title to the messages below based on which dash button someone presses.
so basically if they press the 2kV start button it writes to the excel file as the data comes through "2kV Test Readings" then the msg payload / timestamp that came before in the flow... but it seems my attempt just stops outputting to file if i have the title adding function in place. quite stuck.
to elaborate, i only want the 'title' to occupy 1 cell each time the start is pressed, so if someone presses start and gets 1 batch of readings it is at the top. if they press start and let 4 batches of readings write to file i still only want it to be at the top once... unless they press stop and start again...
here's my flow:
[{"id":"11abe06410824819","type":"tab","label":"Voltage monitor test","disabled":false,"info":"","env":[]},{"id":"e485991ccf3e0822","type":"serial in","z":"11abe06410824819","name":"ESP_RX","serial":"6929e66dfb37b765","x":80,"y":320,"wires":[["fd8076b5fc07bbe3","d1156230815e2561","f9cfdd32067a70ed"]]},{"id":"8d630393845bd583","type":"ui_text","z":"11abe06410824819","group":"5d58b87e2056344d","order":1,"width":6,"height":3,"name":"Date and Time","label":"","format":"{{msg.payload}}","layout":"row-left","className":"","style":true,"font":"","fontSize":16,"color":"#000000","x":1440,"y":20,"wires":[]},{"id":"4bfbe73e0ce0a23d","type":"function","z":"11abe06410824819","name":"add time","func":"msg.payload = new Date().toString() +'\\n'+\" \"+',' +msg.payload;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":340,"wires":[["8ae3077d1e35d6f7","646f21230c7c34d8"]]},{"id":"245ca36fe017d921","type":"file","z":"11abe06410824819","name":"OUTPUT FILE","filename":"C:\\Users\\223131446\\documents\\ESP_NOW_testfile.csv","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":1460,"y":560,"wires":[[]]},{"id":"d1156230815e2561","type":"debug","z":"11abe06410824819","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":140,"y":40,"wires":[]},{"id":"dad545f1b5f6476c","type":"function","z":"11abe06410824819","name":"payload buffer","func":"// Get the cycle var from this node's context store or set to 0 if it doesn't yet exist\nlet cycle = context.get('cycle') ?? 0\n\n// Get the data buffer or an empty array if not exists yet\nconst databuff = context.get('databuff') ?? []\n\n// Add the new data to the buffer\ndatabuff.push(msg.payload)\n\n// Increment the cycle count\ncycle++\n\nif (cycle >= 5) {\n // Output the buffer (join the array as a string)\n node.send({payload: databuff.join('')})\n // reset the buffer\n context.set('databuff', [])\n // reset the counter\n context.set('cycle', 0)\n} else {\n context.set('databuff', databuff)\n context.set('cycle', cycle)\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1180,"y":520,"wires":[["245ca36fe017d921"]]},{"id":"8ae3077d1e35d6f7","type":"function","z":"11abe06410824819","name":"Message parser","func":"var outputs = [];\nvar values = msg.payload.split(\",\");\nfor(var v in values){\n outputs.push({payload:values[v]});\n}\nreturn outputs;","outputs":21,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1180,"y":220,"wires":[["8d630393845bd583"],["70cd1f1ccbd09caf"],["b4d7d97c77eaa853"],["8a48bf7f69cbd11a"],["1774b8ac7e7e9d7b"],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]},{"id":"70cd1f1ccbd09caf","type":"ui_text","z":"11abe06410824819","group":"e926a6330eaa482e","order":1,"width":4,"height":1,"name":"B1 Out","label":"","format":"{{msg.payload}}","layout":"row-spread","className":"","style":true,"font":"","fontSize":16,"color":"#000000","x":1420,"y":60,"wires":[]},{"id":"b4d7d97c77eaa853","type":"ui_text","z":"11abe06410824819","group":"e926a6330eaa482e","order":2,"width":4,"height":1,"name":"B2 Out","label":"","format":"{{msg.payload}}","layout":"row-spread","className":"","style":true,"font":"","fontSize":16,"color":"#000000","x":1420,"y":100,"wires":[]},{"id":"480a77aad8b034ce","type":"delay","z":"11abe06410824819","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":120,"y":680,"wires":[[]]},{"id":"fd8076b5fc07bbe3","type":"q-gate","z":"11abe06410824819","name":"2kV Write Blocker","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"peek","dropCmd":"drop","statusCmd":"status","maxQueueLength":"100","keepNewest":false,"qToggle":false,"persist":true,"storeName":"memory","x":510,"y":260,"wires":[["4bfbe73e0ce0a23d"]]},{"id":"039f4d8694d72753","type":"ui_button","z":"11abe06410824819","name":"2kVStart","group":"fb9a3225602c434e","order":2,"width":3,"height":2,"passthru":false,"label":"Start Receiving Data","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"open","payloadType":"str","topic":"control","topicType":"str","x":340,"y":120,"wires":[["fd8076b5fc07bbe3"]]},{"id":"0f4ca1545306e50a","type":"ui_button","z":"11abe06410824819","name":"2kV Stop","group":"fb9a3225602c434e","order":3,"width":3,"height":2,"passthru":true,"label":"Stop Receiving Data","tooltip":"","color":"","bgcolor":"red","className":"","icon":"","payload":"close","payloadType":"str","topic":"control","topicType":"str","x":340,"y":160,"wires":[["fd8076b5fc07bbe3"]]},{"id":"8a48bf7f69cbd11a","type":"ui_text","z":"11abe06410824819","group":"e926a6330eaa482e","order":3,"width":4,"height":1,"name":"B3 Out","label":"","format":"{{msg.payload}}","layout":"row-spread","className":"","style":true,"font":"","fontSize":16,"color":"#000000","x":1420,"y":140,"wires":[]},{"id":"b804165a13928094","type":"debug","z":"11abe06410824819","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":860,"y":60,"wires":[]},{"id":"1774b8ac7e7e9d7b","type":"ui_text","z":"11abe06410824819","group":"e926a6330eaa482e","order":4,"width":4,"height":1,"name":"B4 Out","label":"","format":"{{msg.payload}}","layout":"row-spread","className":"","style":true,"font":"","fontSize":16,"color":"#000000","x":1420,"y":180,"wires":[]},{"id":"f9cfdd32067a70ed","type":"q-gate","z":"11abe06410824819","name":"4kV Write Blocker","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"peek","dropCmd":"drop","statusCmd":"status","maxQueueLength":"100","keepNewest":false,"qToggle":false,"persist":true,"storeName":"memory","x":510,"y":480,"wires":[[]]},{"id":"8f32978ecfef8149","type":"ui_button","z":"11abe06410824819","name":"4kV Stop","group":"fb9a3225602c434e","order":6,"width":3,"height":2,"passthru":true,"label":"Stop Receiving Data","tooltip":"","color":"","bgcolor":"red","className":"","icon":"","payload":"close","payloadType":"str","topic":"control","topicType":"str","x":320,"y":360,"wires":[["f9cfdd32067a70ed"]]},{"id":"4c93f806372b1bba","type":"ui_button","z":"11abe06410824819","name":"4kV Start","group":"fb9a3225602c434e","order":5,"width":3,"height":2,"passthru":false,"label":"Start Receiving Data","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"open","payloadType":"str","topic":"control","topicType":"str","x":320,"y":320,"wires":[["f9cfdd32067a70ed"]]},{"id":"646f21230c7c34d8","type":"function","z":"11abe06410824819","name":"2kV Title","func":"","outputs":1,"timeout":0,"noerr":0,"initialize":"var title;\nvar data;\ndata = msg.payload;\ntitle = \"2kV Test Readings\";\nmsg.payload = title + data;\nreturn msg;\n","finalize":"","libs":[],"x":920,"y":520,"wires":[["dad545f1b5f6476c","b804165a13928094"]]},{"id":"9ce84772b81d7467","type":"ui_spacer","z":"11abe06410824819","name":"spacer","group":"fb9a3225602c434e","order":4,"width":3,"height":1},{"id":"6929e66dfb37b765","type":"serial-port","name":"Nano IN","serialport":"COM5","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"5d58b87e2056344d","type":"ui_group","name":"Timestamp:","tab":"f95d506942394920","order":3,"disp":true,"width":"6","collapse":false,"className":""},{"id":"e926a6330eaa482e","type":"ui_group","name":"Voltage Readings","tab":"f95d506942394920","order":4,"disp":true,"width":"16","collapse":false,"className":""},{"id":"fb9a3225602c434e","type":"ui_group","name":"Control Panel","tab":"f95d506942394920","order":1,"disp":true,"width":"3","collapse":false,"className":""},{"id":"f95d506942394920","type":"ui_tab","name":"Home","icon":"fa-bolt","disabled":false,"hidden":false}]
my plan is to have a title per type of button pressed. any help is appreciated even if it's just pointing me to a solution to once append a string to a payload automatically