diff --git a/lib/bindings/mqttClient.js b/lib/bindings/mqttClient.js index 0d6449e..c2c4bdf 100644 --- a/lib/bindings/mqttClient.js +++ b/lib/bindings/mqttClient.js @@ -58,6 +58,7 @@ class MqttClient { var options = {}; options.username = this.username; options.password = this.password; + var connected = false; winston.info('Connecting to MQTT server %s with options:%s', host, JSON.stringify(options)); this.mqttClient = mqtt.connect( @@ -70,7 +71,10 @@ class MqttClient { this.mqttClient.on('message', this.listener); this.mqttClient.on('connect', function(object, binding) { winston.info('Connected to MQTT server'); - return callback(); + if (!connected) { + connected = true; + return callback(); + } }); }