Tuesday, July 12, 2022

[FIXED] How can i seperate/split part of string messege in node red

Issue

I received this message:

 "data: "{"cmd":"gw","seqno":515816,"EUI":"000DB53113683569","ts":1510584501221,"fcnt":1,"port":2,"freq":868100000,"toa":1482,"dr":"SF12 BW125 4/5","ack":false,"gws":[{"rssi":-71,"snr":9.5,"ts":1510584501221,"time":"2017-11-13T14:48:21.218869Z","gweui":"B827EBFFFF6A14DD","lat":50.0751806,"lon":14.4022641}],"bat":255,"data":"0002560000000000000000"}"" 

I need to put away the "data: " and on the end the "

I need just the JSON message if I use JSON node it just writes me an error because of the "data: "


Solution

You can use a function node to chop the string up. Something like this:

msg.payload = msg.payload.substring(7,msg.payload.length - 1);
return msg;

And then wire this to a JSON node.



Answered By - hardillb
Answer Checked By - Robin (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.