Add mqtt, mqtts, ws and wss protocols to the mqtt monitor

This commit is contained in:
David Twigger 2023-01-05 08:57:48 +01:00
parent b049e4e1b4
commit c196c34840
2 changed files with 7 additions and 5 deletions

View file

@ -135,7 +135,7 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
const { port, username, password, interval = 20 } = options;
// Adds MQTT protocol to the hostname if not already present
if (!/^(?:http|mqtt)s?:\/\//.test(hostname)) {
if (!/^(?:http|mqtt|ws)s?:\/\//.test(hostname)) {
hostname = "mqtt://" + hostname;
}
@ -145,10 +145,11 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
reject(new Error("Timeout"));
}, interval * 1000 * 0.8);
log.debug("mqtt", "MQTT connecting");
const mqttUrl = `${hostname}:${port}`
log.debug("mqtt", `MQTT connecting to ${mqttUrl}`);
let client = mqtt.connect(hostname, {
port,
let client = mqtt.connect(mqttUrl, {
username,
password
});