# Serialdata and ui dashboard

**URL:** https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046
**Category:** General
**Created:** [4 March 2021 19:37 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046 "2021-03-04T19:37:34Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [4 March 2021 19:37 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/1 "2021-03-04T19:37:34Z")

</div>

Hello, first and foremost i am a newbie learning on the fly. biggest problem is the different ways node red can do a function, however after watching so many videos im left to thinking that i have several issues. but lets start with what i am trying to do,  
1, i have hooked up one pressure transducer to an arduino,  
2. its connected to my rpi4 via usb.  
3. in node red i have a serial in node and it is receiving the data from the Arduino  
i have 2 parts of data coming separated by a comma.  
i need these split so i can send each to there own gauge.  
i plan on adding 2 more transducers that will create 4 more pieces of data that will need split up but I have to understand how to do one before I move on to adding the extra pieces. i have a csv node and it adds colums to them.  
{"col1":"118.92","col2":"1.0"} how do i go from this to having 2 different messages so i can then connect to the ui\_guage node.  
Thanks,  
Billy Jack

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [4 March 2021 20:09 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/2 "2021-03-04T20:09:05Z")

</div>

The gauge should be able to handle setting the value to {{payload.col1}} etc

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [4 March 2021 20:35 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/3 "2021-03-04T20:35:56Z")

</div>

Omg, thank you so much, that has it perfect.  
Now say I need to use col1 data and throw it into a formula or use to log data to calculate flow rate of a pump, would I access the info the same way in a function node etc

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [4 March 2021 20:47 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/4 "2021-03-04T20:47:55Z")

</div>

i guess i should clarify. say each piece of data is just a psi from a different sensor.  
i need to use some math to convert the psi readings into volume of tanks.  
how do i access that data properly in a function node to do my math for me and issue out a new payload  
formula is /  
"psidata" x 27.72 / "specific gravity" this calculates my water column of a tank.  
(second part will be that i have to calculate specific gravity wich is done by  
(watercolumnA-watercolumnB) / "distance between A and B sensors = specific gravity  
would i use a function node connected to my csv node and use " {{payload.col1}} " in the formula?

---

<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: [4 March 2021 21:04 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/5 "2021-03-04T21:04:27Z")

</div>

No need for a function node, you can use a Range node which you can configure to scale msg.payload.col1 using whatever scale/offset you require.

If you did want to use it in a Function node the syntax is javascript so it would be something like  
`msg.payload = msg.payload.col1 * 27.2/sg`

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [4 March 2021 21:23 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/6 "2021-03-04T21:23:11Z")

</div>

ok so for simple if im just calculating volume in a tank with just water i do not have to do the divide by sg so formula is this  
msg.payload = msg.payload.col2 \* 27.72 \* 1017.36 \* .004329  
however if i had to do the divide it would be  
msg.payload = msg.payload.col2 \* 27.72 / sg \* 1017.36 \* .004329  
and if i was to figure the difference for specific gravity i'm better off doing that on the arduino.  
or should i simplify everything on pi  
do all my stuff on arduino  
so my output is just  
gallons in each kettle and specific gravity for the boil kettle ( i have 2 tanks hlt will always have a sg of 1 however boil kettle sg will change all the time.)

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [4 March 2021 21:24 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/7 "2021-03-04T21:24:25Z")

</div>

for more info 1017.36 is my area of my tanks.  
.004329 is how many gallons are in 1 cubic inch

---

<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: [4 March 2021 21:47 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/8 "2021-03-04T21:47:01Z")

</div>

Do it wherever is easiest for you, unless there is a good reason to do it the more difficult way.

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [4 March 2021 22:11 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/9 "2021-03-04T22:11:10Z")

</div>

so in my function it calculates right, how do i round the answer to 2 decimal points?

---

<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: [5 March 2021 09:01 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/10 "2021-03-05T09:01:26Z")

</div>

> [@dceejay](#):
>
> {{payload.col1}}

Assuming this is for a gauge then in the Value Format field put `{{payload | Number: 2}} `

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [5 March 2021 20:47 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/11 "2021-03-05T20:47:08Z")

</div>

got it now new problem  
line one works but line 2 and line 3 are not giving me my vallues. correctly what did i do wrong.  
this is done in Function Node  
msg.gallonshlt = msg.payload.col2 \* 27.72 \* 1017.36 \* .004329  
msg.specificgravity =(msg.payload.col2 \* 27.72) - (msg.payload.col2 \* 27.72) / 12  
msg.gallonsboil = msg.payload.col2 \* 27.72 / (msg.specificgravity) \* 1017.72 \* .004329  
return msg;

I believe the problem lies within the msg.specificgravity formula. there needs to be an if statement. if the specific gravity calculates lets the 1.0000 then the SG should just be 1.0  
please advise. thanks.  
cheers

---

<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: [5 March 2021 21:42 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/12 "2021-03-05T21:42:11Z")

</div>

> [@9toejack](#):
>
> if the specific gravity calculates lets the 1.0000 then the SG should just be 1.0

Is there a typo there? It does not make sense to me.

You would save a lot of typing if you started with  
`let value = msg.payload.col2 * 27.72`  
then use `value` where appropriate in successive lines. Call it something other than value if it has some meaning.  
Are you sure about your formulae, they look a bit odd to me.

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [5 March 2021 22:01 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/13 "2021-03-05T22:01:55Z")

</div>

if you mean where all 3 lines use msg.payad.col2  
not for now there will be a col1 , col2, and col3 when I install other 2 sensors.  
so i need 3 different values sent for the 3 guages i plan to use.

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [5 March 2021 22:05 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/14 "2021-03-05T22:05:30Z")

</div>

can i label those value1 , value2 , etc or do they have to say value

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [5 March 2021 22:17 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/15 "2021-03-05T22:17:44Z")

</div>

```auto

msg.hlt = msg.payload.col2 * 27.72 * 1017.36 * 0.004329

let sg = (msg.payload.col2 * 27.72) - (msg.payload.col2 * 27.72) / 12

if (sg <=1){
msg.sg = "1";
}
else {
msg.sg = "sg ";
}
msg.boil = msg.payload.col2 * 27.72 / (sg) * 1017.72 * 0.004329

return msg;

```

this is how i have it now . but the calculation for sg is causing the hang up  
hlt displays correctly boil kettle and sg do not.

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [5 March 2021 23:14 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/16 "2021-03-05T23:14:21Z")

</div>

ok i figured it out by splitting into 3 different functions. Also caught my formula for sg was missing a set of () all is better now.

```auto

msg.hlt = msg.payload.col2 * 27.72 * 1017.36 * 0.004329

return msg;

```

function one

```auto
let valuesg = ((msg.payload.col2 * 27.72) - (msg.payload.col2 * 27.72)) / 12

if (valuesg <=1){
msg.sg = 1;
}
else {
msg.sg = valuesg;
}
return msg;

```

function 2

```auto
let valuesg = ((msg.payload.col2 * 27.72) - (msg.payload.col2 * 27.72)) / 12

if (valuesg <=1){
msg.sg = 1;
}
else {
msg.sg = valuesg;
}
return msg;

```

Thanks a bunch, i was trying to only have one function node. but its better to have multiple for a quick visual of what is doing what.  
Cheers.

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [6 March 2021 04:35 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/17 "2021-03-06T04:35:15Z")

</div>

so with beer (the reason im doing this)  
gravity runs higher then water. water specific gravity is 1.0  
how ever beer wort runs as low as 1.040 and hi up to 1.100 or maybe higher.  
so i need at least 3 decimals to have an accurate sg for beer formulas.

---

<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: [6 March 2021 09:42 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/18 "2021-03-06T09:42:33Z")

</div>

> [@9toejack](#):
>
> `let valuesg = ((msg.payload.col2 * 27.72) - (msg.payload.col2 * 27.72)) / 12`

That is always zero, so after the check that follows sg will always be 1.

Please tell us the actual formulas you are trying to use to calculate the result. Google has told me that 27.72 inches of water pressure equates to 1 psi so presumably that is where the 27.72 comes in, but where does the 1/12 come in that lets you calc the sg?

Also then what are the other calculations doing? Tell us what you are actually trying to calculate and we will be able to help.

In the meantime, to get you closer perhaps you want something like

```auto
let val = msg.payload.col2 * 27.72
msg.gallonshlt = val * 1017.36 * 0.004329
let sg = val - val/12
if (sg < 1) sg = 1
msg.gallonsboil = val * 1017.72 * 0.004329 / sg
msg.specificgravity = sg
return msg;

```

Why is it 1017.36 for the first calculation and 1017.72 for the last?

---

<div class="post-metadata">

### Author: ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)
#### Post date: [6 March 2021 10:23 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/19 "2021-03-06T10:23:17Z")

</div>

first and for most all the formula's have msg.payload.col2 plugged in because as of now thats the only pressure transducer i have connected at the moment.  
as far as 1017.36 vs 1017.72 the .72 was a typo and i have already fixed that.  
the /12 that number was a planned sepperation of the 2 sensors i'm installing into my boil kettle.  
i actually decided to just use existing ports that i have and to use "3-way tees" to install the press transducers.  
to calculate specific gravity the calculation is  
((water column inches from sensor a ) - (water column inches from sensor 2 )) / (the distance the sensors are apart) = specific gravity.  
the great thing is water specific gravity is 1.000 at 59 degrees.  
so i can calibrate sensors with water and temp.  
get exact distance between sensors. and then the number of "12" will be replaced by the exact distance they are apart so i can calculate specific gravity  
and then use specific gravity to calculate the true water colomn of the wort in boil kettle.  
biggest one to know that not every spot will be msg.payload.col2  
there will be msg. payload.col1 wich will be hlt psi.  
col2 will be boilmain sensor.  
and col3 will be boilsec.  
eventually ill add mash tun sensors.  
and possibly fermenter sensors. so i can monitor the porgress of the fermentation.  
by biggest issue was trying to do all the formulas in one function node.  
splitting them apart makes it easier to modify one thing without having to worry about accidently modifying something else.  
as soon as i have it connected in am. ill get better test going.  
and then i will post the hole flow.  
cheers.

---

<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: [6 March 2021 10:50 UTC](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046/20 "2021-03-06T10:50:44Z")

</div>

OK, now it makes more sense, so where at the moment you have col2 in the sg calc they won't both be col2.  
Well at least my code shows you how you can clamp the sg at 1 a little more neatly.

[Next page](https://discourse.nodered.org/t/serialdata-and-ui-dashboard/42046.md?page=2)
