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

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