From d43fff344438cfd8b81366583fc76fc88f7ac8d9 Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Wed, 31 Jan 2024 14:49:40 +0100 Subject: [PATCH] optional mqtt authentication Signed-off-by: Mark Herwege --- README.md | 2 +- meta.js | 7 ++++++- settings.js | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 60c8d68..20b7769 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ bash <(wget -qO- https://raw.githubusercontent.com/jac459/meta/Release/update.sh ## C - How to install meta if You are a Raspberry/Linux Black Belt - The meta can be installed like any node.js program by taking the files and typing "npm install". - The meta NEEDS MQTT to run. NODE-RED is highly advised. -- MQTT is expected to not have any authentication. +- By default, MQTT is expected to not have any authentication. You can connect to a local MQTT host with authentication by setting the username and password in settings.js (uncomment the specific lines). - Meta-core driver expect node-red, mqtt and meta to by run by pm2. Not by services. This is not a big deal if you don't plan to use it. - The meta expect 2 folders: library (for all drivers) and active (for activated drivers). - You can configure the name, port of the meta in order to run multiple instances of the meta (have different names and port for the neeo). This is very useful if you want to run a new version of the meta without taking risk on your previous version. diff --git a/meta.js b/meta.js index 25b7b24..eafe845 100644 --- a/meta.js +++ b/meta.js @@ -942,7 +942,12 @@ if (process.argv.length>2) { getConfig().then(() => { networkDiscovery(); - mqttClient = mqtt.connect('mqtt://' + settings.mqtt, {clientId:settings.mqttClientId}); // Always connect to the local mqtt broker + var options = { + clientId: settings.mqttClientId, + username: settings.mqttUsername, + password: settings.mqttPassword + } + mqttClient = mqtt.connect('mqtt://' + settings.mqtt, options); // Always connect to the local mqtt broker mqttClient.setMaxListeners(0); //CAREFULL OF MEMORY LEAKS HERE. mqttClient.on('connect', () => { metaLog({type:LOG_TYPE.WARNING, content:"Connection to MQTT Broker Successful."}); diff --git a/settings.js b/settings.js index 2de006c..e56299e 100644 --- a/settings.js +++ b/settings.js @@ -7,6 +7,8 @@ var settings = 'runtimeName' : '.meta', 'defaultPort' : '4016', 'mqttClientId' : 'meta', + // 'mqttUsername' : 'username', + // 'mqttPassword' : 'password', 'activeLibrary' : './active' }