Skip to content

Commit

Permalink
update MQTTBindings.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuedding committed Sep 27, 2023
1 parent 4c7f454 commit aa4132d
Showing 1 changed file with 75 additions and 93 deletions.
168 changes: 75 additions & 93 deletions lib/bindings/MQTTBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,104 +45,86 @@ function generateTopics(callback) {
const topics = [];

config.getLogger().debug(context, 'Generating topics');

let MQTT_SHARE_SUBSCRIPTION_GROUP_VAR = '';
if (config.getConfig().mqtt.sharedSubscriptionsDisabled === true) {
// With leading slashes
topics.push('/+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push('/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push('/+/+/' + constants.MEASURES_SUFIX);
topics.push('/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX);
topics.push('/+/+/' + constants.CONFIGURATION_SUFIX + '/' + constants.CONFIGURATION_COMMAND_SUFIX);
topics.push(
'/' +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push('/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE);
topics.push('/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE);

//Without leading slashes
topics.push('+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push(constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push('+/+/' + constants.MEASURES_SUFIX);
topics.push(constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX);
topics.push('+/+/' + constants.CONFIGURATION_SUFIX + '/' + constants.CONFIGURATION_COMMAND_SUFIX);
topics.push(
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push('+/+/' + constants.CONFIGURATION_COMMAND_UPDATE);
topics.push(constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE);
} else {
let shareSubscriptionGroup = constants.MQTT_SHARE_SUBSCRIPTION_GROUP;
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR = constants.MQTT_SHARE_SUBSCRIPTION_GROUP;
if (config.getConfig().mqtt.groupIdSufix !== undefined) {
shareSubscriptionGroup =
shareSubscriptionGroup.slice(0, -1) +
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR =
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR.slice(0, -1) +
config.getConfig().mqtt.groupIdSufix +
shareSubscriptionGroup.slice(-1);
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR.slice(-1);
}
// With leading slashes
topics.push(shareSubscriptionGroup + '/+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push(
shareSubscriptionGroup + '/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+'
);
topics.push(shareSubscriptionGroup + '/+/+/' + constants.MEASURES_SUFIX);
topics.push(shareSubscriptionGroup + '/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX);
topics.push(
shareSubscriptionGroup +
'/+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push(
shareSubscriptionGroup +
'/' +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push(shareSubscriptionGroup + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE);
topics.push(
shareSubscriptionGroup +
'/' +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_COMMAND_UPDATE
);

//Without leading slashes
topics.push(shareSubscriptionGroup + '+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push(shareSubscriptionGroup + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push(shareSubscriptionGroup + '+/+/' + constants.MEASURES_SUFIX);
topics.push(shareSubscriptionGroup + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX);
topics.push(
shareSubscriptionGroup +
'+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push(
shareSubscriptionGroup +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push(shareSubscriptionGroup + '+/+/' + constants.CONFIGURATION_COMMAND_UPDATE);
topics.push(
shareSubscriptionGroup + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE
);
}
// With leading slashes
topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '/+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR +
'/' +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.MEASURES_SUFIX +
'/+'
);
topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '/+/+/' + constants.MEASURES_SUFIX);
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '/' + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX
);
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR +
'/+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR +
'/' +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '/+/+/' + constants.CONFIGURATION_COMMAND_UPDATE);
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR +
'/' +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_COMMAND_UPDATE
);

//Without leading slashes
topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '+/+/' + constants.MEASURES_SUFIX + '/+');
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX + '/+'
);
topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '+/+/' + constants.MEASURES_SUFIX);
topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + constants.MQTT_TOPIC_PROTOCOL + '/+/+/' + constants.MEASURES_SUFIX);
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR +
'+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_SUFIX +
'/' +
constants.CONFIGURATION_COMMAND_SUFIX
);
topics.push(MQTT_SHARE_SUBSCRIPTION_GROUP_VAR + '+/+/' + constants.CONFIGURATION_COMMAND_UPDATE);
topics.push(
MQTT_SHARE_SUBSCRIPTION_GROUP_VAR +
constants.MQTT_TOPIC_PROTOCOL +
'/+/+/' +
constants.CONFIGURATION_COMMAND_UPDATE
);


callback(null, topics);
}
Expand Down

0 comments on commit aa4132d

Please sign in to comment.