Skip to content

Adding abiltity to alter MQTT version using either envVars or ConfigFile #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/BaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export default class BaseConfig{
if (!("caFile" in this.options.mqtt)) {
this.options.mqtt.caFile = null;
}

if (!("protocolVersion" in this.options.mqtt)) {
this.options.mqtt.protocolVersion = 4;
}
}

getOrgId() {
Expand Down Expand Up @@ -113,9 +117,9 @@ export default class BaseConfig{
// is not recommended for production environments.
rejectUnauthorized: true,

// MQTTv5 support doesn't work with Watson IoT Platform, so stick to default for now
// protocolId: "MQTT",
// protocolVersion: 5
//MQTT version support - MQTTv5 is currently unavailable to use due to the the mqtt.js module
protocolId: "MQTT",
protocolVersion: this.options.mqtt.protocolVersion
}
return mqttConfig;
}
Expand Down
6 changes: 5 additions & 1 deletion src/application/ApplicationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default class ApplicationConfig extends BaseConfig{
let port = process.env.WIOTP_OPTIONS_MQTT_PORT || null;
let transport = process.env.WIOTP_OPTIONS_MQTT_TRANSPORT || null;
let caFile = process.env.WIOTP_OPTIONS_MQTT_CAFILE || null;
let protocolVersion = process.env.WIOTP_OPTIONS_MQTT_VERSION || 4;
let cleanStart = process.env.WIOTP_OPTIONS_MQTT_CLEANSTART || "true";
let sessionExpiry = process.env.WIOTP_OPTIONS_MQTT_SESSIONEXPIRY || 3600;
let keepAlive = process.env.WIOTP_OPTIONS_MQTT_KEEPALIVE || 60;
Expand All @@ -106,7 +107,8 @@ export default class ApplicationConfig extends BaseConfig{
port = parseInt(port);
}
sessionExpiry = parseInt(sessionExpiry);
keepAlive = parseInt(keepAlive)
keepAlive = parseInt(keepAlive);
protocolVersion = parseInt(protocolVersion);

let identity = {appId: appId};
let options = {
Expand All @@ -120,6 +122,7 @@ export default class ApplicationConfig extends BaseConfig{
keepAlive: keepAlive,
sharedSubscription: (["True", "true", "1"].includes(sharedSubs)),
caFile: caFile,
protocolVersion: protocolVersion
},
http: {
verify: (["True", "true", "1"].includes(verifyCert))
Expand Down Expand Up @@ -155,6 +158,7 @@ export default class ApplicationConfig extends BaseConfig{
sessionExpiry: 3600
keepAlive: 60
caFile: /path/to/certificateAuthorityFile.pem
protocolVersion: 4
http:
verify: true
*/
Expand Down
6 changes: 5 additions & 1 deletion src/device/DeviceConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default class DeviceConfig extends BaseConfig{
let port = process.env.WIOTP_OPTIONS_MQTT_PORT || null;
let transport = process.env.WIOTP_OPTIONS_MQTT_TRANSPORT || null;
let caFile = process.env.WIOTP_OPTIONS_MQTT_CAFILE || null;
let protocolVersion = process.env.WIOTP_OPTIONS_MQTT_VERSION || 4;
let cleanStart = process.env.WIOTP_OPTIONS_MQTT_CLEANSTART || "true";
let sessionExpiry = process.env.WIOTP_OPTIONS_MQTT_SESSIONEXPIRY || 3600;
let keepAlive = process.env.WIOTP_OPTIONS_MQTT_KEEPALIVE || 60;
Expand All @@ -94,7 +95,8 @@ export default class DeviceConfig extends BaseConfig{
port = parseInt(port);
}
sessionExpiry = parseInt(sessionExpiry);
keepAlive = parseInt(keepAlive)
keepAlive = parseInt(keepAlive);
protocolVersion = parseInt(protocolVersion);

let identity = {orgId:orgId, typeId: typeId, deviceId:deviceId};
let options = {
Expand All @@ -108,6 +110,7 @@ export default class DeviceConfig extends BaseConfig{
keepAlive: keepAlive,
sharedSubscription: (["True", "true", "1"].includes(sharedSubs)),
caFile: caFile,
protocolVersion: protocolVersion,
},
};
let auth = null;
Expand Down Expand Up @@ -140,6 +143,7 @@ export default class DeviceConfig extends BaseConfig{
sessionExpiry: 3600
keepAlive: 60
caFile: /path/to/certificateAuthorityFile.pem
protocolVersion: 4
*/

const configFile = fs.readFileSync(configFilePath, 'utf8');
Expand Down
1 change: 1 addition & 0 deletions test/ApplicationConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('WIoTP Application Configuration', () => {
expect(config.options.mqtt.sessionExpiry).to.equal(3600);
expect(config.options.mqtt.keepAlive).to.equal(60);
expect(config.options.mqtt.caFile).to.equal("myPath");
expect(config.options.mqtt.protocolVersion).to.equal(4);
expect(config.options.http.verify).to.equal(true);
});

Expand Down
1 change: 1 addition & 0 deletions test/ApplicationConfigFile.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
sessionExpiry: 3600
keepAlive: 60
caFile: myPath
protocolVersion: 4
http:
verify: true
1 change: 1 addition & 0 deletions test/DeviceConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('WIoTP Device Configuration', () => {
expect(config.options.mqtt.sessionExpiry).to.equal(3600);
expect(config.options.mqtt.keepAlive).to.equal(60);
expect(config.options.mqtt.caFile).to.equal("myPath");
expect(config.options.mqtt.protocolVersion).to.equal(4);
});

});
1 change: 1 addition & 0 deletions test/DeviceConfigFile.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
sessionExpiry: 3600
keepAlive: 60
caFile: myPath
protocolVersion: 4