Add timestamp item inside array

Hi,
image

I'm reading Modbus array [5 items] and I need to add -in the first position- the 6th item (timestamp) to log them in a csv file.
I don't know how to insert the timestamp,
any help is appreciated.

here I created an array to simulate the Modbus input

[{"id":"bdca0aac.97159","type":"file","z":"f971f785.8dc938","name":"file","filename":"log.csv","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":610,"y":60,"wires":[[]]},{"id":"2aa05887.c98908","type":"csv","z":"f971f785.8dc938","name":"","sep":";","hdrin":true,"hdrout":"once","multi":"mult","ret":"\\n","temp":"Date,Temp,Cap,REG3,REG4","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":410,"y":60,"wires":[["bdca0aac.97159"]]},{"id":"1ae9aac4.938ea5","type":"inject","z":"f971f785.8dc938","name":"Array 5","props":[{"p":"payload"},{"p":"topic","v":"[\"Temp\",\"Cap\",\"REG3\",\"REG4\",\"REG5\"]","vt":"jsonata"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[2973,68,6208,56,45556]","payloadType":"jsonata","x":200,"y":60,"wires":[["2aa05887.c98908","c5f26fc7.8e8128","baeed3b9.eac98","3e0554e0.46cc8c"]]}]
1 Like
msg.payload.unshift(Date.now())
return msg;
[{"id":"2aa05887.c98908","type":"csv","z":"b872cb4b.5a6448","name":"","sep":";","hdrin":true,"hdrout":"once","multi":"mult","ret":"\\n","temp":"Date,Temp,Cap,REG3,REG4","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":710,"y":760,"wires":[["6e6fe6d9.52fe08"]]},{"id":"1ae9aac4.938ea5","type":"inject","z":"b872cb4b.5a6448","name":"Array 5","props":[{"p":"payload"},{"p":"topic","v":"[\"timestamp\", \"Temp\",\"Cap\",\"REG3\",\"REG4\",\"REG5\"]","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[2973,68,6208,56,45556]","payloadType":"json","x":410,"y":760,"wires":[["79765b97.b1ae44"]]},{"id":"79765b97.b1ae44","type":"function","z":"b872cb4b.5a6448","name":"","func":"msg.payload.unshift(Date.now())\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":760,"wires":[["2aa05887.c98908"]]},{"id":"6e6fe6d9.52fe08","type":"debug","z":"b872cb4b.5a6448","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":760,"wires":[]}]
1 Like

It solved my problem
I dont know how to thank you
Many thanks :heart:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.