Serialdata and ui dashboard

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

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

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

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?

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

1 Like

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.)

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

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

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

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

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

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.

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.

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


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.

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.


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




return msg;

function one

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

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.

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.

1 Like

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

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?

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.

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.