Split message from LoRa to UI

Hi

I need help. How do i split these messages from serial node so i can display it in UI as gauges. I got the datasets from LoRa node.

Thank you

That's a bit of a challenging string to parse, but try a function node with this code:

var arr = msg.payload.trim().split(" ").map(d => d.match(/([a-z]+):(.+),/);
msg.payload = {};
arr.forEach(function(a) {
    var v = a[2].split(",");
    msg.payload[a[1]] = (v.length == 1? +v[0]: v.map(n => +n));
});
return msg;

Of course, this is very specific to the data string you are showing... any changes to the spacing or punctuation could cause it to fail. The resulting payload looks like this:

{
  temp: 28,
  humi: 64.3,
  gyro: [ -0.96, -0.15, 0.18 ],
  press: 970.3,
  lux: 0
}

so your downstream nodes can access any of those 5 properties by name (e.g. msg.payload.humi, or msg.payload.gyro[2]) and have numeric values, suitable for graphing.

1 Like

Thank you so much for the help. It works like a charm.

A quick search of the flows library shows there are at least 3 custom nodes built just for decoding lora data messages... https://flows.nodered.org/?term=lora&type=node

In the long rung, you may be better off using one of those -- especially if the data format may vary (e.g. order of values, optional elements, alternate punctuation, etc).

Thank you for the information. I was actually trying out this LoRa module evaluation kit actually to understand how it works .
https://www.devicemart.co.kr/1289752

Thank you again for your help. I appreciate it a lot