Multiple Payload in formated Output

Hello NodeRed User

i am new here and i need some help.
I am not an expert in coding (Not Programmer) but i understand how works Node-Red.

I have a JSON String like this

{"_timestamp": 1551212773, "Temp": 22.80, "Pressure": 1015, "Humidity": 80}

I made a function example with this code :

var temp = "30";
var hum = "80";
var press = "1050"

var msg1 = { payload: "user DG8RAD pass XXXX" };
var msg2 = { payload: "DG8RAD-1>APRS,TCPIP*:!4808.30N/01125.75E_000/000g003t030r000p000P000h80b09900wRSW" };                          
var msg3 = { payload: "DG8RAD-1>APRS,TCPIP*:>Maker Themen, LoraWAN, Arduino, Raspberry, SmartHome und AFU" };                          
var msg4 = { payload: "File delete" };                          
return [ [ msg1, msg2, msg3 ], msg4 ]

I need exactly this syntax because is Part of APRS Protocol for Ham Radio.

How can add Temp / Pressure / Hum into this String of "var msg2"

I was thinking like in this form :

var msg2 = { payload: "DG8RAD-1>APRS,TCPIP*:!4808.30N/01125.75E_000"+temp"/000g003t030r000p000P000h80b09900wRSW" };

But it doesn't work properly.
Have anyone any idea how can implement this values ?

Best regards Joachim

you are missing a plus after your variable name

Thanks a lot , problem solved
My fault :frowning:

var msg2 = { payload: "DG8RAD-1>APRS,TCPIP*:!4808.30N/01125.75E_000/000g003t0"+temp+"r000p000P000h"+hum+"b"+press+"0wRSW" };

Assuming you are using Node.js above v8.5 or so, you should also be able to use template strings which can be easier to read for things like this:

var msg2 = { payload: `DG8RAD-1>APRS,TCPIP*:!4808.30N/01125.75E_000${temp}/000g003t030r000p000P000h80b09900wRSW` };

Note the use of back-ticks as string delimiters and the variable wrapped in ${} (which can be any JavaScript that returns something that can be interpreted as a string).

1 Like