# Extract values from serial port data & display on dashboard

**URL:** https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758
**Category:** General
**Created:** [29 April 2020 18:06 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758 "2020-04-29T18:06:13Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Allanch7](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Allanch7](https://discourse.nodered.org/u/Allanch7)
#### Post date: [29 April 2020 18:06 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/1 "2020-04-29T18:06:13Z")

</div>

Estoy tratando de armar un dashboard en donde extraigo diferentes valores por puerto serial (COM), esto es lo que me está llegando pero ocupo extraer solamente los valores de BAT, TC, HUM Y PRESS.  
Soy muy nuevo usando red node por lo cual necesito ayuda para extraer estos datos de la cadena.

Gracias

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/392b2cbe88738a477910149942dc326c9b559165.png)

I am trying to put together a dashboard where I extract different values by serial port (COM), this is what is coming to me but I only need to extract the values of BAT, TC, HUM AND PRESS.  
I am very new to using red node so I need help to extract this data from the string.

Thank you

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [29 April 2020 19:27 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/2 "2020-04-29T19:27:27Z")

</div>

Welcome to the forum @Allanch7.

You are lucky that the interesting data is framed by a pair of `#` characters. This makes possible to use a split node to separate the data. After the split node you can use a switch node to route the data to different outputs. Something like below:

 ![b-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e1e2e7b9ef05b31518ea91eb5645c497708ce76.png)

Testing flow:

```auto
[{"id":"613d1be1.756e94","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"688fcd43.63b134","type":"inject","z":"613d1be1.756e94","name":"Your serial node","topic":"","payload":"Data: <=>fijierfji10440#EVENTSBOARD#252#STR:new_sensor_frame#BAT:93#TC:26.45#HUM:35.0#PRES:91231.56#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":180,"wires":[["c3727b79.b17958"]]},{"id":"6c7ea4d9.1df1dc","type":"debug","z":"613d1be1.756e94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":140,"wires":[]},{"id":"c3727b79.b17958","type":"split","z":"613d1be1.756e94","name":"","splt":"#","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":180,"wires":[["5b228f02.4fdd9"]]},{"id":"5b228f02.4fdd9","type":"switch","z":"613d1be1.756e94","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"BAT","vt":"str"},{"t":"cont","v":"TC","vt":"str"},{"t":"cont","v":"HUM","vt":"str"},{"t":"cont","v":"PRES","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":550,"y":180,"wires":[["6c7ea4d9.1df1dc"],["79927bd7.6b8264"],["ba1175cd.e6e118"],["74ca4f6f.1d76e"]]},{"id":"79927bd7.6b8264","type":"debug","z":"613d1be1.756e94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":180,"wires":[]},{"id":"ba1175cd.e6e118","type":"debug","z":"613d1be1.756e94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":220,"wires":[]},{"id":"74ca4f6f.1d76e","type":"debug","z":"613d1be1.756e94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":260,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [29 April 2020 19:27 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/3 "2020-04-29T19:27:45Z")

</div>

You could set the serial settings to split on `#` then, using a function, split each string on `:`. if it matches what you want, return a new `msg`

EDIT...

Serial port setting...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/2/320eb999eb36eeaac3e71b727fd5258dd36d8b56.png)

Example...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2f705f32c339f0d76d1e19dfbe9db6c5a0cc812c.png)

Function code...

```auto
function isNumeric(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

var s = msg.payload;
if(typeof s == "string" && s.includes(":")) {
    let pair = s.split(":");
    let name = pair[0];
    let val = pair[1];
    if(isNumeric(val)){
        val = Number(val);
    }
    msg.topic = name;
    msg.payload = val;
    return msg;
}
return null;

```

flow...

