Skip to content

Commit

Permalink
log mqtt connected after error
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Oct 2, 2024
1 parent e50e105 commit e898eb6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/bindings/MQTTBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -288,13 +289,18 @@ 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);
mqttClient.on('connect', function (ack) {
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');
Expand Down

0 comments on commit e898eb6

Please sign in to comment.