Make status display toggleable and add to MQTT nodes

This commit is contained in:
Nick O'Leary
2014-05-10 23:33:02 +01:00
parent ec5985eaa3
commit 7e85eb297d
4 changed files with 47 additions and 7 deletions

View File

@@ -77,7 +77,9 @@ module.exports = function(RED) {
this.topic = n.topic;
this.broker = n.broker;
this.brokerConfig = RED.nodes.getNode(this.broker);
var node = this;
if (this.brokerConfig) {
this.status({fill:"red",shape:"ring",text:"disconnected"},true);
this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.brokerConfig.clientid,this.brokerConfig.username,this.brokerConfig.password);
var node = this;
this.client.subscribe(this.topic,2,function(topic,payload,qos,retain) {
@@ -87,6 +89,12 @@ module.exports = function(RED) {
}
node.send(msg);
});
this.client.on("connectionlost",function() {
node.status({fill:"red",shape:"ring",text:"disconnected"},true);
});
this.client.on("connect",function() {
node.status({fill:"green",shape:"dot",text:"connected"},true);
});
this.client.connect();
} else {
this.error("missing broker configuration");
@@ -109,8 +117,10 @@ module.exports = function(RED) {
this.broker = n.broker;
this.brokerConfig = RED.nodes.getNode(this.broker);
var node = this;
if (this.brokerConfig) {
this.status({fill:"red",shape:"ring",text:"disconnected"},true);
this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.brokerConfig.clientid,this.brokerConfig.username,this.brokerConfig.password);
this.on("input",function(msg) {
if (msg != null) {
@@ -120,6 +130,13 @@ module.exports = function(RED) {
this.client.publish(msg);
}
});
this.client.on("connectionlost",function() {
node.status({fill:"red",shape:"ring",text:"disconnected"},true);
});
this.client.on("connect",function() {
node.status({fill:"green",shape:"dot",text:"connected"},true);
});
this.client.connect();
} else {
this.error("missing broker configuration");