Set MQTT-Nodes LWT message from my configuration node

I am working on a Node-RED node that implements a specification for an industry alliance (in case you are interested, it is the Open Industry 4.0 Alliance).

The communication sets up on MQTT and the specification describes how to messages are structured, topics are build and more. One thing is, that the birth, close and LWT message is defined.

I do not want to reimplement the MQTT connection, so I am trying to reuse the existing build in MQTT component. My configuration has the possibility to set the MQTT configuration to be used.

Now I am trying to "dynamically" set LWT message of the MQTT config node from within my config node. I can set the message on the MQTT options once I received them with RED.nodes.getNode, but there are not set at the configuration node. At least when I open the underlying MQTT configuration the changes are not applied.

I am pretty sure, that what I do is not (most) intended way to interact with configuration nodes, but nevertheless is it even possible? Or is there an even better way how to do that? Maybe by creating MQTT configuration node directly?

Here is a short snipped, how I try to achieve it (in Typescript):

this.oneOfMySettings = config.oneOfMySettings || "undefined";

if (config.brokerName) { = RED.nodes.getNode(config.brokerName) as MQTTBrokerNode;
    const options:BrokerOptions  = || {};
    options.will = { topic: "my/last/will", payload: this.oneOfMySettings, qos: QOS.AT_LEAST_ONCE, retain: false }; = options;
    console.log("LWT: " + JSON.stringify(;

Thanks, Thomas

1 Like

How would you expect that to work given that the LWT message is sent by the broker based on the client connection? The client sets up the connection and part of the config is the LWT. Node-RED does not, I believe, allow dynamic MQTT client connections. To change the LWT, you have to change the client connection and that is defined in a configuration node. Redeployment of that node is required in order to change any of the settings. That tears down the client connection and rebuilds/restarts it.

1 Like

Not yet, but hopefully in next beta
:crossed_fingers: :

That exactly what I want to do. I want to change the config node, or better the configuration of a specific MQTT connection and then of course redeploy it. The changes are made "under the hood" by my configuration node. This changes will only be applied with a redeployment, so this need would be fulfilled as well.
And yes, redeploying the config node means, that the connection goes down for a short time. But that is acceptable in my case.

Well, contrib nodes do not normally make use of someone else's configuration node but actually I don't think there is any actually limitation on that. So lookup the name of the foreign config node in the code and reuse it in your own nodes. You may wish to make the module that defines that config node a peer dependency in your own module though so that users have a clue - as well as indicating clearly in the documentation of course.

Though I suspect that providing your own version of that MQTT server config node would be a safer idea.

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