# Trouble splitting serial in data (Strings)

**URL:** https://discourse.nodered.org/t/trouble-splitting-serial-in-data-strings/13258
**Category:** Dashboard
**Created:** [14 July 2019 09:23 UTC](https://discourse.nodered.org/t/trouble-splitting-serial-in-data-strings/13258 "2019-07-14T09:23:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![pi.guy](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pi.guy](https://discourse.nodered.org/u/pi.guy)
#### Post date: [14 July 2019 09:23 UTC](https://discourse.nodered.org/t/trouble-splitting-serial-in-data-strings/13258/1 "2019-07-14T09:23:35Z")

</div>

Hello all

I am new to node red and can't seem to find a fix for my issue.

Node red is being run on my pi 3 model b that is connected to ardunio uno via usb serial link. I am able to get the data from the serial.print from the ardunio to show in node red using the serial in node.

Connected to Ardunio UNO:

1x Temperature sensor

1x water flow sensor

1X RTC (Not updated with correct time yet)

1x PH sensor ( **ignore this one for now** )

For reference please see below:

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

\*\* connecting debug node to Serial in log\*\*

What I am trying to do is display the readings (values) coming in from the serial in onto separate dashboard gauges.

The advice I find online says to use a switch to filter the strings However on the debug log for the outputs on the switch I either get no readings or the same reading as the serial in

For reference below

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

As you can see from the screen shoot above the readings are the same as the serial in and pulse though all the readings shown in the debug at the top of the post.

Any advice will be appreciated to get this working

Thanks for reading

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [14 July 2019 09:39 UTC](https://discourse.nodered.org/t/trouble-splitting-serial-in-data-strings/13258/2 "2019-07-14T09:39:55Z")

</div>

Example flow:

```auto
[{"id":"eb87884f.3f892","type":"inject","z":"a5ad0b9b.9014e","name":"temperature","topic":"","payload":"Temperature for the device 1 (index 0) is: 23.37","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":275,"wires":[["e5874145.01e688"]]},{"id":"2d8b4350.3a4ad4","type":"debug","z":"a5ad0b9b.9014e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":595,"y":350,"wires":[]},{"id":"e5874145.01e688","type":"change","z":"a5ad0b9b.9014e","name":"Extract number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number($trim($split(payload,':')[1]))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":405,"y":325,"wires":[["2d8b4350.3a4ad4"]]},{"id":"1617f1c5.a780c6","type":"inject","z":"a5ad0b9b.9014e","name":"","topic":"","payload":"L/hour: 0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":325,"wires":[["e5874145.01e688"]]},{"id":"ae8fb725.bc1028","type":"change","z":"a5ad0b9b.9014e","name":"Extract string","rules":[{"t":"set","p":"payload","pt":"msg","to":"$trim($split(payload,':')[1])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":395,"y":375,"wires":[["2d8b4350.3a4ad4"]]},{"id":"b05f4b05.164b2","type":"inject","z":"a5ad0b9b.9014e","name":"Date","topic":"","payload":"Date: 19.05.2000","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":375,"wires":[["ae8fb725.bc1028"]]},{"id":"e2b1111a.33e82","type":"inject","z":"a5ad0b9b.9014e","name":"time","topic":"","payload":"Time: 14:50:06","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":425,"wires":[["ae8fb725.bc1028"]]}]

```

---

<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: [14 July 2019 09:40 UTC](https://discourse.nodered.org/t/trouble-splitting-serial-in-data-strings/13258/3 "2019-07-14T09:40:27Z")

</div>

A suggestion.  
Construct JSON strings in the Arduino then send that to node red.

Then it's a simple case of using the JSON node to convert your string data to useable object.

No need to split your data whatsoever.

You could also include a topic on the JSON string to simplify routing MSG's through the switch node.

---

<div class="post-metadata">

### Author: ![pi.guy](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pi.guy](https://discourse.nodered.org/u/pi.guy)
#### Post date: [14 July 2019 09:49 UTC](https://discourse.nodered.org/t/trouble-splitting-serial-in-data-strings/13258/4 "2019-07-14T09:49:54Z")

</div>

Thank you for the reply

So the example flow looks like this

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

Question:  
How does the data from the serial link get into this flow ?

Sorry I am new

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [14 July 2019 10:01 UTC](https://discourse.nodered.org/t/trouble-splitting-serial-in-data-strings/13258/5 "2019-07-14T10:01:31Z")

</div>

Like this.

```auto
[{"id":"eb87884f.3f892","type":"inject","z":"a5ad0b9b.9014e","name":"temperature","topic":"","payload":"Temperature for the device 1 (index 0) is: 23.37","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":275,"wires":[["79bab735.7e7aa8"]]},{"id":"2d8b4350.3a4ad4","type":"debug","z":"a5ad0b9b.9014e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":350,"wires":[]},{"id":"1617f1c5.a780c6","type":"inject","z":"a5ad0b9b.9014e","name":"","topic":"","payload":"L/hour: 0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":325,"wires":[["79bab735.7e7aa8"]]},{"id":"b05f4b05.164b2","type":"inject","z":"a5ad0b9b.9014e","name":"Date","topic":"","payload":"Date: 19.05.2000","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":375,"wires":[["79bab735.7e7aa8"]]},{"id":"e2b1111a.33e82","type":"inject","z":"a5ad0b9b.9014e","name":"time","topic":"","payload":"Time: 14:50:06","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":425,"wires":[["79bab735.7e7aa8"]]},{"id":"79bab735.7e7aa8","type":"function","z":"a5ad0b9b.9014e","name":"","func":"i = msg.payload\n\ns = i.split(':')\no = s[1].trim()\n\nif(!isNaN(o) && s[0]!= 'Date' && s[0]!='Time'){\n return {payload:Number(o)}; \n}\n","outputs":1,"noerr":0,"x":475,"y":350,"wires":[["2d8b4350.3a4ad4"]]}]

```

But like @Steve-Mcl mentioned, why sending text from arduino, create a json object instead.

---

<div class="post-metadata">

### Author: ![pi.guy](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pi.guy](https://discourse.nodered.org/u/pi.guy)
#### Post date: [14 July 2019 10:06 UTC](https://discourse.nodered.org/t/trouble-splitting-serial-in-data-strings/13258/6 "2019-07-14T10:06:15Z")

</div>

Thanks

Sorry @Steve-Mcl your reply didn't show until I refreshed the page

I will give the JSON strings in the Arduino ago now
