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

Fix MQTT client reconnect logic

This commit is contained in:
Nick O'Leary 2014-04-21 20:40:56 +01:00
parent 775297d625
commit 0b7fa1ab5c
2 changed files with 136 additions and 135 deletions

View File

@ -45,6 +45,7 @@ function MQTTClient(port,host) {
util.inherits(MQTTClient, events.EventEmitter);
MQTTClient.prototype.connect = function(options) {
if (!this.connected) {
var self = this;
options = options||{};
self.options = options;
@ -180,6 +181,7 @@ MQTTClient.prototype.connect = function(options) {
this.connectionError = false;
client.connect(self.options);
});
}
}
MQTTClient.prototype.subscribe = function(topic,qos) {

View File

@ -91,7 +91,6 @@ module.exports = {
client.on('connect',function() {
if (client) {
util.log('[mqtt] ['+uid+'] connected to broker tcp://'+broker+':'+port);
connecting = false;
for (var s in subscriptions) {
var topic = subscriptions[s].topic;
@ -109,13 +108,13 @@ module.exports = {
});
client.on('connectionlost', function(err) {
util.log('[mqtt] ['+uid+'] connection lost to broker tcp://'+broker+':'+port);
connecting = false;
setTimeout(function() {
if (client) {
client.connect(options);
}
obj.connect();
}, settings.mqttReconnectTime||5000);
});
client.on('disconnect', function() {
connecting = false;
util.log('[mqtt] ['+uid+'] disconnected from broker tcp://'+broker+':'+port);
});