Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Added option to specify custom clientId for the MqttClient #89

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
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (conf.get("mqtt")) {
// eslint-disable-next-line no-unused-vars
const mqttClient = new MqttClient({
brokerURL: conf.get("mqtt").broker_url,
clientId: conf.get("mqtt").clientId,
caPath: conf.get("mqtt").caPath,
identifier: conf.get("mqtt").identifier,
topicPrefix: conf.get("mqtt").topicPrefix,
Expand Down
6 changes: 6 additions & 0 deletions lib/MqttClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MqttClient {
*
* @param {object}options
* @param {string} options.brokerURL
* @param {string} options.clientId
* @param {string} options.caPath
* @param {string} options.identifier
* @param {string} options.topicPrefix
Expand All @@ -27,6 +28,7 @@ class MqttClient {
*/
constructor(options) {
this.brokerURL = options.brokerURL;
this.clientId = options.clientId ?? "";
this.caPath = options.caPath ?? "";
this.identifier = options.identifier ?? "rockrobo";
this.topicPrefix = options.topicPrefix ?? "valetudo";
Expand Down Expand Up @@ -64,6 +66,10 @@ class MqttClient {
connect() {
if (!this.client || (this.client && !this.client.connected && !this.client.reconnecting)) {
const options = {};
if (this.clientId) {
options.clientId = this.clientId;
}

if (this.caPath) {
options.ca = fs.readFileSync(this.caPath);
}
Expand Down
1 change: 1 addition & 0 deletions lib/res/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"topicPrefix": "valetudo",
"autoconfPrefix": "homeassistant",
"broker_url": "mqtt://user:[email protected]",
"clientId": "",
"caPath": "",
"mapDataTopic": "valetudo/robot/MapData/map-data",
"minMillisecondsBetweenMapUpdates": 10000,
Expand Down