From 0055302bdcf2b1c0e77362a573e6c66be79b174c Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Wed, 11 Apr 2018 21:09:19 +0200 Subject: [PATCH] Support MQTT authentication. #2 --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 7e84e6d927..8c96a00182 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,14 @@ if (!settings.devices) { // Setup client console.log(`Connecting to MQTT server at ${settings.mqtt.server}`) -const client = mqtt.connect(settings.mqtt.server) + +const options = {}; +if (settings.mqtt.user && settings.mqtt.password) { + options.username = settings.mqtt.user; + options.password = settings.mqtt.password; +} + +const client = mqtt.connect(settings.mqtt.server, options) const shepherd = new ZShepherd( settings.serial.port, {