mirror of
https://github.com/node-red/node-red.git
synced 2025-12-26 23:26:46 +01:00
Add birth message to MQTT node
This commit is contained in:
@@ -51,6 +51,14 @@ module.exports = function(RED) {
|
||||
this.queue = [];
|
||||
this.subscriptions = {};
|
||||
|
||||
if (n.birthTopic) {
|
||||
this.birthMessage = {
|
||||
topic: n.birthTopic,
|
||||
payload: n.birthPayload || "",
|
||||
qos: Number(n.birthQos||0),
|
||||
retain: n.birthRetain=="true"|| n.birthRetain===true
|
||||
};
|
||||
}
|
||||
events.EventEmitter.call(this);
|
||||
this.setMaxListeners(0);
|
||||
|
||||
@@ -159,6 +167,11 @@ module.exports = function(RED) {
|
||||
node.client.subscribe(topic, options);
|
||||
}
|
||||
|
||||
// Send any birth message
|
||||
if (node.birthMessage) {
|
||||
node.publish(node.birthMessage);
|
||||
}
|
||||
|
||||
// Send any queued messages
|
||||
while(node.queue.length) {
|
||||
var msg = node.queue.shift();
|
||||
|
||||
Reference in New Issue
Block a user