From 4118de6d533205e409c18e44d752e32f0a32b664 Mon Sep 17 00:00:00 2001 From: Tarun Singh Date: Thu, 23 Dec 2021 19:39:47 -0500 Subject: [PATCH] fix protocol not defined bug --- server/util-server.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/util-server.js b/server/util-server.js index 163547dcd..50ed02304 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -94,6 +94,10 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) { return new Promise((resolve, reject) => { const { port, username, password, interval = 20 } = options; try { + // Adds mqtt protocol to the hostname if not already present + if (!/^(?:http|mqtt)s?:\/\//.test(hostname)) { + hostname = "mqtt://" + hostname; + } let client = mqtt.connect(hostname, { port, username,