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) {
this.broker = RED.nodes.getNode(config.brokerName) as MQTTBrokerNode;
const options:BrokerOptions = this.broker.options || {};
options.will = { topic: "my/last/will", payload: this.oneOfMySettings, qos: QOS.AT_LEAST_ONCE, retain: false };
this.broker.options = options;
console.log("LWT: " + JSON.stringify(this.broker.options));
}
Thanks, Thomas