diff --git a/lib/bindings/MQTTBinding.js b/lib/bindings/MQTTBinding.js index e20b2f50..a52b5560 100644 --- a/lib/bindings/MQTTBinding.js +++ b/lib/bindings/MQTTBinding.js @@ -261,6 +261,7 @@ function start(callback) { const retries = mqttConfig.retries ? mqttConfig.retries : constants.MQTT_DEFAULT_RETRIES; const retryTime = mqttConfig.retryTime ? mqttConfig.retryTime : constants.MQTT_DEFAULT_RETRY_TIME; let isConnecting = false; + let isError = false; let numRetried = 1; // retries will be disabled when MQTT_DEFAULT_RETRIES=0 config .getLogger() @@ -288,6 +289,7 @@ function start(callback) { /*jshint quotmark: double */ config.getLogger().fatal("GLOBAL-002: Couldn't connect with MQTT broker: %j", e); /*jshint quotmark: single */ + isError = true; mqttClient.end(); }); mqttClient.on('message', commonBindings.mqttMessageHandler); @@ -295,6 +297,10 @@ function start(callback) { config.getLogger().info(context, 'MQTT Client connected'); recreateSubscriptions(); numRetried = 1; + if (isError) { + config.getLogger().error(context, 'Releasing MQTT Client connected'); + isError = false; + } }); mqttClient.on('reconnect', function () { config.getLogger().debug(context, 'MQTT Client reconnect');