1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add status indicators to serial and tcp (client) nodes

This commit is contained in:
Dave C-J 2014-05-12 16:32:19 +01:00
parent e15a0d545d
commit 7e71a118eb
2 changed files with 52 additions and 31 deletions

View File

@ -70,6 +70,12 @@ module.exports = function(RED) {
}
});
});
node.port.on('ready', function() {
node.status({fill:"green",shape:"dot",text:"connected"},true);
});
node.port.on('closed', function() {
node.status({fill:"red",shape:"ring",text:"not connected"},true);
});
} else {
this.error("missing serial config");
}
@ -89,6 +95,7 @@ module.exports = function(RED) {
if (this.serialConfig) {
var node = this;
node.status({fill:"grey",shape:"dot",text:"unknown"},true);
node.port = serialPool.get(this.serialConfig.serialport,
this.serialConfig.serialbaud,
this.serialConfig.databits,
@ -98,6 +105,12 @@ module.exports = function(RED) {
this.port.on('data', function(msg) {
node.send({ "payload": msg });
});
this.port.on('ready', function() {
node.status({fill:"green",shape:"dot",text:"connected"},true);
});
this.port.on('closed', function() {
node.status({fill:"red",shape:"ring",text:"not connected"},true);
});
} else {
this.error("missing serial config");
}
@ -152,6 +165,7 @@ module.exports = function(RED) {
}
obj.serial.on('error', function(err) {
util.log("[serial] serial port "+port+" error "+err);
obj._emitter.emit('closed');
obj.tout = setTimeout(function() {
setupSerial();
}, settings.serialReconnectTime);
@ -159,6 +173,7 @@ module.exports = function(RED) {
obj.serial.on('close', function() {
if (!obj._closing) {
util.log("[serial] serial port "+port+" closed unexpectedly");
obj._emitter.emit('closed');
obj.tout = setTimeout(function() {
setupSerial();
}, settings.serialReconnectTime);

View File

@ -40,10 +40,12 @@ module.exports = function(RED) {
var reconnectTimeout;
function setupTcpClient() {
node.log("connecting to "+node.host+":"+node.port);
node.status({fill:"grey",shape:"dot",text:"connecting"},true);
var id = (1+Math.random()*4294967295).toString(16);
client = net.connect(node.port, node.host, function() {
buffer = (node.datatype == 'buffer')? new Buffer(0):"";
node.log("connected to "+node.host+":"+node.port);
node.status({fill:"green",shape:"dot",text:"connected"},true);
});
connectionPool[id] = client;
@ -85,6 +87,7 @@ module.exports = function(RED) {
client.on('close', function() {
delete connectionPool[id];
node.log("connection lost to "+node.host+":"+node.port);
node.status({fill:"red",shape:"ring",text:"disconnected"});
if (!node.closing) {
reconnectTimeout = setTimeout(setupTcpClient, reconnectTime);
}
@ -194,9 +197,11 @@ module.exports = function(RED) {
function setupTcpClient() {
node.log("connecting to "+node.host+":"+node.port);
node.status({fill:"grey",shape:"dot",text:"connecting"},true);
client = net.connect(node.port, node.host, function() {
connected = true;
node.log("connected to "+node.host+":"+node.port);
node.status({fill:"green",shape:"dot",text:"connected"},true);
});
client.on('error', function (err) {
node.log('error : '+err);
@ -205,6 +210,7 @@ module.exports = function(RED) {
});
client.on('close', function() {
node.log("connection lost to "+node.host+":"+node.port);
node.status({fill:"red",shape:"ring",text:"disconnected"},true);
connected = false;
client.destroy();
if (!node.closing) {