Pull line number from text

Hi all,

Im sure this is really simple but I couldn't find anything in search that was helpful.

I have a string returned from a solar inverter

1
1
EAB961770026
QRGQQBWVVXSTTVYP
M11
17511-708R+17511-707R
11:45 20/12/2020
0
1
BS30000101770043
2225
8.8
OK
Error

I just want to pull out lines 11 and 12

I tried using a sort node but it didnt seem to put them all into an array

Can somebody give me some hints?

How is this string getting into NR ? Serial port read, etc etc ?

Might be an idea to post up a debug shot as well for some ideas (as there may be a more elegant way)

The string object is the way to get it if it is a contained in a single message

Craig

Hi Craig,

here is the debug

the string is acquired thru a http request

image

OK looks fairly straightforward.

Try and feed it into the String command which should be able to treat it as individual lines - have a look at the help for the string node as it gives all the options and well documented

Craig

1 Like

split the string using a function node and JS, or change node and JSONata

example of JSONata

[{"id":"a0f0ceca.b3f5f","type":"inject","z":"8d22ae29.7df6d","name":"Trigger Manual","props":[{"p":"payload"},{"p":"random","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":2900,"wires":[["f28bcdf4.04cb4"]]},{"id":"f28bcdf4.04cb4","type":"template","z":"8d22ae29.7df6d","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1\n1\nEAB961770026\nQRGQQBWVVXSTTVYP\nM11\n17511-708R+17511-707R\n11:45 20/12/2020\n0\n1\nBS30000101770043\n2225\n8.8\nOK\nError","output":"str","x":140,"y":2960,"wires":[["83a42de1.ce546"]]},{"id":"83a42de1.ce546","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"($value := $split(payload, \"\\n\");\t{\"value1\":$value[10], \"value2\":$value[11]})","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":2920,"wires":[["e865d4e9.d0217"]]},{"id":"e865d4e9.d0217","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":2900,"wires":[]}]
1 Like

Use a function node...

var lines = msg.payload.split("\n");
msg.payload = {
  line11: lines[10],
  line12: lines[11],
}
return msg;

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