# Splitting a string and viewing contents

**URL:** <https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223>\
**Category:** General\
**Created:** [7 September 2019 03:23 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223 "2019-09-07T03:23:58Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaynel2006](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@shaynel2006](https://discourse.nodered.org/u/shaynel2006)\
**Post date:** [7 September 2019 03:23 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/1 "2019-09-07T03:23:58Z")

</div>

Hi All, im new to Node-Red and are slowly learning as i go.  
i have a data logger which broadcasts the string via IP and port.  
i have the string which gives me all of the logger values like this.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/be1f3615cf36659e73e2b571d76ef99a25e1b381.png)  
i want to view for example the value of A01:000000 in a guage (this is setup to measure a tank level.  
could someone point me in the right direction

---

<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:** [7 September 2019 05:22 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/2 "2019-09-07T05:22:20Z")

</div>

With a function node, you can create a "usable" object:

```auto
m = msg.payload.split(":")
key = m[0]
value = parseFloat(m[1])

return {payload:{[key]:value}};

```

However, what do the `0000000`'s represent ? Is this a value of 0 ? Or the number of 0's are the tank level ?

---

<div class="post-metadata">

**Author:** ![shaynel2006](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@shaynel2006](https://discourse.nodered.org/u/shaynel2006)\
**Post date:** [7 September 2019 05:36 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/3 "2019-09-07T05:36:17Z")

</div>

the 00000 represent the value of the gallons, they are not in water at the moment, thats why they are returning 0000

---

<div class="post-metadata">

**Author:** ![shaynel2006](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@shaynel2006](https://discourse.nodered.org/u/shaynel2006)\
**Post date:** [7 September 2019 05:38 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/4 "2019-09-07T05:38:42Z")

</div>

so what i would see generally is.  
A01: 2500  
A02: 3500  
A03: 1500

the rest of the values i dont use or need, the logger has many other features

---

<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:** [7 September 2019 05:51 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/5 "2019-09-07T05:51:44Z")

</div>

Flow example:

```auto
[{"id":"c2c5211f.c3a72","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A01:2500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":256,"y":252,"wires":[["a21a343d.6d65c"]]},{"id":"364365dc.760902","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A02:3500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":308,"wires":[["a21a343d.6d65c"]]},{"id":"49cd7991.f688b","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A03:1500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":364,"wires":[["a21a343d.6d65c"]]},{"id":"a21a343d.6d65c","type":"function","z":"39e527f4.ae0088","name":"","func":"m = msg.payload.split(\":\")\nkey = m[0]\nvalue = parseFloat(m[1])\nreturn {payload:{type:key, value:value}};\n\n\n\n\n","outputs":1,"noerr":0,"x":470,"y":308,"wires":[["7c2dd21c.201b4c"]]},{"id":"22d12f31.9dc318","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":252,"wires":[]},{"id":"7c2dd21c.201b4c","type":"switch","z":"39e527f4.ae0088","name":"","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"A01","vt":"str"},{"t":"eq","v":"A02","vt":"str"},{"t":"eq","v":"A03","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":610,"y":308,"wires":[["22d12f31.9dc318"],["3c36df76.54db1"],["17c2bc1e.ea2654"]]},{"id":"3c36df76.54db1","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":308,"wires":[]},{"id":"17c2bc1e.ea2654","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":364,"wires":[]}]

```

You can replace the debug node with a gauge node and if you need additional values you can define them in the switch node.

---

<div class="post-metadata">

**Author:** ![shaynel2006](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@shaynel2006](https://discourse.nodered.org/u/shaynel2006)\
**Post date:** [7 September 2019 06:04 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/6 "2019-09-07T06:04:43Z")

</div>

> [@bakman2](#):
>
> [{"id":"c2c5211f.c3a72","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A01:2500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":256,"y":252,"wires":[["a21a343d.6d65c"]]},{"id":"364365dc.760902","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A02:3500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":308,"wires":[["a21a343d.6d65c"]]},{"id":"49cd7991.f688b","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A03:1500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":364,"wires":[["a21a343d.6d65c"]]},{"id":"a21a343d.6d65c","type":"function","z":"39e527f4.ae0088","name":"","func":"m = msg.payload.split(":")\nkey = m[0]\nvalue = parseFloat(m[1])\nreturn {payload:{type:key, value:value}};\n\n\n\n\n","outputs":1,"noerr":0,"x":470,"y":308,"wires":[["7c2dd21c.201b4c"]]},{"id":"22d12f31.9dc318","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":252,"wires":},{"id":"7c2dd21c.201b4c","type":"switch","z":"39e527f4.ae0088","name":"","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"A01","vt":"str"},{"t":"eq","v":"A02","vt":"str"},{"t":"eq","v":"A03","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":610,"y":308,"wires":[["22d12f31.9dc318"],["3c36df76.54db1"],["17c2bc1e.ea2654"]]},{"id":"3c36df76.54db1","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":308,"wires":},{"id":"17c2bc1e.ea2654","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":364,"wires":}]

The value of A01: will change as the sensor recieves lower values.  
will this just send me whatever the value is from the a01:?

---

<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:** [7 September 2019 06:05 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/7 "2019-09-07T06:05:47Z")

</div>

> will this just send me whatever the value is from the a01:?

Correct (and A02, A03)

---

<div class="post-metadata">

**Author:** ![shaynel2006](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@shaynel2006](https://discourse.nodered.org/u/shaynel2006)\
**Post date:** [7 September 2019 06:13 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/8 "2019-09-07T06:13:35Z")

</div>

> [@bakman2](#):
>
> [{"id":"c2c5211f.c3a72","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A01:2500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":256,"y":252,"wires":[["a21a343d.6d65c"]]},{"id":"364365dc.760902","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A02:3500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":308,"wires":[["a21a343d.6d65c"]]},{"id":"49cd7991.f688b","type":"inject","z":"39e527f4.ae0088","name":"","topic":"","payload":"A03:1500","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":364,"wires":[["a21a343d.6d65c"]]},{"id":"a21a343d.6d65c","type":"function","z":"39e527f4.ae0088","name":"","func":"m = msg.payload.split(":")\nkey = m[0]\nvalue = parseFloat(m[1])\nreturn {payload:{type:key, value:value}};\n\n\n\n\n","outputs":1,"noerr":0,"x":470,"y":308,"wires":[["7c2dd21c.201b4c"]]},{"id":"22d12f31.9dc318","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":252,"wires":},{"id":"7c2dd21c.201b4c","type":"switch","z":"39e527f4.ae0088","name":"","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"A01","vt":"str"},{"t":"eq","v":"A02","vt":"str"},{"t":"eq","v":"A03","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":610,"y":308,"wires":[["22d12f31.9dc318"],["3c36df76.54db1"],["17c2bc1e.ea2654"]]},{"id":"3c36df76.54db1","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":308,"wires":},{"id":"17c2bc1e.ea2654","type":"debug","z":"39e527f4.ae0088","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854,"y":364,"wires":}]

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/79c375363b8c50d33a7040066ba723c1cfaae639.png)  
what am i missing here?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d8028f017a9e9aae61aa7e1f3d44b1d81fc68bfd.png)

---

<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:** [7 September 2019 06:24 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/9 "2019-09-07T06:24:20Z")

</div>

You have to change the value format (and don't forget the scale):

 ![54](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3d4af8baad9dcf659d1d7beb9d490d95e28e864d.jpeg)

---

<div class="post-metadata">

**Author:** ![shaynel2006](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@shaynel2006](https://discourse.nodered.org/u/shaynel2006)\
**Post date:** [7 September 2019 06:37 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/10 "2019-09-07T06:37:18Z")

</div>

You are a Legend, thank you so much for taking the time

---

<div class="post-metadata">

**Author:** ![shaynel2006](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@shaynel2006](https://discourse.nodered.org/u/shaynel2006)\
**Post date:** [7 September 2019 07:03 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/11 "2019-09-07T07:03:33Z")

</div>

one last question, can i use the time from the logger?  
its TM:1909072355  
can i display this as well?

---

<div class="post-metadata">

**Author:** ![RoganFPS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/roganfps/32/3208_2.png) [@RoganFPS](https://discourse.nodered.org/u/RoganFPS)\
**Post date:** [7 September 2019 07:08 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/12 "2019-09-07T07:08:50Z")

</div>

You will have to find out what type of timestamp is being sent, this maybe something like Pico seconds and then convert it to a readable time stamp with JavaScripts date

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 September 2019 14:19 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/13 "2019-09-07T14:19:24Z")

</div>

I think it is 23:55 07/09/19

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [7 September 2019 22:28 UTC](https://discourse.nodered.org/t/splitting-a-string-and-viewing-contents/15223/14 "2019-09-07T22:28:52Z")

</div>

@shaynel2006

Just an observation:

I _think_ you are tripping yourself with the `msg.payload` structure.

In your other post about the LEDs, you have `msg.payload.value`. Here you have `msg.payload.(something else)`

This is both good and bad.

Good if you need to send the messages via/over MQTT.  
Bad in that you need to remember to do extra processing on the `msg.x` before you get what you want.

Guessing that you are sending the messages over MQTT and have constructed them so, when they are received, put the message through a `JSON` node and it will . . . reformat the message so that:  
`msg.payload.foo` becomes `msg.foo`  
`msg.payload.topic` becomes `msg.topic`  
and so on.

This isn't critical for the working of the flow, but it is adding a level of labels which isn't really needed.
