Add birth message to MQTT node

This commit is contained in:
Nick O'Leary
2015-09-02 11:18:59 +01:00
parent fcf4f40c36
commit c1d694a97c
4 changed files with 59 additions and 6 deletions

View File

@@ -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();