Two messages in one function

Hi !

First sorry for my bad english :slight_smile:

I'm trying to make a node-red function to send two msg.

One of these message contain a variable.

The messages must be like this:

  • msg1: NEXTION,conschauf.txt="19"
  • msg2: NEXTION,p1.pic=8

The value "19" of msg1 is stored in node-red by an other node ( flow.set('consigneconfort', msg.payload.result[0].SetPoint); )

I have write this function:

msg.topic = "ECRAN-ENTREE/cmd";
if (flow.get('modeconfort') === "On") {
    var consigne = flow.get('consigneconfort');
    var msg1 = { payload: 'NEXTION,conschauf.txt="consigne"'};
    var msg2 = { payload: 'NEXTION,p1.pic=8' };
}
return [msg1, msg2];

but the result is:

  • an "Invalid topic specified" error
  • the first message is like this: "NEXTION,conschauf.txt="consigne""

Someone can help me to find the problem, please ?

Regards,

To insert the value of consigne in the message payload, you can do the following.

var msg1 = { payload: `NEXTION,conschauf.txt="${consigne}"`};

As for the function - you are settings msg.topic but then return the msg1 and msg2 objects that don't have topic set. If you want the topic property to be set on those objects, you will need to set it:

var msg1 = { payload: `NEXTION,conschauf.txt="${consigne}"`, topic: "ECRAN-ENTREE/cmd"};
var msg2 = { payload: 'NEXTION,p1.pic=8', topic: "ECRAN-ENTREE/cmd" };
1 Like

Yes !!

Thank you very much :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.