I have files which are created every time the machine is booted.
With fs-ops
node/s I get a list of said files:
["Powered on at 2021-02-01 212108.db","Powered on at 2021-02-02 073139.db","Powered on at 2021-02-02 114601.db","Powered on at 2021-02-02 165843.db","Powered on at 2021-02-02 171120.db","Powered on at 2021-02-02 172557.db","Powered on at 2021-02-03 122336.db","Powered on at 2021-02-04 064446.db","Powered on at 2021-02-04 124940.db","Powered on at 2021-02-04 190643.db","Powered on at 2021-02-05 065420.db","Powered on at 2021-02-05 115718.db","Powered on at 2021-02-05 185952.db","Powered on at 2021-02-05 215415.db","Powered on at 2021-02-05 222908.db","Powered on at 2021-02-06 063001.db"]
What I want to do is make a list (as in a list displayed on the screen) of these files with the format:
the date and time of the file name + the first line of the file.
As the list is contained in msg.payload[x]
I am at a loss how to split it up and spit out all those as lines which than can then be put through a file in
node to read the first line.
I'm sure after my posting this, I will have that ah ha! moment, but as many of you who know me: It won't happen until I post this.
But any help would be appreciated.
Update:
(I told you)
Ok, so now I have this as the message:
up 4 hours, 28 minutesLast alive 2021-02-06 10:57:59
Expanded it has a \n
in it. Or so I think.
(See picture)
I tried the string
node and strip right
\n
but that doesn't work.
Further update:
This is a working flow, but I'm just curious if there is a nicer/neater way I could do it for formatting the message/s.
Foreign nodes
fs-ops-dir
ring-buffer
(Not important in the workings.)
[{"id":"f6edc695.44c1a","type":"split","z":"8bb4de19.f72c88","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":2080,"y":1330,"wires":[["5affc1e5.4dd268"]]},{"id":"5affc1e5.4dd268","type":"change","z":"8bb4de19.f72c88","name":"set msg.filename","rules":[{"t":"move","p":"payload","pt":"msg","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2165,"y":1330,"wires":[["9da1bb26.a6eb58"]],"l":false},{"id":"a72d260.586b358","type":"change","z":"8bb4de19.f72c88","name":"set msg.files","rules":[{"t":"move","p":"files","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1995,"y":1330,"wires":[["f6edc695.44c1a"]],"l":false},{"id":"9da1bb26.a6eb58","type":"template","z":"8bb4de19.f72c88","name":"","field":"filename","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"/home/me/.node-red/public/history/{{filename}}","output":"str","x":2260,"y":1330,"wires":[["33e7cf5b.473a98"]]},{"id":"5da9bf43.2ee768","type":"fs-ops-dir","z":"8bb4de19.f72c88","name":"List files","path":"/home/me/.node-red/public/history","pathType":"str","filter":"*","filterType":"str","dir":"files","dirType":"msg","x":1890,"y":1330,"wires":[["a72d260.586b358"]]},{"id":"33e7cf5b.473a98","type":"file in","z":"8bb4de19.f72c88","name":"Log","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":1880,"y":1380,"wires":[["6830cf4c.36f878"]]},{"id":"a5dec011.09a168","type":"inject","z":"8bb4de19.f72c88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1900,"y":1260,"wires":[["5da9bf43.2ee768"]]},{"id":"668363a0.da2484","type":"ui_button","z":"8bb4de19.f72c88","name":"Create history list","group":"8a97b9d.4e64d48","order":1,"width":"2","height":"1","passthru":false,"label":"Show","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":1920,"y":1210,"wires":[["5da9bf43.2ee768"]]},{"id":"6830cf4c.36f878","type":"string","z":"8bb4de19.f72c88","name":"filename","methods":[{"name":"getRightMost","params":[{"type":"str","value":"/"}]},{"name":"delRightMost","params":[{"type":"str","value":"."}]}],"prop":"filename","propout":"filename","object":"msg","objectout":"msg","x":2030,"y":1380,"wires":[["a0199d1e.23bd58"]]},{"id":"a0199d1e.23bd58","type":"string","z":"8bb4de19.f72c88","name":"","methods":[{"name":"delRightMost","params":[{"type":"str","value":"minutes"}]},{"name":"chompLeft","params":[{"type":"str","value":"up "}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":2170,"y":1380,"wires":[["d600953e.5b1e4"]]},{"id":"d600953e.5b1e4","type":"template","z":"8bb4de19.f72c88","name":"Structure","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{filename}} for {{payload}} minutes","output":"str","x":2310,"y":1380,"wires":[["b355ebea.1d25a"]]},{"id":"b355ebea.1d25a","type":"ring-buffer","z":"8bb4de19.f72c88","name":"Cache","capacity":16,"order":"new-to-old","sendOnlyIfFull":false,"pushAfterClear":false,"extra":false,"perTopic":false,"x":2450,"y":1380,"wires":[["dfebd910.415f88"]]},{"id":"3ddb8752.20aff8","type":"change","z":"8bb4de19.f72c88","name":"Wipe","rules":[{"t":"set","p":"clear","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2255,"y":1210,"wires":[["b355ebea.1d25a"]],"l":false},{"id":"dfebd910.415f88","type":"ui_template","z":"8bb4de19.f72c88","group":"8a97b9d.4e64d48","name":"Hisotry list","order":3,"width":"9","height":"8","format":"<table id=\"table\" border=\"1\">\n <tr>\n <th>History</th> \n </tr>\n <tbody>\n <tr ng-repeat=\"row in msg.payload track by $index\">\n <td class=\"text\" >{{row}}</td>\n </tr>\n </tbody>\n</table>\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":2630,"y":1380,"wires":[[]]},{"id":"d57a1888.e83428","type":"ui_button","z":"8bb4de19.f72c88","name":"Create history list","group":"8a97b9d.4e64d48","order":2,"width":"2","height":"1","passthru":false,"label":"Wipe","tooltip":"","color":"","bgcolor":"","icon":"","payload":"blah","payloadType":"str","topic":"","x":2130,"y":1210,"wires":[["3ddb8752.20aff8"]]},{"id":"8a97b9d.4e64d48","type":"ui_group","name":"Group 1","tab":"718742c7.3798cc","order":1,"disp":true,"width":"9","collapse":false},{"id":"718742c7.3798cc","type":"ui_tab","name":"Machine Usage","icon":"dashboard","order":1,"disabled":false,"hidden":false}]