add Username and Password fields to MQTT Outbound

cron-as-worker-process
Moe 2022-06-06 13:32:58 -07:00
parent 42838d7cda
commit a63e08f48e
2 changed files with 14 additions and 2 deletions

View File

@ -8,12 +8,20 @@ module.exports = function(s,config,lang,getSnapshot){
} = require('../events/utils.js')(s,config,lang)
try{
function createMqttSubscription(options){
const mqttEndpoint = options.host
let mqttEndpoint = options.host
const username = options.username || ''
const password = options.password || ''
const subKey = options.subKey
const groupKey = options.ke
const onData = options.onData || function(){}
if(mqttEndpoint.indexOf('://') === -1){
mqttEndpoint = `mqtt://${mqttEndpoint}`
}
s.debugLog('Connecting.... mqtt://' + mqttEndpoint)
const client = mqtt.connect('mqtt://' + mqttEndpoint)
const client = mqtt.connect('mqtt://' + mqttEndpoint,{
username: username,
password: password,
})
client.on('connect', function () {
s.debugLog('Connected! mqtt://' + mqttEndpoint)
client.subscribe(subKey, function (err) {

View File

@ -58,6 +58,10 @@ $(document).ready(function(){
<input placeholder="${lang.Example} : mqtt.server.host" class="form-control form-control-sm mb-2" mqtt-param="host" value="${row.host || ''}">
<input placeholder="${lang.Example} : your/events" class="form-control form-control-sm" mqtt-param="pubKey" value="${row.pubKey || ''}">
</div>
<div class="px-1 py-2">
<input placeholder="${lang.Username}" class="form-control form-control-sm mb-2" mqtt-param="username" value="${row.username || ''}">
<input placeholder="${lang.Password}" class="form-control form-control-sm" mqtt-param="password" value="${row.password || ''}">
</div>
<div class="px-1 py-2">
<select multiple class="form-control form-control-sm" mqtt-param="msgFor">
${selecteEventsHtml}