Probably better suited to a regular expression that captures the PG number and status (or split on newline then split each line on space) then send each as a separate message with topic set OR build an overall object with all PGs and their state.
example of generating a message with topic and payload as value for each "PG X STATE"...
let lines = msg.payload.split("\n");
for(let i = 0; i < lines.length; i++) {
let line = lines[i].trim();
let parts = line.split(" ");
if(parts.length != 2) continue;
node.send({ topic: "mydevice/pg/" + parts[1] + "/state" , payload: parts[2]});
}
You could feed this function to a join node if you want a single key/val object (just send a msg with msg.complete set true after the for loop).
EDIT...
Forgot to say: If you have any control of the send format - I strongly recommend you send a JSON string (all this looping and splitting would be completely unecessary)
With your flow, it works.
so i try on with the other strings....(i get some different strings from the device), but with your flow i hope i can make it work
i will give you a answer.
There are 4 dif. String's beginning with the following ASCII:
OK /n
JA-121T.... OK/n
PGSTATE... OK/n
PRFSTATE.... OK/n
But sometimes the payload is a combination of two result of 2 payloads. See the att. Image
So it's to tricky for me to parse it.
Is there a simple way to resolve this?
Thank you