Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ input:
# url: mqtt://test.mosquitto.org
# # see connect options: https://www.npmjs.com/package/mqtt#connect
# connectOptions:
# userName: nobody
# username: nobody
# password: secret
# topics:
# - log-messages
Expand Down Expand Up @@ -824,6 +824,8 @@ output:
# module: output-mqtt
# url: mqtt://test.mosquitto.org
# topic: sensor-data
# qos: 2
# retain: false
# debug: false
# # optional filter settings matching data field with regular expressions
# filter:
Expand All @@ -833,6 +835,8 @@ output:
# module: output-mqtt
# url: mqtt://test.mosquitto.org
# topic: log-data
# qos: 2
# retain: false
# debug: false
# filter:
# field: logSource
Expand Down
6 changes: 4 additions & 2 deletions config/examples/mqtt-output.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ output:
url: mqtt://test.mosquitto.org
# see https://www.npmjs.com/package/mqtt#connect
#connectOptions:
# userName: nobody
# username: nobody
# password: secret
# keepAlive: 60
# keepalive: 60
# wsOptions:
# port: 9999
# host: localhost
topic: sensor-data
qos: 2
retain: false
debug: false
# optional filter settings matching data field with regular expressions
filter:
Expand Down
13 changes: 8 additions & 5 deletions lib/plugins/output/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ var consoleLogger = require('../../util/logger.js')

/** example configuration
output:
module: mqtt
module: output-mqtt
url: mqtt://127.0.0.1:1883
topic: all_events
qos: 2
retain: false
# see https://www.npmjs.com/package/mqtt#connect options
connectOptions:
userName: nobody
username: nobody
password: secret
keepAlive: 60
keepalive: 60
wsOptions:
port: 9999
host: localhost
Expand All @@ -36,6 +38,7 @@ module.exports = OutputMqtt
OutputMqtt.prototype.eventHandler = function (data, context) {
var msg = safeStringify(data)
var topic = this.config.topic
const { qos = 0, retain = false } = this.config
if (this.config.dynamicTopic !== undefined) {
topic = eval(this.config.dynamicTopic)
consoleLogger.log('Topic ' + topic)
Expand All @@ -59,7 +62,7 @@ OutputMqtt.prototype.eventHandler = function (data, context) {
if (this.config.debug === true) {
consoleLogger.log('mqtt publish -t ' + topic + ' -m ' + msg)
}
return this.client.publish(topic, msg)
return this.client.publish(topic, msg, { qos, retain })
} else {
if (this.config.debug === true) {
consoleLogger.log(
Expand All @@ -72,7 +75,7 @@ OutputMqtt.prototype.eventHandler = function (data, context) {
if (this.config.debug === true) {
consoleLogger.log('mqtt pub -t ' + topic + ' -m ' + msg)
}
return this.client.publish(topic, safeStringify(data))
return this.client.publish(topic, msg, { qos, retain })
}
}

Expand Down