Skip to content

Commit

Permalink
add option to allow self-signed certificate with MQTT
Browse files Browse the repository at this point in the history
also log the reason an MQTT connection failed
  • Loading branch information
ccutrer committed Jun 11, 2021
1 parent 5efe5d7 commit d603470
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"port": 1883,
"username": "",
"password": "",
"selfSignedCertificate": false,
"rootTopic": "@bind=(state.equipment.model).replace(' ','-').replace('/','').toLowerCase();",
"retain": true,
"qos": 0,
Expand Down Expand Up @@ -251,4 +252,4 @@
}
},
"appVersion": "0.0.1"
}
}
7 changes: 5 additions & 2 deletions web/interfaces/mqttInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class MqttInterfaceBindings extends BaseInterfaceBindings {
private subscribed: boolean; // subscribed to events or not
private sentInitialMessages = false;
private init = () => {

let baseOpts = extend(true, { headers: {} }, this.cfg.options, this.context.options);
if ((typeof baseOpts.hostname === 'undefined' || !baseOpts.hostname) && (typeof baseOpts.host === 'undefined' || !baseOpts.host || baseOpts.host === '*')) {
logger.warn(`Interface: ${this.cfg.name} has not resolved to a valid host.`);
Expand All @@ -52,6 +51,7 @@ export class MqttInterfaceBindings extends BaseInterfaceBindings {
clientId: this.tokensReplacer(baseOpts.clientId, undefined, toks, { vars: {} } as any, {}),
username: baseOpts.username,
password: baseOpts.password,
rejectUnauthorized: !baseOpts.selfSignedCertificate,
url
}
this.client = connect(url, opts);
Expand All @@ -63,6 +63,9 @@ export class MqttInterfaceBindings extends BaseInterfaceBindings {
} catch (err) { logger.error(err); }
});

this.client.on('error', (error) => {
logger.error(`MQTT error ${error}`)
});
}
public async stopAsync() {
try {
Expand Down Expand Up @@ -458,4 +461,4 @@ export interface IMQTT {
class MQTTMessage {
topic: string;
message: string;
}
}

0 comments on commit d603470

Please sign in to comment.