```auto
[{"id":"be0c31c5.4f9ed","type":"inject","z":"c70ba4a4.e7fb58","name":"","topic":"","payload":"<=>SDASDEFASF#BAT:93#TC:26.45#HUM:35.0#PRES:91231.56#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":690,"y":700,"wires":[["337183dd.3c553c","d65d45ae.d11a08"]]},{"id":"337183dd.3c553c","type":"split","z":"c70ba4a4.e7fb58","name":"","splt":"#","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"","x":820,"y":700,"wires":[["9d077fb7.14cf4"]]},{"id":"a64f74d4.8f5778","type":"comment","z":"c70ba4a4.e7fb58","name":"Use inject+split to fake the serial data","info":"","x":750,"y":660,"wires":[]},{"id":"9d077fb7.14cf4","type":"function","z":"c70ba4a4.e7fb58","name":"split on :","func":"function isNumeric(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n}\n\nvar s = msg.payload;\nif(typeof s == \"string\" && s.includes(\":\")) {\n let pair = s.split(\":\");\n let name = pair[0];\n let val = pair[1];\n if(isNumeric(val)){\n val = Number(val);\n }\n msg.topic = name;\n msg.payload = val;\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"x":1020,"y":700,"wires":[["cfab5df0.2fa3c"]]},{"id":"cfab5df0.2fa3c","type":"debug","z":"c70ba4a4.e7fb58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1170,"y":700,"wires":[]},{"id":"28998841.424988","type":"comment","z":"c70ba4a4.e7fb58","name":"Connect the function to output of serial node","info":"","x":1130,"y":660,"wires":[]},{"id":"d65d45ae.d11a08","type":"debug","z":"c70ba4a4.e7fb58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":810,"y":780,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [29 April 2020 20:15 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/4 "2020-04-29T20:15:16Z")

</div>

As you can see one of the strengths of Node-RED is that you have several ways to achieve what you want. An alternative to split the values is by using REGEX inside a change node.

 ![b-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab357a7406f714b1b99f5bea8714f35fbf8ffc75.png)

Flow:

```auto
[{"id":"613d1be1.756e94","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"688fcd43.63b134","type":"inject","z":"613d1be1.756e94","name":"Your serial node","topic":"","payload":"Data: <=>fijierfji10440#EVENTSBOARD#252#STR:new_sensor_frame#BAT:93#TC:26.45#HUM:35.0#PRES:91231.56#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":180,"wires":[["c3727b79.b17958"]]},{"id":"c3727b79.b17958","type":"split","z":"613d1be1.756e94","name":"","splt":"#","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":180,"wires":[["5b228f02.4fdd9"]]},{"id":"5b228f02.4fdd9","type":"switch","z":"613d1be1.756e94","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"BAT","vt":"str"},{"t":"cont","v":"TC","vt":"str"},{"t":"cont","v":"HUM","vt":"str"},{"t":"cont","v":"PRES","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":550,"y":240,"wires":[["c1302d98.3895f"],["7c03fd8c.357bb4"],["7775b6c6.146cd8"],["7b773e27.d85c9"]]},{"id":"542e0391.8eb54c","type":"debug","z":"613d1be1.756e94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"bat","targetType":"msg","x":920,"y":160,"wires":[]},{"id":"c1302d98.3895f","type":"change","z":"613d1be1.756e94","name":"","rules":[{"t":"set","p":"temp","pt":"msg","to":"$match(payload,/\\d+\\.*\\d*/)","tot":"jsonata"},{"t":"set","p":"bat","pt":"msg","to":"temp.match","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":160,"wires":[["542e0391.8eb54c"]]},{"id":"7c03fd8c.357bb4","type":"change","z":"613d1be1.756e94","name":"","rules":[{"t":"set","p":"temp","pt":"msg","to":"$match(payload,/\\d+\\.*\\d*/)","tot":"jsonata"},{"t":"set","p":"tc","pt":"msg","to":"temp.match","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":220,"wires":[["73bd8466.77928c"]]},{"id":"7775b6c6.146cd8","type":"change","z":"613d1be1.756e94","name":"","rules":[{"t":"set","p":"temp","pt":"msg","to":"$match(payload,/\\d+\\.*\\d*/)","tot":"jsonata"},{"t":"set","p":"hum","pt":"msg","to":"temp.match","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":280,"wires":[["81f1ea1b.a00768"]]},{"id":"7b773e27.d85c9","type":"change","z":"613d1be1.756e94","name":"","rules":[{"t":"set","p":"temp","pt":"msg","to":"$match(payload,/\\d+\\.*\\d*/)","tot":"jsonata"},{"t":"set","p":"pres","pt":"msg","to":"temp.match","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":340,"wires":[["a994e0b8.085ab"]]},{"id":"73bd8466.77928c","type":"debug","z":"613d1be1.756e94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"tc","targetType":"msg","x":910,"y":220,"wires":[]},{"id":"81f1ea1b.a00768","type":"debug","z":"613d1be1.756e94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"hum","targetType":"msg","x":920,"y":280,"wires":[]},{"id":"a994e0b8.085ab","type":"debug","z":"613d1be1.756e94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"pres","targetType":"msg","x":920,"y":340,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![Allanch7](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Allanch7](https://discourse.nodered.org/u/Allanch7)
#### Post date: [29 April 2020 21:55 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/6 "2020-04-29T21:55:09Z")

</div>

He podido avanzar, esto es lo que me esta mostrando, como puedo sacar esos valores de TC,HUM,PRES,BAT por ejemplo a un gauge ya que estos son valores de sensores.

 ![Captura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e3493b83f677078a0861cd3e05d41319e43cba2f.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [30 April 2020 00:54 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/7 "2020-04-30T00:54:48Z")

</div>

Hi @Allanch7 - sorry, my Spanish is not great and this is predominantly an English forum.

As i understand it, you want to know how to send these values to a gauge (for example)?

What have you tried?

Have you installed node-red-dashboard?

Its quite simple (PS, read the INFO on the Side-bar for help)

Add these...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da08161a5fdff0ce6d95000e75aec3069361b131.png)

Get this...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/3/339168cd6fac81fe1df47eaf99bc809787e986a4.png)

Demo flow...

```auto
[{"id":"19c61b33.f26065","type":"inject","z":"c70ba4a4.e7fb58","name":"","topic":"","payload":"<=>SDASDEFASF#BAT:93#TC:26.45#HUM:35.0#PRES:91231.56#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1310,"y":720,"wires":[["b3bf3347.93cb8","cdb376f2.428208"]]},{"id":"b3bf3347.93cb8","type":"split","z":"c70ba4a4.e7fb58","name":"","splt":"#","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"","x":1440,"y":720,"wires":[["2301b865.c6ad88"]]},{"id":"a2ca5411.c38888","type":"comment","z":"c70ba4a4.e7fb58","name":"Use inject+split to fake the serial data","info":"","x":1370,"y":680,"wires":[]},{"id":"2301b865.c6ad88","type":"function","z":"c70ba4a4.e7fb58","name":"split on :","func":"function isNumeric(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n}\n\nvar s = msg.payload;\nif(typeof s == \"string\" && s.includes(\":\")) {\n let pair = s.split(\":\");\n let name = pair[0];\n let val = pair[1];\n if(isNumeric(val)){\n val = Number(val);\n }\n msg.topic = name;\n msg.payload = val;\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"x":1640,"y":720,"wires":[["8d741514.2fe0e8"]]},{"id":"8691f52f.ee7b68","type":"comment","z":"c70ba4a4.e7fb58","name":"Connect the function to output of serial node","info":"","x":1750,"y":680,"wires":[]},{"id":"cdb376f2.428208","type":"debug","z":"c70ba4a4.e7fb58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1430,"y":800,"wires":[]},{"id":"8d741514.2fe0e8","type":"switch","z":"c70ba4a4.e7fb58","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"BAT","vt":"str"},{"t":"eq","v":"PRES","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1840,"y":720,"wires":[["a7a27243.02e6d"],["264f8075.9e932"]]},{"id":"a7a27243.02e6d","type":"ui_gauge","z":"c70ba4a4.e7fb58","name":"","group":"f659c41f.adaeb8","order":1,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":2020,"y":680,"wires":[]},{"id":"264f8075.9e932","type":"ui_chart","z":"c70ba4a4.e7fb58","name":"","group":"f659c41f.adaeb8","order":2,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":2020,"y":740,"wires":[[]]},{"id":"f659c41f.adaeb8","type":"ui_group","z":"","name":"HOME2","tab":"9ac44b8b.164fe8","order":1,"disp":true,"width":"6","collapse":false},{"id":"9ac44b8b.164fe8","type":"ui_tab","z":"","name":"TEST2","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![Allanch7](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Allanch7](https://discourse.nodered.org/u/Allanch7)
#### Post date: [30 April 2020 14:51 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/8 "2020-04-30T14:51:57Z")

</div>

yes but it doesn't show the values, what I want is to put 4 indicators on a board.

 ![Captura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e78537a89578f9fbeae0bff439ea92eaee3809f5.png) ![Captura2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/beb8d167cf34633aa2c0273b93c4888303bcdfbb.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [30 April 2020 14:55 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/9 "2020-04-30T14:55:15Z")

</div>

Put debug nodes after each node. See what's happening.

---

<div class="post-metadata">

### Author: ![Allanch7](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Allanch7](https://discourse.nodered.org/u/Allanch7)
#### Post date: [30 April 2020 14:59 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/10 "2020-04-30T14:59:09Z")

</div>

If i put the debug modules after the switch they don't show data

 ![Captura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d920a564b2a9af3f1c3d2d2f40cfd7fba5e324d3.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [30 April 2020 16:55 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/11 "2020-04-30T16:55:01Z")

</div>

That's why your graphs are empty.

Did you put debug nodes further back to see what was going into the switch node like I said...

> [@Steve-Mcl](#):
>
> Put debug nodes after each node. See what's happening

Put them everywhere. See what they contain, figure out why the messages are not getting through.

---

<div class="post-metadata">

### Author: ![machadotiago](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/machadotiago/32/23776_2.png) [@machadotiago](https://discourse.nodered.org/u/machadotiago)
#### Post date: [30 April 2020 17:47 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/12 "2020-04-30T17:47:27Z")

</div>

(Just to add my contribution to the discussion) I strongly encourage you to try to develop this flow by using the standard NR nodes (split, switch, change, and so on) without using the function node.

We have been working with Node-RED since 5 years and what we see is that developing Flows using "Function" nodes can be very hard if you are not a Javascript developer, in the other hand, if you understand how to use the standard nodes you can go from **newbie** to **pro** much much faster, trust me.

---

<div class="post-metadata">

### Author: ![FrankAB](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@FrankAB](https://discourse.nodered.org/u/FrankAB)
#### Post date: [13 April 2021 16:31 UTC](https://discourse.nodered.org/t/extract-values-from-serial-port-data-display-on-dashboard/25758/13 "2021-04-13T16:31:34Z")

</div>

Hi Steve  
gauge = 100 looks better  
Regards
